diff --git a/internal/metrics.go b/internal/metrics.go index 0028b1e32..ac01e0f3f 100644 --- a/internal/metrics.go +++ b/internal/metrics.go @@ -112,8 +112,9 @@ type Alerting struct { } type Label struct { - Key string `json:"key" yaml:"key"` - Description string `json:"description" yaml:"description"` + Key string `json:"key" yaml:"key"` + Description string `json:"description" yaml:"description"` + Type *string `json:"type" yaml:"type"` } func GenerateMetricsDocumentation(root string, in MetricsDoc) error { @@ -323,12 +324,32 @@ func generateMetricsGO(root string, in MetricsDoc) error { } } + var keys []string + var params []string + + params = append(params, "value float64") + keys = append(keys, "value") + + for _, label := range details.Labels { + k := strings.ToLower(label.Key) + keys = append(keys, k) + + if t := label.Type; t != nil { + params = append(params, fmt.Sprintf("%s %s", k, *t)) + } else { + params = append(params, fmt.Sprintf("%s string", k)) + } + } + if err := i.Execute(out, map[string]interface{}{ "name": mname, "fname": strings.Join(fnameParts, ""), "ename": strings.Join(tparts, ""), "shortDescription": details.ShortDescription, "labels": generateLabels(details.Labels), + "type": details.Type, + "fparams": strings.Join(params, ", "), + "fkeys": strings.Join(keys, ", "), }); err != nil { return err } diff --git a/internal/metrics.item.go.tmpl b/internal/metrics.item.go.tmpl index 1a9637daa..cc38a9b21 100644 --- a/internal/metrics.item.go.tmpl +++ b/internal/metrics.item.go.tmpl @@ -32,4 +32,8 @@ func init() { func {{ .ename }}() metrics.Description { return {{ .fname }} +} + +func {{ .ename }}{{ .type }}({{ .fparams }}) metrics.Metric { + return {{ .ename }}().Gauge({{ .fkeys }}) } \ No newline at end of file diff --git a/pkg/deployment/agency/cache.go b/pkg/deployment/agency/cache.go index 3036a8b68..029ec4581 100644 --- a/pkg/deployment/agency/cache.go +++ b/pkg/deployment/agency/cache.go @@ -57,29 +57,29 @@ func (h health) Leader() (driver.Connection, bool) { func (h health) CollectMetrics(m metrics.PushMetric) { if err := h.Serving(); err == nil { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheServing().Gauge(1, h.namespace, h.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheServingGauge(1, h.namespace, h.name)) } else { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheServing().Gauge(0, h.namespace, h.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheServingGauge(0, h.namespace, h.name)) } if err := h.Healthy(); err == nil { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheHealthy().Gauge(1, h.namespace, h.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheHealthyGauge(1, h.namespace, h.name)) } else { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheHealthy().Gauge(0, h.namespace, h.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheHealthyGauge(0, h.namespace, h.name)) } for _, name := range h.names { if i, ok := h.commitIndexes[name]; ok { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheMemberServing().Gauge(1, h.namespace, h.name, name), - metric_descriptions.ArangodbOperatorAgencyCacheMemberCommitOffset().Gauge(float64(i), h.namespace, h.name, name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheMemberServingGauge(1, h.namespace, h.name, name), + metric_descriptions.ArangodbOperatorAgencyCacheMemberCommitOffsetGauge(float64(i), h.namespace, h.name, name)) } else { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheMemberServing().Gauge(0, h.namespace, h.name, name), - metric_descriptions.ArangodbOperatorAgencyCacheMemberCommitOffset().Gauge(-1, h.namespace, h.name, name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheMemberServingGauge(0, h.namespace, h.name, name), + metric_descriptions.ArangodbOperatorAgencyCacheMemberCommitOffsetGauge(-1, h.namespace, h.name, name)) } } for k, l := range h.election { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheLeaders().Gauge(float64(l), h.namespace, h.name, k)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheLeadersGauge(float64(l), h.namespace, h.name, k)) } } diff --git a/pkg/deployment/metrics.go b/pkg/deployment/metrics.go index 50ff271e6..fcbb4d4d4 100644 --- a/pkg/deployment/metrics.go +++ b/pkg/deployment/metrics.go @@ -157,20 +157,20 @@ func (i *inventory) Add(d *Deployment) { } func (d *Deployment) CollectMetrics(m metrics.PushMetric) { - m.Push(metric_descriptions.ArangodbOperatorAgencyErrors().Gauge(float64(d.metrics.agency.errors), d.namespace, d.name)) - m.Push(metric_descriptions.ArangodbOperatorAgencyFetches().Gauge(float64(d.metrics.agency.fetches), d.namespace, d.name)) - m.Push(metric_descriptions.ArangodbOperatorAgencyIndex().Gauge(float64(d.metrics.agency.index), d.namespace, d.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyErrorsCount(float64(d.metrics.agency.errors), d.namespace, d.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyFetchesCount(float64(d.metrics.agency.fetches), d.namespace, d.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyIndexGauge(float64(d.metrics.agency.index), d.namespace, d.name)) if c := d.agencyCache; c != nil { - m.Push(metric_descriptions.ArangodbOperatorAgencyCachePresent().Gauge(1, d.namespace, d.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCachePresentGauge(1, d.namespace, d.name)) if h, ok := c.Health(); ok { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheHealthPresent().Gauge(1, d.namespace, d.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheHealthPresentGauge(1, d.namespace, d.name)) h.CollectMetrics(m) } else { - m.Push(metric_descriptions.ArangodbOperatorAgencyCacheHealthPresent().Gauge(0, d.namespace, d.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCacheHealthPresentGauge(0, d.namespace, d.name)) } } else { - m.Push(metric_descriptions.ArangodbOperatorAgencyCachePresent().Gauge(0, d.namespace, d.name)) + m.Push(metric_descriptions.ArangodbOperatorAgencyCachePresentGauge(0, d.namespace, d.name)) } } diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_health_present.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_health_present.go index c2c02e671..04903ce0b 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_health_present.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_health_present.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyCacheHealthPresent() metrics.Description { return arangodbOperatorAgencyCacheHealthPresent } + +func ArangodbOperatorAgencyCacheHealthPresentGauge(value float64, namespace string, name string) metrics.Metric { + return ArangodbOperatorAgencyCacheHealthPresent().Gauge(value, namespace, name) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_healthy.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_healthy.go index 6b7f91f67..279de2531 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_healthy.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_healthy.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyCacheHealthy() metrics.Description { return arangodbOperatorAgencyCacheHealthy } + +func ArangodbOperatorAgencyCacheHealthyGauge(value float64, namespace string, name string) metrics.Metric { + return ArangodbOperatorAgencyCacheHealthy().Gauge(value, namespace, name) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_leaders.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_leaders.go index 96de6eda3..e89ca1cfa 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_leaders.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_leaders.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyCacheLeaders() metrics.Description { return arangodbOperatorAgencyCacheLeaders } + +func ArangodbOperatorAgencyCacheLeadersGauge(value float64, namespace string, name string, agent string) metrics.Metric { + return ArangodbOperatorAgencyCacheLeaders().Gauge(value, namespace, name, agent) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_member_commit_offset.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_member_commit_offset.go index 420a926e2..d09e43171 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_member_commit_offset.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_member_commit_offset.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyCacheMemberCommitOffset() metrics.Description { return arangodbOperatorAgencyCacheMemberCommitOffset } + +func ArangodbOperatorAgencyCacheMemberCommitOffsetGauge(value float64, namespace string, name string, agent string) metrics.Metric { + return ArangodbOperatorAgencyCacheMemberCommitOffset().Gauge(value, namespace, name, agent) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_member_serving.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_member_serving.go index fb5fb68e2..efe4e2950 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_member_serving.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_member_serving.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyCacheMemberServing() metrics.Description { return arangodbOperatorAgencyCacheMemberServing } + +func ArangodbOperatorAgencyCacheMemberServingGauge(value float64, namespace string, name string, agent string) metrics.Metric { + return ArangodbOperatorAgencyCacheMemberServing().Gauge(value, namespace, name, agent) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_present.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_present.go index e798c05b0..c06810b32 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_present.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_present.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyCachePresent() metrics.Description { return arangodbOperatorAgencyCachePresent } + +func ArangodbOperatorAgencyCachePresentGauge(value float64, namespace string, name string) metrics.Metric { + return ArangodbOperatorAgencyCachePresent().Gauge(value, namespace, name) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_serving.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_serving.go index f68fc314c..d4a7aa1d7 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_serving.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_cache_serving.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyCacheServing() metrics.Description { return arangodbOperatorAgencyCacheServing } + +func ArangodbOperatorAgencyCacheServingGauge(value float64, namespace string, name string) metrics.Metric { + return ArangodbOperatorAgencyCacheServing().Gauge(value, namespace, name) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_errors.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_errors.go index f9f884f91..ff73e10cd 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_errors.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_errors.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyErrors() metrics.Description { return arangodbOperatorAgencyErrors } + +func ArangodbOperatorAgencyErrorsCount(value float64, namespace string, name string) metrics.Metric { + return ArangodbOperatorAgencyErrors().Gauge(value, namespace, name) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_fetches.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_fetches.go index 4e93f4bc5..c8fbe9979 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_fetches.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_fetches.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyFetches() metrics.Description { return arangodbOperatorAgencyFetches } + +func ArangodbOperatorAgencyFetchesCount(value float64, namespace string, name string) metrics.Metric { + return ArangodbOperatorAgencyFetches().Gauge(value, namespace, name) +} diff --git a/pkg/generated/metric_descriptions/arangodb_operator_agency_index.go b/pkg/generated/metric_descriptions/arangodb_operator_agency_index.go index 86c94c961..8840cfe4c 100644 --- a/pkg/generated/metric_descriptions/arangodb_operator_agency_index.go +++ b/pkg/generated/metric_descriptions/arangodb_operator_agency_index.go @@ -33,3 +33,7 @@ func init() { func ArangodbOperatorAgencyIndex() metrics.Description { return arangodbOperatorAgencyIndex } + +func ArangodbOperatorAgencyIndexGauge(value float64, namespace string, name string) metrics.Metric { + return ArangodbOperatorAgencyIndex().Gauge(value, namespace, name) +}