-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEVHAS-611] Update Component create metrics for better data (#441)
* Update metrics only if current err state is different to the prev Signed-off-by: Maysun J Faisal <[email protected]> * Remove metrics tracking for Gitops due to future commitments Signed-off-by: Maysun J Faisal <[email protected]> --------- Signed-off-by: Maysun J Faisal <[email protected]>
- Loading branch information
1 parent
632e05e
commit da050c7
Showing
12 changed files
with
637 additions
and
411 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright 2024 Red Hat, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package github | ||
|
||
// GitHubUserErr is a user related error for the GitHub related operations | ||
type GitHubUserErr struct { | ||
Err string | ||
} | ||
|
||
func (e *GitHubUserErr) Error() string { | ||
return e.Err | ||
} | ||
|
||
// GitHubSystemErr is a system related error for the GitHub related operations | ||
type GitHubSystemErr struct { | ||
Err string | ||
} | ||
|
||
func (e *GitHubSystemErr) Error() string { | ||
return e.Err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// Copyright 2024 Red Hat, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package metrics | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
var ( | ||
ApplicationDeletionTotalReqs = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_application_deletion_total", | ||
Help: "Number of application deletion requests processed", | ||
}, | ||
) | ||
ApplicationDeletionFailed = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_application_failed_deletion_total", | ||
Help: "Number of failed application deletion requests", | ||
}, | ||
) | ||
|
||
ApplicationDeletionSucceeded = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_application_successful_deletion_total", | ||
Help: "Number of successful application deletion requests", | ||
}, | ||
) | ||
|
||
ApplicationCreationTotalReqs = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_application_creation_total", | ||
Help: "Number of application creation requests processed", | ||
}, | ||
) | ||
ApplicationCreationFailed = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_application_failed_creation_total", | ||
Help: "Number of failed application creation requests", | ||
}, | ||
) | ||
|
||
ApplicationCreationSucceeded = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_application_successful_creation_total", | ||
Help: "Number of successful application creation requests", | ||
}, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// Copyright 2024 Red Hat, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package metrics | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
var ( | ||
componentCreationTotalReqs = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_component_creation_total", | ||
Help: "Number of component creation requests processed", | ||
}, | ||
) | ||
componentCreationFailed = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_component_failed_creation_total", | ||
Help: "Number of failed component creation requests", | ||
}, | ||
) | ||
|
||
componentCreationSucceeded = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_component_successful_creation_total", | ||
Help: "Number of successful component creation requests", | ||
}, | ||
) | ||
|
||
ComponentDeletionTotalReqs = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_component_deletion_total", | ||
Help: "Number of component deletion requests processed", | ||
}, | ||
) | ||
ComponentDeletionFailed = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_component_failed_deletion_total", | ||
Help: "Number of failed component deletion requests", | ||
}, | ||
) | ||
|
||
ComponentDeletionSucceeded = prometheus.NewCounter( | ||
prometheus.CounterOpts{ | ||
Name: "has_component_successful_deletion_total", | ||
Help: "Number of successful component deletion requests", | ||
}, | ||
) | ||
) | ||
|
||
// IncrementComponentCreationFailed increments the component creation failed metric. | ||
// Pass in the new error to update the metric, otherwise it will be ignored. | ||
func IncrementComponentCreationFailed(oldError, newError string) { | ||
if newError != "" && (oldError == "" || !strings.Contains(oldError, newError)) { | ||
// pair the componentCreationTotalReqs counter with componentCreationFailed because | ||
// we dont want a situation where we increment componentCreationTotalReqs in the | ||
// beginning of a reconcile, and we skip the componentCreationFailed metric because | ||
// the errors are the same. Otherwise we will have a situation where neither the success | ||
// nor the fail metric is increasing but the total request count is increasing. | ||
componentCreationTotalReqs.Inc() | ||
componentCreationFailed.Inc() | ||
} | ||
} | ||
|
||
func GetComponentCreationFailed() prometheus.Counter { | ||
return componentCreationFailed | ||
} | ||
|
||
// IncrementComponentCreationSucceeded increments the component creation succeeded metric. | ||
func IncrementComponentCreationSucceeded(oldError, newError string) { | ||
if oldError == "" || newError == "" || !strings.Contains(oldError, newError) { | ||
// pair the componentCreationTotalReqs counter with componentCreationSucceeded because | ||
// we dont want a situation where we increment componentCreationTotalReqs in the | ||
// beginning of a reconcile, and we skip the componentCreationSucceeded metric because | ||
// the errors are the same. Otherwise we will have a situation where neither the success | ||
// nor the fail metric is increasing but the total request count is increasing. | ||
componentCreationTotalReqs.Inc() | ||
componentCreationSucceeded.Inc() | ||
} | ||
} | ||
|
||
func GetComponentCreationSucceeded() prometheus.Counter { | ||
return componentCreationSucceeded | ||
} | ||
|
||
func GetComponentCreationTotalReqs() prometheus.Counter { | ||
return componentCreationTotalReqs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// | ||
// Copyright 2024 Red Hat, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package metrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
) | ||
|
||
func TestComponentMetricsIncrement(t *testing.T) { | ||
|
||
tests := []struct { | ||
name string | ||
oldErr string | ||
newErr string | ||
expectSuccessIncremented bool | ||
expectFailureIncremented bool | ||
}{ | ||
{ | ||
name: "no errors", | ||
oldErr: "", | ||
newErr: "", | ||
expectSuccessIncremented: true, | ||
expectFailureIncremented: false, | ||
}, | ||
{ | ||
name: "no old error, new error", | ||
oldErr: "", | ||
newErr: "error", | ||
expectSuccessIncremented: true, | ||
expectFailureIncremented: true, | ||
}, | ||
{ | ||
name: "old error, no new error", | ||
oldErr: "error", | ||
newErr: "", | ||
expectSuccessIncremented: true, | ||
expectFailureIncremented: false, | ||
}, | ||
{ | ||
name: "old error, new error - same error", | ||
oldErr: "error", | ||
newErr: "error", | ||
expectSuccessIncremented: false, | ||
expectFailureIncremented: false, | ||
}, | ||
{ | ||
name: "old error, new error - different error", | ||
oldErr: "error", | ||
newErr: "error 2", | ||
expectSuccessIncremented: true, | ||
expectFailureIncremented: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
beforeCreateSuccess := testutil.ToFloat64(componentCreationSucceeded) | ||
beforeCreateFailed := testutil.ToFloat64(componentCreationFailed) | ||
|
||
IncrementComponentCreationSucceeded(tt.oldErr, tt.newErr) | ||
|
||
if tt.expectSuccessIncremented && testutil.ToFloat64(componentCreationSucceeded) <= beforeCreateSuccess { | ||
t.Errorf("TestComponentMetricsIncrement error: expected component create success metrics to be incremented but was not incremented") | ||
} else if !tt.expectSuccessIncremented && testutil.ToFloat64(componentCreationSucceeded) > beforeCreateSuccess { | ||
t.Errorf("TestComponentMetricsIncrement error: expected component create success metrics not to be incremented but it was incremented") | ||
} | ||
|
||
IncrementComponentCreationFailed(tt.oldErr, tt.newErr) | ||
|
||
if tt.expectFailureIncremented && testutil.ToFloat64(componentCreationFailed) <= beforeCreateFailed { | ||
t.Errorf("TestComponentMetricsIncrement error: expected component create failed metrics to be incremented but was not incremented") | ||
} else if !tt.expectFailureIncremented && testutil.ToFloat64(componentCreationFailed) > beforeCreateFailed { | ||
t.Errorf("TestComponentMetricsIncrement error: expected component create failed metrics not to be incremented but it was incremented") | ||
} | ||
|
||
}) | ||
} | ||
} |
Oops, something went wrong.