-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow specifying Collector's own Resource in the config #5402
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,7 @@ func (tel *colTelemetry) init(col *Collector) error { | |
func (tel *colTelemetry) initOnce(col *Collector) error { | ||
logger := col.telemetry.Logger | ||
cfg := col.service.config.Telemetry | ||
resource := cfg.Resource | ||
|
||
level := cfg.Metrics.Level | ||
metricsAddr := cfg.Metrics.Address | ||
|
@@ -109,8 +110,29 @@ func (tel *colTelemetry) initOnce(col *Collector) error { | |
|
||
logger.Info("Setting up own telemetry...") | ||
|
||
instanceUUID, _ := uuid.NewRandom() | ||
instanceID := instanceUUID.String() | ||
// Construct telemetry attributes from resource attributes. | ||
telAttrs := map[string]string{} | ||
for k, v := range resource { | ||
// nil value indicates that the attribute should not be included in the telemetry. | ||
if v != nil { | ||
telAttrs[k] = *v | ||
} | ||
} | ||
|
||
if _, ok := resource[semconv.AttributeServiceInstanceID]; !ok { | ||
// AttributeServiceInstanceID is not specified in the config. Auto-generate one. | ||
instanceUUID, _ := uuid.NewRandom() | ||
instanceID := instanceUUID.String() | ||
telAttrs[semconv.AttributeServiceInstanceID] = instanceID | ||
} | ||
|
||
if AddCollectorVersionTag { | ||
tigrannajaryan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if _, ok := resource[semconv.AttributeServiceVersion]; !ok { | ||
// AttributeServiceVersion is not specified in the config. Use the actual | ||
// build version. | ||
telAttrs[semconv.AttributeServiceVersion] = version.Version | ||
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. On non-core distros, this will show 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. I haven't verified, but I think you are right. This PR didn't change the behavior. 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. You are right, I missed that this was not introduced by this PR. I will make a note to reproduce and open an issue then. We probably want to get rid of 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. There is another semi-related issue: for Agent Management the Supervisor needs a way to fetch the Collector's version. If we are going to change how versions are embedded in the Collector I want to use the opportunity to see if we can make it fetchable by the Supervisor. A few options:
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. I submitted a separate issue for this #5438 |
||
} | ||
} | ||
|
||
var pe http.Handler | ||
if tel.registry.IsEnabled(useOtelForInternalMetricsfeatureGateID) { | ||
|
@@ -120,7 +142,7 @@ func (tel *colTelemetry) initOnce(col *Collector) error { | |
} | ||
pe = otelHandler | ||
} else { | ||
ocHandler, err := tel.initOpenCensus(col, instanceID) | ||
ocHandler, err := tel.initOpenCensus(col, telAttrs) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -131,8 +153,7 @@ func (tel *colTelemetry) initOnce(col *Collector) error { | |
"Serving Prometheus metrics", | ||
zap.String(zapKeyTelemetryAddress, metricsAddr), | ||
zap.String(zapKeyTelemetryLevel, level.String()), | ||
zap.String(semconv.AttributeServiceInstanceID, instanceID), | ||
zap.String(semconv.AttributeServiceVersion, version.Version), | ||
zap.Any("Resource", resource), | ||
) | ||
|
||
mux := http.NewServeMux() | ||
|
@@ -152,7 +173,7 @@ func (tel *colTelemetry) initOnce(col *Collector) error { | |
return nil | ||
} | ||
|
||
func (tel *colTelemetry) initOpenCensus(col *Collector, instanceID string) (http.Handler, error) { | ||
func (tel *colTelemetry) initOpenCensus(col *Collector, telAttrs map[string]string) (http.Handler, error) { | ||
processMetricsViews, err := telemetry2.NewProcessMetricsViews(getBallastSize(col.service.host)) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -178,10 +199,8 @@ func (tel *colTelemetry) initOpenCensus(col *Collector, instanceID string) (http | |
|
||
opts.ConstLabels = make(map[string]string) | ||
|
||
opts.ConstLabels[sanitizePrometheusKey(semconv.AttributeServiceInstanceID)] = instanceID | ||
|
||
if AddCollectorVersionTag { | ||
opts.ConstLabels[sanitizePrometheusKey(semconv.AttributeServiceVersion)] = version.Version | ||
for k, v := range telAttrs { | ||
opts.ConstLabels[sanitizePrometheusKey(k)] = v | ||
} | ||
|
||
pe, err := prometheus.NewExporter(opts) | ||
|
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.
This is not 100% true, only if the exporter is prometheus.
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.
Maybe I can just delete this line to void misleading?