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

Support valkey-go tracing #3081

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Support valkey-go tracing #3081

wants to merge 23 commits into from

Conversation

keisku
Copy link

@keisku keisku commented Jan 12, 2025

What does this PR do?

Support https://github.com/valkey-io/valkey-go

Example:

2025-01-24_00-08-27

Motivation

#2920

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.
  • For internal contributors, a matching PR should be created to the v2-dev branch and reviewed by @DataDog/apm-go.

Unsure? Have a question? Request a review!

@github-actions github-actions bot added the apm:ecosystem contrib/* related feature requests or bugs label Jan 12, 2025
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jan 12, 2025

Datadog Report

Branch report: keisku/valkey-go-support
Commit report: 3939a5a
Test service: dd-trace-go

❌ 8 Failed (0 Known Flaky), 5167 Passed, 70 Skipped, 2m 54.4s Total Time

❌ Failed Tests (8)

This report shows up to 5 failed tests.

  • TestNewClient - gopkg.in/DataDog/dd-trace-go.v1/contrib/valkey-go - Details

    Expand for error
     Failed
     
     === RUN   TestNewClient
     --- FAIL: TestNewClient (0.11s)
    
  • TestNewClient/Test_GET_command_with_stream_with_env_vars - gopkg.in/DataDog/dd-trace-go.v1/contrib/valkey-go - Details

    Expand for error
     Failed
     
     === RUN   TestNewClient/Test_GET_command_with_stream_with_env_vars
         valkey_test.go:287: 
             	Error Trace:	/home/runner/work/dd-trace-go/dd-trace-go/contrib/valkey-go/valkey_test.go:287
             	Error:      	Received unexpected error:
             	            	dial tcp 127.0.0.1:6380: connect: connection refused
             	Test:       	TestNewClient/Test_GET_command_with_stream_with_env_vars
             	Messages:   	Test GET command with stream with env vars
         --- FAIL: TestNewClient/Test_GET_command_with_stream_with_env_vars (0.02s)
    
  • TestNewClient/Test_HMGET_command_with_cache - gopkg.in/DataDog/dd-trace-go.v1/contrib/valkey-go - Details

    Expand for error
     Failed
     
     === RUN   TestNewClient/Test_HMGET_command_with_cache
         valkey_test.go:287: 
             	Error Trace:	/home/runner/work/dd-trace-go/dd-trace-go/contrib/valkey-go/valkey_test.go:287
             	Error:      	Received unexpected error:
             	            	dial tcp 127.0.0.1:6380: connect: connection refused
             	Test:       	TestNewClient/Test_HMGET_command_with_cache
             	Messages:   	Test HMGET command with cache
         --- FAIL: TestNewClient/Test_HMGET_command_with_cache (0.01s)
    
  • TestNewClient/Test_invalid_password - gopkg.in/DataDog/dd-trace-go.v1/contrib/valkey-go - Details

    Expand for error
     Failed
     
     === RUN   TestNewClient/Test_invalid_password
         valkey_test.go:67: 
             	Error Trace:	/home/runner/work/dd-trace-go/dd-trace-go/contrib/valkey-go/valkey_test.go:67
             	            				/home/runner/work/dd-trace-go/dd-trace-go/contrib/valkey-go/valkey_test.go:289
             	Error:      	Error message not equal:
             	            	expected: "WRONGPASS invalid username-password pair or user is disabled."
             	            	actual  : "dial tcp 127.0.0.1:6380: connect: connection refused"
             	Test:       	TestNewClient/Test_invalid_password
     ...
    
  • TestNewClient/Test_invalid_username - gopkg.in/DataDog/dd-trace-go.v1/contrib/valkey-go - Details

    Expand for error
     Failed
     
     === RUN   TestNewClient/Test_invalid_username
         valkey_test.go:56: 
             	Error Trace:	/home/runner/work/dd-trace-go/dd-trace-go/contrib/valkey-go/valkey_test.go:56
             	            				/home/runner/work/dd-trace-go/dd-trace-go/contrib/valkey-go/valkey_test.go:289
             	Error:      	Error message not equal:
             	            	expected: "WRONGPASS invalid username-password pair or user is disabled."
             	            	actual  : "dial tcp 127.0.0.1:6380: connect: connection refused"
             	Test:       	TestNewClient/Test_invalid_username
     ...
    

@pr-commenter
Copy link

pr-commenter bot commented Jan 12, 2025

Benchmarks

Benchmark execution time: 2025-01-23 15:27:59

Comparing candidate commit 25088d1 in PR branch keisku/valkey-go-support with baseline commit 382c311 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 59 metrics, 0 unstable metrics.

@keisku keisku force-pushed the keisku/valkey-go-support branch 8 times, most recently from e41ab88 to 7c97f5b Compare January 15, 2025 08:55
@keisku keisku force-pushed the keisku/valkey-go-support branch from 7c97f5b to 6aa8d69 Compare January 15, 2025 10:56
@keisku keisku marked this pull request as ready for review January 15, 2025 11:20
@keisku keisku requested review from a team as code owners January 15, 2025 11:20
contrib/valkey-go/valkey.go Outdated Show resolved Hide resolved
@keisku keisku force-pushed the keisku/valkey-go-support branch from 11e7c51 to 2750600 Compare January 16, 2025 03:33
@keisku keisku force-pushed the keisku/valkey-go-support branch from 2750600 to fe59e6d Compare January 16, 2025 03:36
@darccio
Copy link
Member

darccio commented Jan 17, 2025

@keisku Thanks for contributing this integration! Please fix the conflicts and this should be good to go.

Also remember to create the same PR against v2-dev. Keep in mind that this branch has some major differences, including an instrumentation package for contribs. Check the same integration for Redis to learn more about how to integrate a library in our contribs in our upcoming v2 version.

contrib/valkey-go/example_test.go Show resolved Hide resolved
contrib/valkey-go/valkey.go Outdated Show resolved Hide resolved
Signed-off-by: keisku <keisuke.umegaki@datadoghq.com>
Signed-off-by: keisku <keisuke.umegaki@datadoghq.com>
Signed-off-by: keisku <keisuke.umegaki@datadoghq.com>
Signed-off-by: keisku <keisuke.umegaki@datadoghq.com>
@keisku keisku force-pushed the keisku/valkey-go-support branch from fbb2f5f to 6d5b6f6 Compare January 18, 2025 01:22
@keisku keisku requested a review from hannahkm January 18, 2025 01:24
contrib/valkey-go/valkey.go Outdated Show resolved Hide resolved
contrib/valkey-go/valkey.go Outdated Show resolved Hide resolved
contrib/valkey-go/valkey.go Outdated Show resolved Hide resolved
skipRawCommand bool
}

func (c *coreClient) peerTags() []tracer.StartSpanOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't be setting peer.* tags in this integration. You can mirror the behavior of the go-redis integration for these tags: https://github.com/DataDog/dd-trace-go/blob/main/contrib/redis/go-redis.v9/redis.go#L75-L111 (changing redis -> valkey where appropiate)

Copy link
Author

Choose a reason for hiding this comment

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

we shouldn't be setting peer.* tags in this integration.

Could you explain the reason for this?

After reading the following docs, I understood peer.* is necessary tags now. Since the last commit for go-redis.v9 was two years ago, I assumed that it was not required at that time.

I'd appreciate it if you could let me know if my understanding is incorrect.

Copy link
Contributor

@rarguelloF rarguelloF Jan 22, 2025

Choose a reason for hiding this comment

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

The agent checks a list of tags to compute peer.service, and I think both out.host and peer.hostname would be considered in this case. But for consistency with other integrations, I think its preferred to just set out.host (I am asking around if this preference has changed recently and if we have any documentation about it)

contrib/valkey-go/valkey.go Outdated Show resolved Hide resolved
contrib/valkey-go/valkey.go Outdated Show resolved Hide resolved
contrib/valkey-go/option.go Outdated Show resolved Hide resolved
contrib/valkey-go/example_test.go Outdated Show resolved Hide resolved
contrib/valkey-go/example_test.go Outdated Show resolved Hide resolved
contrib/valkey-go/example_test.go Outdated Show resolved Hide resolved
@keisku keisku requested a review from rarguelloF January 21, 2025 01:56
Comment on lines 161 to 167
ipAddr := net.ParseIP(c.host)
var peerHostKey string
if ipAddr == nil {
peerHostKey = ext.PeerHostname
} else if ipAddr.To4() != nil {
peerHostKey = ext.PeerHostIPV4
} else {
peerHostKey = ext.PeerHostIPV6
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ipAddr := net.ParseIP(c.host)
var peerHostKey string
if ipAddr == nil {
peerHostKey = ext.PeerHostname
} else if ipAddr.To4() != nil {
peerHostKey = ext.PeerHostIPV4
} else {
peerHostKey = ext.PeerHostIPV6
}

this is not necessary, the integration should only set out.host when unsure whether the value is an IP address or a hostname. We already have this sort of logic in place in the backend.

Copy link
Author

Choose a reason for hiding this comment

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

out.host seems to be deprecated. So, should we set network.destination.name or network.destination.ip?

// TargetHost sets the target host address.
// Deprecated: Use NetworkDestinationName instead for hostname and NetworkDestinationIP for IP addresses
TargetHost = "out.host"

skipRawCommand bool
}

func (c *coreClient) peerTags() []tracer.StartSpanOption {
Copy link
Contributor

@rarguelloF rarguelloF Jan 22, 2025

Choose a reason for hiding this comment

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

The agent checks a list of tags to compute peer.service, and I think both out.host and peer.hostname would be considered in this case. But for consistency with other integrations, I think its preferred to just set out.host (I am asking around if this preference has changed recently and if we have any documentation about it)

Comment on lines 189 to 188
tracer.Tag(ext.ValkeyDatabaseIndex, c.option.SelectDB),
tracer.Tag("db.out", c.option.SelectDB),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
tracer.Tag(ext.ValkeyDatabaseIndex, c.option.SelectDB),
tracer.Tag("db.out", c.option.SelectDB),
tracer.Tag("out.db", c.option.SelectDB),
  • db.out -> out.db
  • only one of the 2 tags (we want to avoid repeated information)

Also, if you don't mind, could you create a new constant ext.OutDB for out.db to prevent this kind of mistake to happen in the future? 🙏

Copy link
Author

Choose a reason for hiding this comment

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

Since out.host was deprecated, should we avoid setting out.db?
Or should we keep setting out.db for consistency of redis integration?

dc939eb marked it as deprecated.

opts = append(opts, []tracer.StartSpanOption{
// valkeyotel tags
tracer.Tag("db.stmt_size", input.size),
tracer.Tag("db.operation", input.command),
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to add obfuscation, since its already done in the agent (the code you linked). However I just noticed there's an issue, since that code will only run if span.type is redis, so it won't run for valkey. I will talk to the apm-agent team about this.

But basically what we want to do here is:

if !input.skipRawCommand {
	opts = append(opts, tracer.Tag(ext.ValkeyRawCommand, input.command))
}

Also it is preferred to set only the raw command tag, since its the one the agent checks for obfuscation (when the logic is updated to check for valkey as well).

@keisku keisku force-pushed the keisku/valkey-go-support branch from 787b31f to 27b0fec Compare January 23, 2025 08:51
@keisku keisku requested a review from rarguelloF January 23, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants