-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HCP Telemetry] Move first TelemetryConfig Fetch into the TelemetryConfigProvider #18318
Changes from 4 commits
3810663
76d40eb
17917a1
e2020e6
bc356c3
d3ff4fd
0fa2160
3e7bd17
d355427
e67ba41
9c8711c
150fb64
1b3d71a
4769d7b
89cb0d3
aa9f8a6
b11d972
2a784ae
50266bd
24e9a7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The entire first fetchTelemetryConfig call is removed simplifying this file quite a lot. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ type MetricsClient interface { | |
// EndpointProvider exposes the GetEndpoint() interface method to fetch the endpoint. | ||
// This abstraction layer offers flexibility, in particular for dynamic configuration or changes to the endpoint. | ||
Achooo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type EndpointProvider interface { | ||
Enabler | ||
GetEndpoint() *url.URL | ||
} | ||
|
||
|
@@ -65,6 +66,10 @@ func (e *OTELExporter) Aggregation(kind metric.InstrumentKind) aggregation.Aggre | |
|
||
// Export serializes and transmits metric data to a receiver. | ||
func (e *OTELExporter) Export(ctx context.Context, metrics *metricdata.ResourceMetrics) error { | ||
if !e.endpointProvider.Enabled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Early return when not exporter is not enabled. |
||
return nil | ||
} | ||
|
||
endpoint := e.endpointProvider.GetEndpoint() | ||
if endpoint == nil { | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,15 @@ import ( | |
// DefaultExportInterval is a default time interval between export of aggregated metrics. | ||
const DefaultExportInterval = 10 * time.Second | ||
|
||
// Enabler must be implemented as it is required to process metrics | ||
// Returning false will mean the sink is disabled, and will not accept metrics. | ||
type Enabler interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chapmanc Although I like this idea a lot, I think it might be neater to use a So moving to: type Disabler interface {
Disabled() bool
} By default this will be false, so sink is enabled. What do you think? |
||
Enabled() bool | ||
} | ||
|
||
// ConfigProvider is required to provide custom metrics processing. | ||
type ConfigProvider interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Enabler | ||
// GetLabels should return a set of OTEL attributes added by default all metrics. | ||
GetLabels() map[string]string | ||
// GetFilters should return filtesr that are required to enable metric processing. | ||
|
@@ -127,8 +134,11 @@ func (o *OTELSink) IncrCounter(key []string, val float32) { | |
// AddSampleWithLabels emits a Consul gauge metric that gets | ||
// registed by an OpenTelemetry Histogram instrument. | ||
func (o *OTELSink) SetGaugeWithLabels(key []string, val float32, labels []gometrics.Label) { | ||
k := o.flattenKey(key) | ||
if !o.cfgProvider.Enabled() { | ||
return | ||
} | ||
|
||
k := o.flattenKey(key) | ||
if !o.allowedMetric(k) { | ||
return | ||
} | ||
|
@@ -155,8 +165,11 @@ func (o *OTELSink) SetGaugeWithLabels(key []string, val float32, labels []gometr | |
|
||
// AddSampleWithLabels emits a Consul sample metric that gets registed by an OpenTelemetry Histogram instrument. | ||
func (o *OTELSink) AddSampleWithLabels(key []string, val float32, labels []gometrics.Label) { | ||
k := o.flattenKey(key) | ||
if !o.cfgProvider.Enabled() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How the early return works when it is not enabled. So no metrics are collected. |
||
return | ||
} | ||
|
||
k := o.flattenKey(key) | ||
if !o.allowedMetric(k) { | ||
return | ||
} | ||
|
@@ -181,8 +194,11 @@ func (o *OTELSink) AddSampleWithLabels(key []string, val float32, labels []gomet | |
|
||
// IncrCounterWithLabels emits a Consul counter metric that gets registed by an OpenTelemetry Histogram instrument. | ||
func (o *OTELSink) IncrCounterWithLabels(key []string, val float32, labels []gometrics.Label) { | ||
k := o.flattenKey(key) | ||
if !o.cfgProvider.Enabled() { | ||
return | ||
} | ||
|
||
k := o.flattenKey(key) | ||
if !o.allowedMetric(k) { | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export this to use as default in https://github.com/hashicorp/consul/pull/18318/files#diff-9fd2535b13a1b9701661bdd379418cb004a41b5b747ff9911e8cbbffea54b9afR60.
In case the first fetch is not available, this default is set to all metrics.