Skip to content
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

Conversation

tigrannajaryan
Copy link
Member

@tigrannajaryan tigrannajaryan commented May 19, 2022

Resolves #5398

This adds a sub-section in the service.telemetry config section where any Resource attributes can be specified. All specified attributes will included as own metrics labels.

If service.instance.id is not specified it will be auto-generated. Previously service.instance.id was always auto-generated, so the default of the new behavior matches the old behavior.

For example we can have the following in the config:

service:
  telemetry:
    resource:
      service.instance.id: 01G3EN4NW306AFVGQT5ZYC0GEK
      service.namespace: onlineshop
      deployment.environment: production

@tigrannajaryan tigrannajaryan requested review from a team and dmitryax May 19, 2022 22:59
@codecov
Copy link

codecov bot commented May 19, 2022

Codecov Report

Merging #5402 (dc41385) into main (9f15964) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head dc41385 differs from pull request most recent head a5bd0fd. Consider uploading reports for the commit a5bd0fd to get more accurate results

@@            Coverage Diff             @@
##             main    #5402      +/-   ##
==========================================
+ Coverage   90.98%   91.01%   +0.02%     
==========================================
  Files         191      190       -1     
  Lines       11429    11442      +13     
==========================================
+ Hits        10399    10414      +15     
+ Misses        811      809       -2     
  Partials      219      219              
Impacted Files Coverage Δ
service/telemetry.go 78.28% <100.00%> (+2.20%) ⬆️
config/configmap.go 90.09% <0.00%> (ø)
config/mapconverter/expandmapconverter/expand.go 100.00% <0.00%> (ø)
...rter/overwritepropertiesmapconverter/properties.go 100.00% <0.00%> (ø)
config/mapconverter.go

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f15964...a5bd0fd. Read the comment docs.

@tigrannajaryan tigrannajaryan force-pushed the feature/tigran/resource-in-config branch from 1e74451 to 39c367d Compare May 19, 2022 23:06
config/moved_service.go Outdated Show resolved Hide resolved
service/telemetry.go Outdated Show resolved Hide resolved
Comment on lines 117 to 118
var instanceID string
instanceID = resource[semconv.AttributeServiceInstanceID]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow users to decide to not have this... or have it empty if they want?

instanceID, ok := resource[semconv.AttributeServiceInstanceID]
if !ok {
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty label values don't work with OpenCensus Prometheus exporter (I didn't dig deep into why, but I tried and the label is just ignored).

Perhaps we can make "empty" string a marker for deleting the label? I.e. you can do this to stop emitting the auto-generated service.instance.id:

service:
  telemetry:
    resource:
      service.instance.id:

Is this valuable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. You can now provide empty string to suppress built-in attributes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@open-telemetry/collector-approvers I would like opinions on this. Is this a) valuable and b) not-surprising behaviour?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty strings are valid on resource attributes so it does feel a bit like surprising behavior to me.

I don't have a good replacement for this though, only thing I can think of is maybe just service.instance.id: null? since null attributes are not valid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, null is probably a better choice. Let me try that.

service/telemetry.go Outdated Show resolved Hide resolved
service/telemetry.go Show resolved Hide resolved
@tigrannajaryan tigrannajaryan force-pushed the feature/tigran/resource-in-config branch from ab6d9d5 to 9e1bb3b Compare May 20, 2022 14:00
@tigrannajaryan
Copy link
Member Author

@open-telemetry/collector-approvers please review.

Comment on lines 132 to 133
// Empty Resource attributes are an indication by the user to suppress and stop
// emitting the particular attribute.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we making an assumption of how users set attributes or adding a feature that allows users to suppress attributes when they want? If it is the latter, a config option specifically for "stop emitting these attributes" might be clearer. If this approach is kept we should document it clearly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a feature that allows users to suppress attributes when they want

To suppress attributes that are otherwise automatically included.

If this approach is kept we should document it clearly.

It is documented in the code in the ServiceTelemetry struct.

@TylerHelmuth
Copy link
Member

This is a great addition, can the new feature be documented specifically on opentelemetry.io? There is a section of telemetry in the collector config doc. It doesn't list every config option, but I think adding this feature to the explicitly mentioned options would be good.

@tigrannajaryan
Copy link
Member Author

This is a great addition, can the new feature be documented specifically on opentelemetry.io? There is a section of telemetry in the collector config doc. It doesn't list every config option, but I think adding this feature to the explicitly mentioned options would be good.

I think we need to look into using https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/cmd/configschema to generate the documentation and see if we can push it to opentelemetry.io (or pull from there). I don't think it is sustainable to document things here in the code and also on the website and keep the docs in sync manually. We can look into it in a separate PR, that's out of the scope for this PR.

@tigrannajaryan tigrannajaryan force-pushed the feature/tigran/resource-in-config branch from b915b7e to 4638360 Compare May 24, 2022 19:07
service/telemetry.go Outdated Show resolved Hide resolved
Resolves open-telemetry#5398

This adds a sub-section in the `service.telemetry` config section where any
Resource attributes can be specified.

For example we can have the following in the config:

service:
  telemetry:
    resource:
      service.instance.id: 01G3EN4NW306AFVGQT5ZYC0GEK
      service.namespace: onlineshop
      deployment.environment: production
@tigrannajaryan tigrannajaryan force-pushed the feature/tigran/resource-in-config branch from dc41385 to a5bd0fd Compare May 25, 2022 00:26
@tigrannajaryan
Copy link
Member Author

@bogdandrutu @mx-psi ok to merge?

@tigrannajaryan tigrannajaryan merged commit 87abc21 into open-telemetry:main May 26, 2022
@tigrannajaryan tigrannajaryan deleted the feature/tigran/resource-in-config branch May 26, 2022 19:41
@@ -38,6 +38,13 @@ type Service struct {
type ServiceTelemetry struct {
Logs ServiceTelemetryLogs `mapstructure:"logs"`
Metrics ServiceTelemetryMetrics `mapstructure:"metrics"`

// Resource specifies user-defined attributes to include with all emitted telemetry.
// For metrics the attributes become Prometheus labels.
Copy link
Member

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.

Copy link
Member Author

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?

if _, ok := resource[semconv.AttributeServiceVersion]; !ok {
// AttributeServiceVersion is not specified in the config. Use the actual
// build version.
telAttrs[semconv.AttributeServiceVersion] = version.Version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On non-core distros, this will show latest, right? We probably want to explicitly pass a version on the Collector settings to avoid this

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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 version.Version entirely and leave passing the version to the builder instead.

Copy link
Member Author

Choose a reason for hiding this comment

The 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:

  • Have a manifest file with version number recorded in it and include the manifest in Collector's installation packages.
  • Try to fetch version number from executable directly (as a symbol?). Not very desirable since it requires platform specific code.
  • Read from CLI by using --version flag (not very reliable since the output format is not precisely defined).
  • Something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I submitted a separate issue for this #5438

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow specifying Collector's own Resource in the config
5 participants