Skip to content

Commit

Permalink
Add repository fields to BuildInfo metric
Browse files Browse the repository at this point in the history
Fixes AM-41
  • Loading branch information
gagbo committed Oct 31, 2023
1 parent 71cd848 commit 40f4dee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
7 changes: 7 additions & 0 deletions otel/autometrics/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 5 additions & 1 deletion pkg/autometrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 0 additions & 20 deletions prometheus/autometrics/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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) {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
33 changes: 17 additions & 16 deletions prometheus/autometrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 40f4dee

Please sign in to comment.