-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kanister prometheus metrics: Controller Integration + ActionSet resol…
…ution counter exports (#2247) * Added metrics file in controller * Exporting resolution metrics for success and failure * Adding unit test to ensure increments are done correctly * Added code to avoid panics if nil registry is passed * Added code to test for nil registry scenario * Added code to read env variable which checks to see if kanister metrics is enabled * moved synchronous failure increments to the callee * fixed issue with registry setting * renamed metric to include kanister_ prefix * Added godocs * Addressed Vivek's review comments * renamed dto to promtest * renamed promtest to promgomodel * fixed go.mod * Fixed testing apis * Addressed Pavan's review comments --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
38e2af4
commit 536ac9a
Showing
7 changed files
with
203 additions
and
55 deletions.
There are no files selected for viewing
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
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,58 @@ | ||
// Copyright 2023 The Kanister Authors. | ||
// | ||
// 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 controller | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
kanistermetrics "github.com/kanisterio/kanister/pkg/metrics" | ||
) | ||
|
||
// metrics encapsulates all the prometheus metrics that controller | ||
// needs to own. | ||
type metrics struct { | ||
actionSetResolutionCounterVec prometheus.CounterVec | ||
} | ||
|
||
const ( | ||
ACTION_SET_COUNTER_VEC_LABEL_RES = "resolution" | ||
ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS = "success" | ||
ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE = "failure" | ||
) | ||
|
||
// getActionSetCounterVecLabels builds a new BoundedLabel list to construct | ||
// the labels permutations for the prometheus metric. | ||
func getActionSetCounterVecLabels() []kanistermetrics.BoundedLabel { | ||
bl := make([]kanistermetrics.BoundedLabel, 1) | ||
bl[0] = kanistermetrics.BoundedLabel{ | ||
LabelName: ACTION_SET_COUNTER_VEC_LABEL_RES, | ||
LabelValues: []string{ | ||
ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, | ||
ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE, | ||
}, | ||
} | ||
return bl | ||
} | ||
|
||
// newMetrics constructs a new metrics object that encapsulates all the | ||
// prometheus metric objects that the controller package needs to own. | ||
func newMetrics(reg prometheus.Registerer) *metrics { | ||
actionSetCounterOpts := prometheus.CounterOpts{ | ||
Name: "kanister_action_set_resolutions_total", | ||
Help: "Total number of action set resolutions", | ||
} | ||
actionSetResolutionCounterVec := kanistermetrics.InitCounterVec(reg, actionSetCounterOpts, getActionSetCounterVecLabels()) | ||
return &metrics{actionSetResolutionCounterVec: *actionSetResolutionCounterVec} | ||
} |
Oops, something went wrong.