forked from grafana/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loki.source.heroku: use an unchecked collector for server metrics (gr…
…afana#3711) * loki.source.heroku: use an unchecked collector for server metrics Every time an HTTP server for `loki.source.heroku` is created, it creates a new weaveworks/common server, and registers the same set of metrics to the provided collector. By default, these are checked metrics, which causes the agent-wide `/metrics` endpoint to stop working with an error: An error has occurred while serving metrics: 4 error(s) occurred: * collected metric "loki_source_heroku_drain_target_tcp_connections_limit" { label:<name:"component_id" value:"loki.source.heroku.repro" > label:<name:"protocol" value:"http" > gauge:<value:0 > } was collected before with the same name and label values * collected metric "loki_source_heroku_drain_target_tcp_connections_limit" { label:<name:"component_id" value:"loki.source.heroku.repro" > label:<name:"protocol" value:"grpc" > gauge:<value:0 > } was collected before with the same name and label values * collected metric "loki_source_heroku_drain_target_tcp_connections" { label:<name:"component_id" value:"loki.source.heroku.repro" > label:<name:"protocol" value:"http" > gauge:<value:0 > } was collected before with the same name and label values * collected metric "loki_source_heroku_drain_target_tcp_connections" { label:<name:"component_id" value:"loki.source.heroku.repro" > label:<name:"protocol" value:"grpc" > gauge:<value:0 > } was collected before with the same name and label values This commit adds a new utility method to create an unchecked prometheus.Collector implementation, and then creates a new prometheus.Registry to store server metrics any time a new server is created. The prometheus.Registry instance for the server is then passed to the unchecked prometheus.Collector for handling. Closes grafana#3646. * loki.source.gcplog: apply same server metrics fix Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
104 additions
and
25 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
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,49 @@ | ||
package util | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// UncheckedCollector is a prometheus.Collector which stores a set of unchecked | ||
// metrics. | ||
type UncheckedCollector struct { | ||
mut sync.RWMutex | ||
inner prometheus.Collector | ||
} | ||
|
||
var _ prometheus.Collector = (*UncheckedCollector)(nil) | ||
|
||
// NewUncheckedCollector creates a new UncheckedCollector. If inner is nil, | ||
// UncheckedCollector returns no metrics. | ||
func NewUncheckedCollector(inner prometheus.Collector) *UncheckedCollector { | ||
return &UncheckedCollector{inner: inner} | ||
} | ||
|
||
// SetCollector replaces the inner collector. | ||
func (uc *UncheckedCollector) SetCollector(inner prometheus.Collector) { | ||
uc.mut.Lock() | ||
defer uc.mut.Unlock() | ||
|
||
uc.inner = inner | ||
} | ||
|
||
// Describe implements [prometheus.Collector], but is a no-op to be considered | ||
// an "unchecked" collector by Prometheus. See [prometheus.Collector] for more | ||
// information. | ||
func (uc *UncheckedCollector) Describe(_ chan<- *prometheus.Desc) { | ||
// No-op: do not send any descriptions of metrics to avoid having them be | ||
// checked. | ||
} | ||
|
||
// Collector implements [prometheus.Collector]. If the UncheckedCollector has a | ||
// non-nil inner collector, metrics will be collected from it. | ||
func (uc *UncheckedCollector) Collect(ch chan<- prometheus.Metric) { | ||
uc.mut.RLock() | ||
defer uc.mut.RUnlock() | ||
|
||
if uc.inner != nil { | ||
uc.inner.Collect(ch) | ||
} | ||
} |