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

Honor enabled resource attributes #22105

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions .chloggen/redisreceiver-honor-enabled-resource-attrs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: "enhancement"

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: "redisreceiver"

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Honor the enabled flag for resource attributes (flag was introduced after creation of this receiver)"

issues: [22044]
8 changes: 7 additions & 1 deletion receiver/redisreceiver/redis_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type redisScraper struct {
settings component.TelemetrySettings
mb *metadata.MetricsBuilder
uptime time.Duration
cfg *Config
}

const redisMaxDbs = 16 // Maximum possible number of redis databases
Expand All @@ -52,6 +53,7 @@ func newRedisScraperWithClient(client client, settings receiver.CreateSettings,
redisSvc: newRedisSvc(client),
settings: settings.TelemetrySettings,
mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings),
cfg: cfg,
}
return scraperhelper.NewScraper(
metadata.Type,
Expand Down Expand Up @@ -93,7 +95,11 @@ func (rs *redisScraper) Scrape(context.Context) (pmetric.Metrics, error) {
rs.recordKeyspaceMetrics(now, inf)
rs.recordRoleMetrics(now, inf)
rs.recordCmdStatsMetrics(now, inf)
return rs.mb.Emit(metadata.WithRedisVersion(rs.getRedisVersion(inf))), nil
var resourceMetricOptions []metadata.ResourceMetricsOption
if rs.cfg.MetricsBuilderConfig.ResourceAttributes.RedisVersion.Enabled {
resourceMetricOptions = append(resourceMetricOptions, metadata.WithRedisVersion(rs.getRedisVersion(inf)))
}
Comment on lines +99 to +101
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe this is needed. Its a responsibility of the metrics builder and should be handled by WithRedisVersion. If it's not working for any reason, let's fix the metrics builder

return rs.mb.Emit(resourceMetricOptions...), nil
}

// recordCommonMetrics records metrics from Redis info key-value pairs.
Expand Down
2 changes: 2 additions & 0 deletions receiver/redisreceiver/redis_scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func TestRedisRunnable(t *testing.T) {
ilm := rm.ScopeMetrics().At(0)
il := ilm.Scope()
assert.Equal(t, "otelcol/redisreceiver", il.Name())
// Only version should be enabled by default at this moment
assert.Equal(t, 1, rm.Resource().Attributes().Len())
Copy link
Contributor

Choose a reason for hiding this comment

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

We can add this assertion to the test as a chore PR.

}

func TestNewReceiver_invalid_auth_error(t *testing.T) {
Expand Down