From 17f50811573f40a38e9a766f254d7bd16d6a0822 Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Fri, 9 Jun 2023 10:13:27 -0600 Subject: [PATCH 1/2] [receiver/elasticsearch] Bump 'receiver.elasticsearch.emitNodeVersionAttr' to stable --- .chloggen/elastic-stable-nodevesiongate.yaml | 20 +++++++ receiver/elasticsearchreceiver/scraper.go | 54 ++++++------------- .../elasticsearchreceiver/scraper_test.go | 8 --- 3 files changed, 36 insertions(+), 46 deletions(-) create mode 100755 .chloggen/elastic-stable-nodevesiongate.yaml diff --git a/.chloggen/elastic-stable-nodevesiongate.yaml b/.chloggen/elastic-stable-nodevesiongate.yaml new file mode 100755 index 000000000000..155f8bf9b352 --- /dev/null +++ b/.chloggen/elastic-stable-nodevesiongate.yaml @@ -0,0 +1,20 @@ +# Use this changelog template to create an entry for release notes. +# If your change doesn't affect end users, such as a test fix or a tooling change, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: elasticsearchreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Bump 'receiver.elasticsearch.emitNodeVersionAttr' to stable + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [16847] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/receiver/elasticsearchreceiver/scraper.go b/receiver/elasticsearchreceiver/scraper.go index 0c613bde4f97..94ee36ed7161 100644 --- a/receiver/elasticsearchreceiver/scraper.go +++ b/receiver/elasticsearchreceiver/scraper.go @@ -30,17 +30,12 @@ var ( v, _ := version.NewVersion("7.13") return v }() -) - -const ( - readmeURL = "https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/elasticsearchreceiver/README.md" -) -var ( - emitNodeVersionAttr = featuregate.GlobalRegistry().MustRegister( + _ = featuregate.GlobalRegistry().MustRegister( "receiver.elasticsearch.emitNodeVersionAttr", - featuregate.StageBeta, - featuregate.WithRegisterDescription("When enabled, all node metrics will be enriched with the node version resource attribute."), + featuregate.StageStable, + featuregate.WithRegisterToVersion("0.82.0"), + featuregate.WithRegisterDescription("All node metrics will be enriched with the node version resource attribute."), featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/16847"), ) ) @@ -54,29 +49,17 @@ type elasticsearchScraper struct { mb *metadata.MetricsBuilder version *version.Version clusterName string - - // Feature gates - emitNodeVersionAttr bool } func newElasticSearchScraper( settings receiver.CreateSettings, cfg *Config, ) *elasticsearchScraper { - e := &elasticsearchScraper{ - settings: settings.TelemetrySettings, - cfg: cfg, - mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings), - emitNodeVersionAttr: emitNodeVersionAttr.IsEnabled(), - } - - if !e.emitNodeVersionAttr { - settings.Logger.Warn( - fmt.Sprintf("Feature gate %s is not enabled. Please see the README for more information: %s", emitNodeVersionAttr.ID(), readmeURL), - ) + return &elasticsearchScraper{ + settings: settings.TelemetrySettings, + cfg: cfg, + mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings), } - - return e } func (r *elasticsearchScraper) start(_ context.Context, host component.Host) (err error) { @@ -128,15 +111,12 @@ func (r *elasticsearchScraper) scrapeNodeMetrics(ctx context.Context, now pcommo return } - var nodesInfo *model.Nodes - if r.emitNodeVersionAttr { - // Certain node metadata is not available from the /_nodes/stats endpoint. Therefore, we need to get this metadata - // from the /_nodes endpoint. The metadata may or may not be used depending on feature gates. - nodesInfo, err = r.client.Nodes(ctx, r.cfg.Nodes) - if err != nil { - errs.AddPartial(26, err) - return - } + // Certain node metadata is not available from the /_nodes/stats endpoint. Therefore, we need to get this metadata + // from the /_nodes endpoint. + nodesInfo, err := r.client.Nodes(ctx, r.cfg.Nodes) + if err != nil { + errs.AddPartial(26, err) + return } for id, info := range nodeStats.Nodes { @@ -346,10 +326,8 @@ func (r *elasticsearchScraper) scrapeNodeMetrics(ctx context.Context, now pcommo metadata.WithElasticsearchNodeName(info.Name), } - if r.emitNodeVersionAttr { - if node, ok := nodesInfo.Nodes[id]; ok { - nodeMetadata = append(nodeMetadata, metadata.WithElasticsearchNodeVersion(node.Version)) - } + if node, ok := nodesInfo.Nodes[id]; ok { + nodeMetadata = append(nodeMetadata, metadata.WithElasticsearchNodeVersion(node.Version)) } r.mb.EmitForResource(nodeMetadata...) diff --git a/receiver/elasticsearchreceiver/scraper_test.go b/receiver/elasticsearchreceiver/scraper_test.go index 2d872e570ba6..ff903bb40d44 100644 --- a/receiver/elasticsearchreceiver/scraper_test.go +++ b/receiver/elasticsearchreceiver/scraper_test.go @@ -15,7 +15,6 @@ import ( "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configtls" - "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/collector/receiver/receivertest" "go.opentelemetry.io/collector/receiver/scrapererror" @@ -29,13 +28,6 @@ const fullExpectedMetricsPath = "./testdata/expected_metrics/full.yaml" const skipClusterExpectedMetricsPath = "./testdata/expected_metrics/clusterSkip.yaml" const noNodesExpectedMetricsPath = "./testdata/expected_metrics/noNodes.yaml" -func TestMain(m *testing.M) { - // Enable the feature gates before all tests to avoid flaky tests. - _ = featuregate.GlobalRegistry().Set(emitNodeVersionAttr.ID(), true) - code := m.Run() - os.Exit(code) -} - func TestScraper(t *testing.T) { t.Parallel() From 8760677af45ad6c32ee022965accdaf8ba4a14ba Mon Sep 17 00:00:00 2001 From: Daniel Jaglowski Date: Mon, 12 Jun 2023 07:12:10 -0600 Subject: [PATCH 2/2] Update .chloggen/elastic-stable-nodevesiongate.yaml Co-authored-by: Pablo Baeyens --- .chloggen/elastic-stable-nodevesiongate.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/elastic-stable-nodevesiongate.yaml b/.chloggen/elastic-stable-nodevesiongate.yaml index 155f8bf9b352..338744b02d35 100755 --- a/.chloggen/elastic-stable-nodevesiongate.yaml +++ b/.chloggen/elastic-stable-nodevesiongate.yaml @@ -17,4 +17,4 @@ issues: [16847] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: +subtext: All node metrics are now enriched with the node version resource attribute.