From 40f4dee6a40352a732518a26c64aedef4b001240 Mon Sep 17 00:00:00 2001 From: Gerry Agbobada Date: Tue, 31 Oct 2023 17:43:42 +0100 Subject: [PATCH] Add repository fields to BuildInfo metric Fixes AM-41 --- otel/autometrics/otel.go | 7 ++++++ pkg/autometrics/main.go | 6 ++++- prometheus/autometrics/instrument.go | 20 ----------------- prometheus/autometrics/prometheus.go | 33 ++++++++++++++-------------- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/otel/autometrics/otel.go b/otel/autometrics/otel.go index 4fcd437..57591e8 100644 --- a/otel/autometrics/otel.go +++ b/otel/autometrics/otel.go @@ -84,6 +84,13 @@ const ( // BranchLabel is the openTelemetry attribute that describes the branch of the build of the monitored codebase. BranchLabel = "branch" + // RepositoryURLLabel is the openTelemetry attribute that describes the URL at which the repository containing + // the monitored service can be found + RepositoryURLLabel = "repository.url" + // RepositoryProviderLabel is the openTelemetry attribute that describes the service provider for the monitored + // service repository url + RepositoryProviderLabel = "repository.provider" + // ServiceNameLabel is the openTelemetry attribute that describes the name of the Service being monitored. ServiceNameLabel = "service.name" diff --git a/pkg/autometrics/main.go b/pkg/autometrics/main.go index 1d15db7..0dd0f81 100644 --- a/pkg/autometrics/main.go +++ b/pkg/autometrics/main.go @@ -51,8 +51,12 @@ type BuildInfo struct { Version string // Branch is the branch of the build of the codebase. Branch string - // ServiceName is the name of the service + // Service is the name of the service Service string + // RepositoryURL is the URL of the repository containing the code + RepositoryURL string + // RepositoryProvider is the service provider for the repository containing the code + RepositoryProvider string } // PushConfiguration holds the information necessary to push metrics to an OTEL Collector. diff --git a/prometheus/autometrics/instrument.go b/prometheus/autometrics/instrument.go index fac3cd1..82f19fa 100644 --- a/prometheus/autometrics/instrument.go +++ b/prometheus/autometrics/instrument.go @@ -62,11 +62,6 @@ func Instrument(ctx context.Context, err *error) { CommitLabel: buildInfo.Commit, VersionLabel: buildInfo.Version, ServiceNameLabel: buildInfo.Service, - // REVIEW: This clear mode label is added to make the metrics work when - // pushing metrics to a gravel gateway. To reconsider once - // https://github.com/sinkingpoint/prometheus-gravel-gateway/issues/28 - // is solved - ClearModeLabel: ClearModeFamily, }).(prometheus.ExemplarAdder).AddWithExemplar(1, info) functionCallsDuration.With(prometheus.Labels{ @@ -81,11 +76,6 @@ func Instrument(ctx context.Context, err *error) { CommitLabel: buildInfo.Commit, VersionLabel: buildInfo.Version, ServiceNameLabel: buildInfo.Service, - // REVIEW: This clear mode label is added to make the metrics work when - // pushing metrics to a gravel gateway. To reconsider once - // https://github.com/sinkingpoint/prometheus-gravel-gateway/issues/28 - // is solved - ClearModeLabel: ClearModeFamily, }).(prometheus.ExemplarObserver).ObserveWithExemplar(time.Since(am.GetStartTime(ctx)).Seconds(), info) if am.GetTrackConcurrentCalls(ctx) { @@ -98,11 +88,6 @@ func Instrument(ctx context.Context, err *error) { CommitLabel: buildInfo.Commit, VersionLabel: buildInfo.Version, ServiceNameLabel: buildInfo.Service, - // REVIEW: This clear mode label is added to make the metrics work when - // pushing metrics to a gravel gateway. To reconsider once - // https://github.com/sinkingpoint/prometheus-gravel-gateway/issues/28 - // is solved - ClearModeLabel: ClearModeFamily, }).Add(-1) } @@ -153,11 +138,6 @@ func PreInstrument(ctx context.Context) context.Context { CommitLabel: buildInfo.Commit, VersionLabel: buildInfo.Version, ServiceNameLabel: buildInfo.Service, - // REVIEW: This clear mode label is added to make the metrics work when - // pushing metrics to a gravel gateway. To reconsider once - // https://github.com/sinkingpoint/prometheus-gravel-gateway/issues/28 - // is solved - ClearModeLabel: ClearModeFamily, }).Add(1) } diff --git a/prometheus/autometrics/prometheus.go b/prometheus/autometrics/prometheus.go index 437073e..03797cc 100644 --- a/prometheus/autometrics/prometheus.go +++ b/prometheus/autometrics/prometheus.go @@ -76,16 +76,16 @@ const ( // BranchLabel is the prometheus label that describes the branch of the build of the monitored codebase. BranchLabel = "branch" + // RepositoryURLLabel is the prometheus label that describes the URL at which the repository containing + // the monitored service can be found + RepositoryURLLabel = "repository_url" + // RepositoryProviderLabel is the prometheus label that describes the service provider for the monitored + // service repository url + RepositoryProviderLabel = "repository_provider" + // ServiceNameLabel is the prometheus label that describes the name of the service being monitored ServiceNameLabel = "service_name" - // ClearModeLabel is the label used by Prometheus Gravel Gateway to deal with aggregation. - ClearModeLabel = "clearmode" - - ClearModeFamily = "family" - ClearModeAggregate = "aggregate" - ClearModeReplace = "replace" - traceIdExemplar = "trace_id" spanIdExemplar = "span_id" parentSpanIdExemplar = "parent_id" @@ -162,20 +162,20 @@ func Init(reg *prometheus.Registry, histogramBuckets []float64, buildInformation functionCallsCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: FunctionCallsCountName, - }, []string{FunctionLabel, ModuleLabel, CallerFunctionLabel, CallerModuleLabel, ResultLabel, TargetSuccessRateLabel, SloNameLabel, CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel, ClearModeLabel}) + }, []string{FunctionLabel, ModuleLabel, CallerFunctionLabel, CallerModuleLabel, ResultLabel, TargetSuccessRateLabel, SloNameLabel, CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel}) functionCallsDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{ Name: FunctionCallsDurationName, Buckets: histogramBuckets, - }, []string{FunctionLabel, ModuleLabel, CallerFunctionLabel, CallerModuleLabel, TargetLatencyLabel, TargetSuccessRateLabel, SloNameLabel, CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel, ClearModeLabel}) + }, []string{FunctionLabel, ModuleLabel, CallerFunctionLabel, CallerModuleLabel, TargetLatencyLabel, TargetSuccessRateLabel, SloNameLabel, CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel}) functionCallsConcurrent = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: FunctionCallsConcurrentName, - }, []string{FunctionLabel, ModuleLabel, CallerFunctionLabel, CallerModuleLabel, CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel, ClearModeLabel}) + }, []string{FunctionLabel, ModuleLabel, CallerFunctionLabel, CallerModuleLabel, CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel}) buildInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: BuildInfoName, - }, []string{CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel, ClearModeLabel}) + }, []string{CommitLabel, VersionLabel, BranchLabel, ServiceNameLabel, RepositoryURLLabel, RepositoryProviderLabel}) if reg != nil { reg.MustRegister(functionCallsCount) @@ -190,11 +190,12 @@ func Init(reg *prometheus.Registry, histogramBuckets []float64, buildInformation } buildInfo.With(prometheus.Labels{ - CommitLabel: buildInformation.Commit, - VersionLabel: buildInformation.Version, - BranchLabel: buildInformation.Branch, - ServiceNameLabel: autometrics.GetService(), - ClearModeLabel: ClearModeFamily, + CommitLabel: buildInformation.Commit, + VersionLabel: buildInformation.Version, + BranchLabel: buildInformation.Branch, + ServiceNameLabel: autometrics.GetService(), + RepositoryURLLabel: buildInformation.RepositoryURL, + RepositoryProviderLabel: buildInformation.RepositoryProvider, }).Set(1) if pusher != nil {