Skip to content

Commit

Permalink
Make sure emitted resource metrics have distinct resources by default
Browse files Browse the repository at this point in the history
This is done by enabling and renaming the following resource attributes:
    - proxy_name -> haproxy.proxy_name
    - service_name -> haproxy.service_name
  • Loading branch information
dmitryax committed Aug 5, 2023
1 parent 0eaf99c commit 6bd459f
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 94 deletions.
20 changes: 20 additions & 0 deletions .chloggen/haproxy-fix-emitted-resource-metrics.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: bug_fix

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Make sure emitted resource metrics have distinct resources by default

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24921]

subtext: |
This is done by enabling and renaming the following resource attributes:
- proxy_name -> haproxy.proxy_name
- service_name -> haproxy.service_name
4 changes: 2 additions & 2 deletions receiver/haproxyreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ Cumulative number of sessions. Corresponds to HAProxy's `stot` metric.
| haproxy.algo | load balancing algorithm | Any Str | true |
| haproxy.iid | unique proxy id | Any Str | true |
| haproxy.pid | process id (0 for first instance, 1 for second, ...) | Any Str | true |
| haproxy.proxy_name | Proxy name | Any Str | true |
| haproxy.service_name | Service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener) | Any Str | true |
| haproxy.sid | server id (unique inside a proxy) | Any Str | true |
| haproxy.type | (0=frontend, 1=backend, 2=server, 3=socket/listener) | Any Str | true |
| haproxy.url | The path to the HAProxy socket or HTTP URL. | Any Str | true |
| proxy_name | Proxy name | Any Str | false |
| service_name | Service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener) | Any Str | false |
30 changes: 15 additions & 15 deletions receiver/haproxyreceiver/internal/metadata/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 36 additions & 36 deletions receiver/haproxyreceiver/internal/metadata/generated_config_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions receiver/haproxyreceiver/internal/metadata/generated_resource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions receiver/haproxyreceiver/internal/metadata/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ all_set:
enabled: true
haproxy.pid:
enabled: true
haproxy.proxy_name:
enabled: true
haproxy.service_name:
enabled: true
haproxy.sid:
enabled: true
haproxy.type:
enabled: true
haproxy.url:
enabled: true
proxy_name:
enabled: true
service_name:
enabled: true
none_set:
metrics:
haproxy.bytes.input:
Expand Down Expand Up @@ -135,13 +135,13 @@ none_set:
enabled: false
haproxy.pid:
enabled: false
haproxy.proxy_name:
enabled: false
haproxy.service_name:
enabled: false
haproxy.sid:
enabled: false
haproxy.type:
enabled: false
haproxy.url:
enabled: false
proxy_name:
enabled: false
service_name:
enabled: false
6 changes: 4 additions & 2 deletions receiver/haproxyreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ resource_attributes:
description: load balancing algorithm
enabled: true
type: string
proxy_name:
haproxy.proxy_name:
description: Proxy name
enabled: true
type: string
service_name:
haproxy.service_name:
description: Service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)
enabled: true
type: string

attributes:
Expand Down
4 changes: 2 additions & 2 deletions receiver/haproxyreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ func (s *scraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
scrapeErrors = append(scrapeErrors, err)
}
rb := s.mb.NewResourceBuilder()
rb.SetProxyName(record["pxname"])
rb.SetServiceName(record["svname"])
rb.SetHaproxyProxyName(record["pxname"])
rb.SetHaproxyServiceName(record["svname"])
rb.SetHaproxyAddr(s.endpoint)
s.mb.EmitForResource(metadata.WithResource(rb.Emit()))
}
Expand Down
1 change: 1 addition & 0 deletions receiver/haproxyreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Test_scraper_readStats(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, m)
require.Equal(t, 6, m.ResourceMetrics().Len())
require.NotEqual(t, m.ResourceMetrics().At(0).Resource(), m.ResourceMetrics().At(1).Resource())
require.Equal(t, 1, m.ResourceMetrics().At(0).ScopeMetrics().Len())
require.Equal(t, 10, m.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().Len())
metric := m.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0)
Expand Down

0 comments on commit 6bd459f

Please sign in to comment.