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

[receiver/apache]: add optional apache.server.name resource attribute #14926

Merged

Conversation

aboguszewski-sumo
Copy link
Member

@aboguszewski-sumo aboguszewski-sumo commented Oct 13, 2022

Description:
Server name is used as a normal attribute, but it should be a resource attribute. This PR does the first step of changing it, by adding a feature gate to use apache.server.name resource attribute instead of server_name metric-level attribute.

Link to tracking Issue: #14791

Testing:
Unit and integration tests.

Documentation:
mdatagen and changes to README.md

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

@dmitryax as a breaking change for a "beta" receiver, should this be behind a feature gate? i recall that was the decision for the hostmetrics receiver.

@dmitryax
Copy link
Member

@dmitryax as a breaking change for a "beta" receiver, should this be behind a feature gate? i recall that was the decision for the hostmetrics receiver.

I believe many backends flatten the attribute so it could've be ok to merge but the attribute name is changed which is a breaking change anyway. So I agree that it should be done through a feature gate.

@aboguszewski-sumo can you please update break the change into several steps using a feature gate:

  1. add a disabled feature gate, add a warning if it's not enabled by the user.
  2. enable feature gate by default
  3. feature gate removed along with old code

this should span over several releases

cc @djaglowski as code owner

@aboguszewski-sumo
Copy link
Member Author

aboguszewski-sumo commented Oct 17, 2022

@dmitryax sure, I can do this. However, I'm not sure if I understand how it should be done, so please correct me if I'm wrong:

  1. add a resource attribute, but don't emit it by default; add a warning if disabled
  2. emit the resource attribute by default
  3. stop emitting the attribute server_name for each metric; remove the config option and warning

To sum up: server_name is still emitted always in points 1 and 2, gets removed in point 3. I can't imagine optional emitting metric-level attribute unless there's a configuration for mdatagen I'm not aware of, so I think that the only possibility is to remove it as late as possible.

Also - I want to add a mysql.server.port resource attribute, should it undergo a similar process? If not, can it get merged before we finish all steps for mysql.server.name?

@aboguszewski-sumo aboguszewski-sumo force-pushed the apache-name-resource-attr branch from 49752c4 to a376537 Compare October 17, 2022 11:43
@aboguszewski-sumo aboguszewski-sumo changed the title [receiver/apache]: extract server name as resource attribute [receiver/apache]: add optional apache.server.name resource attribute Oct 17, 2022
@aboguszewski-sumo
Copy link
Member Author

I have force pushed the changes for the first step on this branch (I have a backup of the original if needed). Please review if it's what you meant.

@dmitryax
Copy link
Member

Also - I want to add a mysql.server.port resource attribute, should it undergo a similar process? If not, can it get merged before we finish all steps for mysql.server.name?

Removing server_name should be controlled by one feature gate. Adding mysql.server.port resource attribute should be controlled by another feature gate. Both of them should go through the same process:

  1. introduced as disabled with a warning if not enabled by user
  2. enabled by default
  3. removed

About mdatagen:

  1. you can move existing generated_metrics.go to deprecated_metrics.go
  2. apply changes for enabled server_name feature gate, regenerate generated_metrics.go, remove duplicated API deprecated_metrics.go from, then you'll have both old and new APIs.
  3. Then you can use both interfaces depending on whether the server_name feature gate is enabled or not.

@aboguszewski-sumo aboguszewski-sumo force-pushed the apache-name-resource-attr branch 3 times, most recently from 134e6f9 to c615a18 Compare October 18, 2022 10:15
@aboguszewski-sumo aboguszewski-sumo force-pushed the apache-name-resource-attr branch from c615a18 to 6bac04c Compare October 18, 2022 10:20
@aboguszewski-sumo
Copy link
Member Author

Sorry for the misunderstanding, I have pushed a version with feature gate.
Do I understand correctly that the transitions between feature gate states are done on every second release? (so, if this gets released in v0.63, then it will be enabled by default in v0.65)

@dmitryax
Copy link
Member

dmitryax commented Oct 18, 2022

Do I understand correctly that the transitions between feature gate states are done on every second release? (so, if this gets released in v0.63, then it will be enabled by default in v0.65)

Yes, that's an ideal approach

@@ -28,6 +28,7 @@ type Config struct {
scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
confighttp.HTTPClientSettings `mapstructure:",squash"`
serverName string
emitServerNameAsResourceAttribute bool
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 still a config option, not a feature gate. Please take a look at this feature gates example

emitMetricsWithDirectionAttributeFeatureGate = featuregate.Gate{

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 a feature gate used, just not directly in the scraper, but in the factory:
https://github.com/aboguszewski-sumo/opentelemetry-collector-contrib/blob/6bac04c5014dbda6dfe8a424c02b9ab93459cbcc/receiver/apachereceiver/factory.go#L38-L50
I just thought that a pattern where it is injected in the scraper with the config seems more reasonable. I'll just move this code to the scraper then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

@djaglowski djaglowski requested a review from dmitryax October 18, 2022 16:41
Copy link
Member

@djaglowski djaglowski left a comment

Choose a reason for hiding this comment

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

@dmitryax, I agree w/ your suggestions here.

Since there is some ongoing work, I invalidated your previous approval to make sure this doesn't get merged prematurely.

@aboguszewski-sumo aboguszewski-sumo force-pushed the apache-name-resource-attr branch from 40161d6 to 825ebe4 Compare October 20, 2022 12:42
Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

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

LGTM. Just few nits

}

if !a.emitMetricsWithServerNameAsResourceAttribute {
settings.Logger.Warn(fmt.Sprintf("Feature gate %s is not enabled. Please see the README.md file of apache receiver for more information.", EmitServerNameAsResourceAttribute))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just put a link to README here?

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 added the link. However, I was not sure which branch/tag should we link to - I picked main, to avoid predicting if the next stable version will be v0.63.0 or some other v0.63.x like in case of v0.57.

receiver/apachereceiver/scraper.go Outdated Show resolved Hide resolved
@aboguszewski-sumo aboguszewski-sumo force-pushed the apache-name-resource-attr branch from 8c12baf to 3ac9b82 Compare October 21, 2022 08:01
Copy link
Member

@djaglowski djaglowski left a comment

Choose a reason for hiding this comment

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

LGTM

@aboguszewski-sumo
Copy link
Member Author

This did not manage to be merged before v0.63, so I updated information about turning this feature on by default in the readme.

@dmitryax any chance of merging this soon?

@aboguszewski-sumo
Copy link
Member Author

@djaglowski @dmitryax what's the status of this PR? I believe I've made all necessary changes.

@djaglowski djaglowski merged commit d420dbc into open-telemetry:main Nov 3, 2022
dineshg13 pushed a commit to DataDog/opentelemetry-collector-contrib that referenced this pull request Nov 21, 2022
shalper2 pushed a commit to shalper2/opentelemetry-collector-contrib that referenced this pull request Dec 6, 2022
@plantfansam plantfansam mentioned this pull request Jul 21, 2023
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.

4 participants