Skip to content

ddtrace/tracer: extending sampling rule struct with tags, resource and target_span#2403

Merged
dianashevchenko merged 6 commits into
shevchenko/tag-resource-samplingfrom
shevchenko/extend-trace-sampling-logic
Nov 30, 2023
Merged

ddtrace/tracer: extending sampling rule struct with tags, resource and target_span#2403
dianashevchenko merged 6 commits into
shevchenko/tag-resource-samplingfrom
shevchenko/extend-trace-sampling-logic

Conversation

@dianashevchenko

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR extends the sampling rules to include resource, tags, and target_span. The sampling logic will be added in the subsequent PRs. This PR only modifies the SamplingRule struct, json marshalling and unmarshalling.

Motivation

As part of the Extending sampling efforts to include resource, tags, and target_span fields in the sampling logic.

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.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@dianashevchenko
dianashevchenko requested a review from a team November 30, 2023 13:05
@pr-commenter

pr-commenter Bot commented Nov 30, 2023

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2023-11-30 15:10:27

Comparing candidate commit f4d9f1d in PR branch shevchenko/extend-trace-sampling-logic with baseline commit a6e5ba9 in branch shevchenko/tag-resource-sampling.

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

@ahmed-mez ahmed-mez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! Just added a few minor suggestions.

Comment thread ddtrace/tracer/rules_sampler.go Outdated
Comment thread ddtrace/tracer/rules_sampler.go Outdated
Comment thread ddtrace/tracer/rules_sampler.go Outdated
Comment thread ddtrace/tracer/rules_sampler.go Outdated
Tags map[string]*regexp.Regexp

// TargetSpanRoot specifies whether sampling should be applied to the root spans only.
TargetSpanRoot bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: perhaps TargetRootSpan or just TargetRoot ?

Comment thread ddtrace/tracer/rules_sampler.go
}, {
},
{
value: `[{"target_span": "root", "sample_rate": 1.0,"tags": {"host":"h-1234"}}]`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we cover any and "" as possible values of target_span in the tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test only check validity of the unmarshalling, will add the checks when i add sampling logic itself

@ahmed-mez ahmed-mez Nov 30, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This code block

			var targetRoot bool
			switch strings.ToLower(v.TargetSpan) {
			case "", "root":
				targetRoot = true
			case "any":
				targetRoot = false
			default:
				errs = append(errs, fmt.Sprintf(`at index %d: "target_span" value is not expected, must be in ["any", "root", ""]`, i))
				continue
			}

is in the unmarshalling logic that is being tested, the unit tests of unmarshalSamplingRules should cover it imho.

Current coverage misses any:
image

Comment thread ddtrace/tracer/rules_sampler.go
Comment thread ddtrace/tracer/rules_sampler.go Outdated
@dianashevchenko
dianashevchenko merged commit 5ffad80 into shevchenko/tag-resource-sampling Nov 30, 2023
@dianashevchenko
dianashevchenko deleted the shevchenko/extend-trace-sampling-logic branch November 30, 2023 15:59
ruleN: 1,
},
{
value: `[{"target_span": "root", "sample_rate": 1.0, "tags": {"host":"h-1234"}}]`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should be any not root 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

dammit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will fix now, in the different branch though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants