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/elasticsearch] Bump 'receiver.elasticsearch.emitNodeVersionAttr' to stable #23254

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .chloggen/elastic-stable-nodevesiongate.yaml
Original file line number Diff line number Diff line change
@@ -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:
djaglowski marked this conversation as resolved.
Show resolved Hide resolved
54 changes: 16 additions & 38 deletions receiver/elasticsearchreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)
)
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down
8 changes: 0 additions & 8 deletions receiver/elasticsearchreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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()

Expand Down