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/redis] include server.address and server.port resource attributes #26707

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
32e8863
feat(redisreceiver): include server.address and server.port resource …
sigilioso Sep 15, 2023
234e0f2
fix(redisreceiver): missing 'make generate' execution
sigilioso Sep 15, 2023
6d7957e
test(redisreceiver): update redis receiver required config
sigilioso Sep 15, 2023
97cf3e5
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Sep 18, 2023
4dfe8ef
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Sep 19, 2023
9131dc1
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Sep 26, 2023
e906966
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Sep 27, 2023
2d4c282
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Sep 28, 2023
aa9fecb
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Oct 2, 2023
cb37e15
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Oct 5, 2023
30f864a
chore: change wrapped error
sigilioso Oct 15, 2023
1078ee7
chore: disable new resource attributes by default
sigilioso Oct 16, 2023
0a65de4
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Oct 16, 2023
5a5f3a0
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Oct 17, 2023
cd01d66
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Oct 27, 2023
049736c
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Oct 30, 2023
4363b37
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Nov 2, 2023
4a30ab3
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Nov 9, 2023
ab09651
Merge branch 'main' into redis-receiver-server-address-and-port
sigilioso Nov 14, 2023
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
27 changes: 27 additions & 0 deletions .chloggen/redis-receiver-server-address-and-port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# 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: include server.address and server.port resource attributes

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

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
6 changes: 6 additions & 0 deletions cmd/otelcontribcol/receivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/otlpjsonfilereceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/snmpreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver"
Expand Down Expand Up @@ -348,6 +349,11 @@ func TestDefaultReceivers(t *testing.T) {
},
{
receiver: "redis",
getConfigFn: func() component.Config {
cfg := rcvrFactories["redis"].CreateDefaultConfig().(*redisreceiver.Config)
cfg.Endpoint = "localhost:6379"
return cfg
},
},
{
receiver: "riak",
Expand Down
17 changes: 17 additions & 0 deletions receiver/redisreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package redisreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver"

import (
"fmt"
"net"

"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtls"
Expand Down Expand Up @@ -34,3 +37,17 @@ type Config struct {

MetricsBuilderConfig metadata.MetricsBuilderConfig `mapstructure:",squash"`
}

// configInfo holds configuration information to be used as resource/metrics attributes.
type configInfo struct {
Address string
Port string
}

func newConfigInfo(cfg *Config) (configInfo, error) {
address, port, err := net.SplitHostPort(cfg.Endpoint)
if err != nil {
return configInfo{}, fmt.Errorf("invalid endpoint %q: %w", cfg.Endpoint, err)
}
return configInfo{Address: address, Port: port}, nil
}
2 changes: 2 additions & 0 deletions receiver/redisreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,5 @@ Redis node's role
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| redis.version | Redis server's version. | Any Str | true |
| server.address | Redis server's address | Any Str | true |
| server.port | Redis server's port | Any Str | true |
6 changes: 6 additions & 0 deletions receiver/redisreceiver/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func TestIntegration(t *testing.T) {
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.ChangeResourceAttributeValue("server.address", func(_ string) string {
return "localhost"
}),
pmetrictest.ChangeResourceAttributeValue("server.port", func(_ string) string {
return redisPort
}),
),
).Run(t)
}
10 changes: 9 additions & 1 deletion receiver/redisreceiver/internal/metadata/generated_config.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.

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

14 changes: 14 additions & 0 deletions receiver/redisreceiver/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.

Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ all_set:
resource_attributes:
redis.version:
enabled: true
server.address:
enabled: true
server.port:
enabled: true
none_set:
metrics:
redis.clients.blocked:
Expand Down Expand Up @@ -145,3 +149,7 @@ none_set:
resource_attributes:
redis.version:
enabled: false
server.address:
enabled: false
server.port:
enabled: false
8 changes: 8 additions & 0 deletions receiver/redisreceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ resource_attributes:
description: Redis server's version.
enabled: true
type: string
server.address:
description: Redis server's address
enabled: true
type: string
server.port:
description: Redis server's port
enabled: true
atoulme marked this conversation as resolved.
Show resolved Hide resolved
type: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the port a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could parse it to get the corresponding number, but it is a string when it is taken from the address

