Skip to content

[receiver/lightprometheus] Change configurable resource_attribute names #6257

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

Merged
merged 4 commits into from
May 28, 2025
Merged
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

### 🚩 Deprecations 🚩

- (Splunk) `receiver/lightprometheus`: The following configurable `resource_attributes` are being renamed to match semantic conventions. ([#6257](https://github.com/signalfx/splunk-otel-collector/pull/6257))
- `net.host.name` -> `server.address`
- `net.host.port` -> `server.port`
- `http.scheme` -> `url.scheme`

`net.host.name`, `net.host.port`, and `http.scheme` are now considered to be deprecated and will be removed in a future release.

### 💡 Enhancements 💡

- (Splunk) `deployments/nomad`: Add official support for `v1.9.7` ([#6248](https://github.com/signalfx/splunk-otel-collector/pull/6248))
Expand Down
6 changes: 3 additions & 3 deletions internal/receiver/lightprometheusreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ The following settings can be optionally configured:
- `enabled`: (default: true)
- `service.instance.id`:
- `enabled`: (default: true)
- `net.host.name`:
- `server.address`:
- `enabled`: (default: false)
- `net.host.port`:
- `server.port`:
- `enabled`: (default: false)
- `http.scheme`:
- `url.scheme`:
- `enabled`: (default: false)
- [HTTP Client Configuration options](https://github.com/open-telemetry/opentelemetry-collector/tree/main/config/confighttp#client-configuration)

Expand Down
8 changes: 8 additions & 0 deletions internal/receiver/lightprometheusreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func createDefaultConfig() component.Config {
// set the default collection interval to 30 seconds which is half of the
// lowest job frequency of 1 minute
scs.CollectionInterval = time.Second * 30

return &Config{
ControllerConfig: scs,
ClientConfig: confighttp.NewDefaultClientConfig(),
Expand All @@ -37,8 +38,12 @@ func createDefaultConfig() component.Config {
NetHostName: ResourceAttributeConfig{Enabled: false},
NetHostPort: ResourceAttributeConfig{Enabled: false},
HTTPScheme: ResourceAttributeConfig{Enabled: false},
ServerAddress: ResourceAttributeConfig{Enabled: false},
ServerPort: ResourceAttributeConfig{Enabled: false},
URLScheme: ResourceAttributeConfig{Enabled: false},
},
}

}

// ResourceAttributeConfig provides configuration for a resource attribute.
Expand All @@ -50,6 +55,9 @@ type ResourceAttributeConfig struct {
type ResourceAttributesConfig struct {
ServiceName ResourceAttributeConfig `mapstructure:"service.name"`
ServiceInstanceID ResourceAttributeConfig `mapstructure:"service.instance.id"`
ServerAddress ResourceAttributeConfig `mapstructure:"server.address"`
ServerPort ResourceAttributeConfig `mapstructure:"server.port"`
URLScheme ResourceAttributeConfig `mapstructure:"url.scheme"`
NetHostName ResourceAttributeConfig `mapstructure:"net.host.name"`
NetHostPort ResourceAttributeConfig `mapstructure:"net.host.port"`
HTTPScheme ResourceAttributeConfig `mapstructure:"http.scheme"`
Expand Down
6 changes: 3 additions & 3 deletions internal/receiver/lightprometheusreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func TestValidConfig(t *testing.T) {
ResourceAttributes: ResourceAttributesConfig{
ServiceInstanceID: ResourceAttributeConfig{Enabled: false},
ServiceName: ResourceAttributeConfig{Enabled: false},
NetHostName: ResourceAttributeConfig{Enabled: true},
NetHostPort: ResourceAttributeConfig{Enabled: false},
HTTPScheme: ResourceAttributeConfig{Enabled: false},
ServerAddress: ResourceAttributeConfig{Enabled: true},
ServerPort: ResourceAttributeConfig{Enabled: false},
URLScheme: ResourceAttributeConfig{Enabled: false},
},
}
expectedCfg.ClientConfig.Endpoint = "http://localhost:9090/metrics"
Expand Down
25 changes: 24 additions & 1 deletion internal/receiver/lightprometheusreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
conventions "go.opentelemetry.io/collector/semconv/v1.25.0"
"go.uber.org/zap"
)

Expand All @@ -55,6 +55,16 @@ func newScraper(
}

func (s *scraper) start(ctx context.Context, host component.Host) error {
if s.cfg.ResourceAttributes.NetHostName.Enabled {
s.settings.Logger.Warn("[Deprecated] The resource attribute `net.host.name` has been renamed `server.address.name` to match semantic conventions in `v0.126.0`. Please update references. `net.host.name` will be removed in a future release.")
}
if s.cfg.ResourceAttributes.NetHostPort.Enabled {
s.settings.Logger.Warn("[Deprecated] The resource attribute `net.host.port` has been renamed `server.port` to match semantic conventions in `v0.126.0`. Please update references. `net.host.port` will be removed in a future release.")
}
if s.cfg.ResourceAttributes.HTTPScheme.Enabled {
s.settings.Logger.Warn("[Deprecated] The resource attribute `http.scheme` has been renamed `url.scheme` to match semantic conventions in `v0.126.0`. Please update references. `http.scheme` will be removed in a future release.")
}

s.startTime = pcommon.NewTimestampFromTime(time.Now())
var err error
s.client, err = s.cfg.ClientConfig.ToClient(ctx, host, s.settings)
Expand Down Expand Up @@ -100,18 +110,31 @@ func (s *scraper) fetchPrometheusMetrics(fetch fetcher) (pmetric.Metrics, error)
if s.cfg.ResourceAttributes.ServiceName.Enabled {
res.Attributes().PutStr(conventions.AttributeServiceName, s.name)
}

if s.cfg.ResourceAttributes.NetHostName.Enabled {
res.Attributes().PutStr(conventions.AttributeNetHostName, u.Host)
}
if s.cfg.ResourceAttributes.ServerAddress.Enabled {
res.Attributes().PutStr(conventions.AttributeServerAddress, u.Host)
}

if s.cfg.ResourceAttributes.ServiceInstanceID.Enabled {
res.Attributes().PutStr(conventions.AttributeServiceInstanceID, u.Host)
}

if s.cfg.ResourceAttributes.NetHostPort.Enabled {
res.Attributes().PutStr(conventions.AttributeNetHostPort, u.Port())
}
if s.cfg.ResourceAttributes.ServerPort.Enabled {
res.Attributes().PutStr(conventions.AttributeServerPort, u.Port())
}

if s.cfg.ResourceAttributes.HTTPScheme.Enabled {
res.Attributes().PutStr(conventions.AttributeHTTPScheme, u.Scheme)
}
if s.cfg.ResourceAttributes.URLScheme.Enabled {
res.Attributes().PutStr(conventions.AttributeURLScheme, u.Scheme)
}
s.convertMetricFamilies(metricFamilies, rm)
return m, nil
}
Expand Down
20 changes: 19 additions & 1 deletion internal/receiver/lightprometheusreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"go.opentelemetry.io/collector/confmap/xconfmap"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver/receivertest"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
conventions "go.opentelemetry.io/collector/semconv/v1.25.0"
)

func TestScraper(t *testing.T) {
Expand All @@ -53,6 +53,24 @@ func TestScraper(t *testing.T) {
},
{
name: "all_resource_attributes",
cfg: func() *Config {
cfg := createDefaultConfig().(*Config)
cfg.ResourceAttributes.ServiceName.Enabled = true
cfg.ResourceAttributes.URLScheme.Enabled = true
cfg.ResourceAttributes.ServerPort.Enabled = true
cfg.ResourceAttributes.ServerAddress.Enabled = true
return cfg
}(),
expectedResourceAttributes: map[string]any{
conventions.AttributeServiceName: "",
conventions.AttributeServiceInstanceID: u.Host,
conventions.AttributeServerAddress: u.Host,
conventions.AttributeServerPort: u.Port(),
conventions.AttributeURLScheme: "http",
},
},
{
name: "deprecated_resource_attributes",
cfg: func() *Config {
cfg := createDefaultConfig().(*Config)
cfg.ResourceAttributes.ServiceName.Enabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ lightprometheus:
enabled: false
service.instance.id:
enabled: false
net.host.name:
server.address:
enabled: true
Loading