1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

[Feature] Metrics counter (#1333)

This commit is contained in:
Adam Janikowski 2023-06-12 15:18:51 +02:00 committed by GitHub
parent 618b48f606
commit 1b76f8c4e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 141 additions and 49 deletions

View file

@ -3,6 +3,7 @@
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
- (Feature) AgencyCache Interface
- (Feature) Agency Cache Poll EE Extension
- (Feature) Metrics Counter
## [1.2.29](https://github.com/arangodb/kube-arangodb/tree/1.2.29) (2023-06-08)
- (Maintenance) Add govulncheck to pipeline, update golangci-linter

View file

@ -35,5 +35,5 @@ func {{ .ename }}() metrics.Description {
}
func {{ .ename }}{{ .type }}({{ .fparams }}) metrics.Metric {
return {{ .ename }}().Gauge({{ .fkeys }})
return {{ .ename }}().{{ .type }}({{ .fkeys }})
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorAgencyErrors() metrics.Description {
}
func ArangodbOperatorAgencyErrorsCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorAgencyErrors().Gauge(value, namespace, name)
return ArangodbOperatorAgencyErrors().Counter(value, namespace, name)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorAgencyFetches() metrics.Description {
}
func ArangodbOperatorAgencyFetchesCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorAgencyFetches().Gauge(value, namespace, name)
return ArangodbOperatorAgencyFetches().Counter(value, namespace, name)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorEngineOpsAlerts() metrics.Description {
}
func ArangodbOperatorEngineOpsAlertsCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorEngineOpsAlerts().Gauge(value, namespace, name)
return ArangodbOperatorEngineOpsAlerts().Counter(value, namespace, name)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorEnginePanicsRecovered() metrics.Description {
}
func ArangodbOperatorEnginePanicsRecoveredCounter(value float64, section string) metrics.Metric {
return ArangodbOperatorEnginePanicsRecovered().Gauge(value, section)
return ArangodbOperatorEnginePanicsRecovered().Counter(value, section)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorKubernetesClientRequestErrors() metrics.Description {
}
func ArangodbOperatorKubernetesClientRequestErrorsCounter(value float64, component string, verb string) metrics.Metric {
return ArangodbOperatorKubernetesClientRequestErrors().Gauge(value, component, verb)
return ArangodbOperatorKubernetesClientRequestErrors().Counter(value, component, verb)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorKubernetesClientRequests() metrics.Description {
}
func ArangodbOperatorKubernetesClientRequestsCounter(value float64, component string, verb string) metrics.Metric {
return ArangodbOperatorKubernetesClientRequests().Gauge(value, component, verb)
return ArangodbOperatorKubernetesClientRequests().Counter(value, component, verb)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorMembersUnexpectedContainerExitCodes() metrics.Description {
}
func ArangodbOperatorMembersUnexpectedContainerExitCodesCounter(value float64, namespace string, name string, member string, container string, containerType string, code string, reason string) metrics.Metric {
return ArangodbOperatorMembersUnexpectedContainerExitCodes().Gauge(value, namespace, name, member, container, containerType, code, reason)
return ArangodbOperatorMembersUnexpectedContainerExitCodes().Counter(value, namespace, name, member, container, containerType, code, reason)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorRebalancerMovesFailed() metrics.Description {
}
func ArangodbOperatorRebalancerMovesFailedCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorRebalancerMovesFailed().Gauge(value, namespace, name)
return ArangodbOperatorRebalancerMovesFailed().Counter(value, namespace, name)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorRebalancerMovesGenerated() metrics.Description {
}
func ArangodbOperatorRebalancerMovesGeneratedCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorRebalancerMovesGenerated().Gauge(value, namespace, name)
return ArangodbOperatorRebalancerMovesGenerated().Counter(value, namespace, name)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorRebalancerMovesSucceeded() metrics.Description {
}
func ArangodbOperatorRebalancerMovesSucceededCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorRebalancerMovesSucceeded().Gauge(value, namespace, name)
return ArangodbOperatorRebalancerMovesSucceeded().Counter(value, namespace, name)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorResourcesArangodeploymentImmutableErrors() metrics.Descript
}
func ArangodbOperatorResourcesArangodeploymentImmutableErrorsCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorResourcesArangodeploymentImmutableErrors().Gauge(value, namespace, name)
return ArangodbOperatorResourcesArangodeploymentImmutableErrors().Counter(value, namespace, name)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorResourcesArangodeploymentStatusRestores() metrics.Descripti
}
func ArangodbOperatorResourcesArangodeploymentStatusRestoresCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorResourcesArangodeploymentStatusRestores().Gauge(value, namespace, name)
return ArangodbOperatorResourcesArangodeploymentStatusRestores().Counter(value, namespace, name)
}

View file

@ -35,5 +35,5 @@ func ArangodbOperatorResourcesArangodeploymentValidationErrors() metrics.Descrip
}
func ArangodbOperatorResourcesArangodeploymentValidationErrorsCounter(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorResourcesArangodeploymentValidationErrors().Gauge(value, namespace, name)
return ArangodbOperatorResourcesArangodeploymentValidationErrors().Counter(value, namespace, name)
}

View file

@ -34,6 +34,7 @@ type Description interface {
Collect(out chan<- prometheus.Metric, collect func(p Producer) error)
Gauge(value float64, labels ...string) Metric
Counter(value float64, labels ...string) Metric
}
type description struct {
@ -42,6 +43,10 @@ type description struct {
desc *prometheus.Desc
}
func (d *description) Counter(value float64, labels ...string) Metric {
return newCounter(d, value, labels...)
}
func (d *description) Gauge(value float64, labels ...string) Metric {
return newGauge(d, value, labels...)
}

View file

@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -29,10 +29,6 @@ type Metric interface {
prometheus.Metric
}
type Gauge interface {
Metric
}
type Error interface {
Metric
}
@ -56,33 +52,3 @@ func newError(desc Description, value error) Error {
err: value,
}
}
func newGauge(desc Description, value float64, labels ...string) Gauge {
return gauge{
desc: desc,
labels: labels,
value: value,
}
}
type gauge struct {
desc Description
labels []string
value float64
}
func (g gauge) Desc() *prometheus.Desc {
return g.desc.Desc()
}
func (g gauge) Write(metric *dto.Metric) error {
metric.Label = g.desc.Labels(g.labels...)
metric.Gauge = &dto.Gauge{
Value: &g.value,
}
return nil
}

View file

@ -0,0 +1,60 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)
type Counter interface {
Metric
}
func newCounter(desc Description, value float64, labels ...string) Counter {
return couter{
desc: desc,
labels: labels,
value: value,
}
}
type couter struct {
desc Description
labels []string
value float64
}
func (g couter) Desc() *prometheus.Desc {
return g.desc.Desc()
}
func (g couter) Write(metric *dto.Metric) error {
metric.Label = g.desc.Labels(g.labels...)
metric.Counter = &dto.Counter{
Value: &g.value,
}
return nil
}

View file

@ -0,0 +1,60 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
)
type Gauge interface {
Metric
}
func newGauge(desc Description, value float64, labels ...string) Gauge {
return gauge{
desc: desc,
labels: labels,
value: value,
}
}
type gauge struct {
desc Description
labels []string
value float64
}
func (g gauge) Desc() *prometheus.Desc {
return g.desc.Desc()
}
func (g gauge) Write(metric *dto.Metric) error {
metric.Label = g.desc.Labels(g.labels...)
metric.Gauge = &dto.Gauge{
Value: &g.value,
}
return nil
}