Copy link
Contributor

Choose a reason for hiding this comment

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

it's fine, let's leave it as is


attributes:
state:
Expand Down
27 changes: 18 additions & 9 deletions receiver/redisreceiver/redis_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package redisreceiver // import "github.com/open-telemetry/opentelemetry-collect

import (
"context"
"fmt"
"strconv"
"strings"
"time"
Expand All @@ -23,11 +24,12 @@ import (
// Runs intermittently, fetching info from Redis, creating metrics/datapoints,
// and feeding them to a metricsConsumer.
type redisScraper struct {
client client
redisSvc *redisSvc
settings component.TelemetrySettings
mb *metadata.MetricsBuilder
uptime time.Duration
client client
redisSvc *redisSvc
settings component.TelemetrySettings
mb *metadata.MetricsBuilder
uptime time.Duration
configInfo configInfo
}

const redisMaxDbs = 16 // Maximum possible number of redis databases
Expand All @@ -48,11 +50,16 @@ func newRedisScraper(cfg *Config, settings receiver.CreateSettings) (scraperhelp
}

func newRedisScraperWithClient(client client, settings receiver.CreateSettings, cfg *Config) (scraperhelper.Scraper, error) {
configInfo, err := newConfigInfo(cfg)
if err != nil {
return nil, fmt.Errorf("invalid config %w", err)
sigilioso marked this conversation as resolved.
Show resolved Hide resolved
}
rs := &redisScraper{
client: client,
redisSvc: newRedisSvc(client),
settings: settings.TelemetrySettings,
mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings),
client: client,
redisSvc: newRedisSvc(client),
settings: settings.TelemetrySettings,
mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings),
configInfo: configInfo,
}
return scraperhelper.NewScraper(
metadata.Type,
Expand Down Expand Up @@ -96,6 +103,8 @@ func (rs *redisScraper) Scrape(context.Context) (pmetric.Metrics, error) {
rs.recordCmdMetrics(now, inf)
rb := rs.mb.NewResourceBuilder()
rb.SetRedisVersion(rs.getRedisVersion(inf))
rb.SetServerAddress(rs.configInfo.Address)
rb.SetServerPort(rs.configInfo.Port)
return rs.mb.Emit(metadata.WithResource(rb.Emit())), nil
}

Expand Down
8 changes: 8 additions & 0 deletions receiver/redisreceiver/redis_scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestRedisRunnable(t *testing.T) {
settings := receivertest.NewNopCreateSettings()
settings.Logger = logger
cfg := createDefaultConfig().(*Config)
cfg.Endpoint = "localhost:6379"
rs := &redisScraper{mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, settings)}
runner, err := newRedisScraperWithClient(newFakeClient(), settings, cfg)
require.NoError(t, err)
Expand All @@ -35,6 +36,13 @@ func TestRedisRunnable(t *testing.T) {
assert.Equal(t, "otelcol/redisreceiver", il.Name())
}

func TestNewReceiver_invalid_endpoint(t *testing.T) {
c := createDefaultConfig().(*Config)
_, err := createMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), c, nil)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid endpoint")
}

func TestNewReceiver_invalid_auth_error(t *testing.T) {
c := createDefaultConfig().(*Config)
c.TLS = configtls.TLSClientSetting{
Expand Down
6 changes: 6 additions & 0 deletions receiver/redisreceiver/testdata/integration/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ resourceMetrics:
- key: redis.version
value:
stringValue: 6.0.3
- key: server.address
value:
stringValue: localhost
- key: server.port
value:
stringValue: "6379"
scopeMetrics:
- metrics:
- description: Number of clients pending on a blocking call
Expand Down