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

[CI Visibility] Add support for CI Visibility mode in ddtrace #2739

Conversation

tonyredondo
Copy link
Member

@tonyredondo tonyredondo commented Jun 12, 2024

What does this PR do?

This PR is a continuation of #2736 and adds support for CI Visibility mode inside ddtrace.

When the CI Visibility mode is enabled, the tracer is initialised with the CIVisibility Writer, Transport and the custom Payload format.

The PR tries to reduce the impact on the current tracer code, by only modifying the options file to check if the civisibility mode is enabled and change the configuration to the ci visibility defaults, including the new transport. It also changes the tracer file to set the civisibility writer when the civisibility mode is enabled.

Motivation

The CI Visibility agentless intake has a custom payload format based on events.
We want to reuse the current tracer implementation but making it compatible with the ci visibility format (aka CI Visibility Protocol) required to support Test Suite Level Visibility (tslv)

More information about the protocol and TSLV can be found here and here

Stacked PRs

  1. [CI Visibility] Initial internal consts and utilities #2736
  2. [CI Visibility] Add support for CI Visibility mode in ddtrace #2739 | [This one]
  3. [CI Visibility] Manual Api and Go/Testing integration #2742

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.

Unsure? Have a question? Request a review!

ddtrace/tracer/civisibility_transport_test.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_tslv.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_tslv.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_tslv.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_tslv.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_transport.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_transport.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_transport.go Outdated Show resolved Hide resolved
@pr-commenter
Copy link

pr-commenter bot commented Jun 12, 2024

Benchmarks

Benchmark execution time: 2024-07-05 10:34:05

Comparing candidate commit 93cfbc8 in PR branch tony/civisibility-part2-ddtrace-modifications with baseline commit 1987b7b in branch tony/civisibility-part1-consts-and-utils.

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

scenario:BenchmarkHttpServeTrace-24

  • 🟩 execution_time [-747.244ns; -644.756ns] or [-4.317%; -3.725%]

@tonyredondo tonyredondo marked this pull request as ready for review June 12, 2024 10:35
@tonyredondo tonyredondo requested a review from a team as a code owner June 12, 2024 10:35
@tonyredondo tonyredondo force-pushed the tony/civisibility-part1-consts-and-utils branch from 615ef86 to ccc1a39 Compare June 13, 2024 13:37
@tonyredondo tonyredondo requested review from a team as code owners June 13, 2024 13:37
@tonyredondo tonyredondo force-pushed the tony/civisibility-part2-ddtrace-modifications branch from 47ea235 to 5862d18 Compare June 13, 2024 13:54
Copy link
Contributor

@ManuelPalenzuelaDD ManuelPalenzuelaDD left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@darccio darccio left a comment

Choose a reason for hiding this comment

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

Some comments of things I saw on a first cursory review. I'll be OOO, so maybe @dianashevchenko can take another look.

ddtrace/tracer/civisibility_payload.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_payload.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_transport.go Outdated Show resolved Hide resolved
Copy link
Member

@darccio darccio left a comment

Choose a reason for hiding this comment

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

I had to review it at last hour before going OOO, so consider this approval just a way to unlock it :) I'd appreciate if more eyes can take a deeper look cc @dianashevchenko

ddtrace/tracer/option.go Outdated Show resolved Hide resolved
@tonyredondo tonyredondo force-pushed the tony/civisibility-part2-ddtrace-modifications branch from c7de335 to e3400dd Compare June 14, 2024 08:02
ddtrace/tracer/civisibility_transport_test.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_payload_test.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_transport.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_payload_test.go Show resolved Hide resolved
ddtrace/tracer/civisibility_writer.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_writer.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_writer.go Show resolved Hide resolved
ddtrace/tracer/civisibility_writer_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

golangci

ddtrace/tracer/civisibility_tslv.go|303 col 59| undefined: constants.TestSuiteIDTagName
ddtrace/tracer/civisibility_tslv.go|323 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|323 col 61| too many errors) (typecheck)
ddtrace/tracer/civisibility_transport.go|72 col 49| undefined: constants.CiVisibilityAgentlessEnabledEnvironmentVariable
ddtrace/tracer/civisibility_transport.go|87 col 31| undefined: constants.CiVisibilityAgentlessURLEnvironmentVariable
ddtrace/tracer/civisibility_tslv.go|276 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|277 col 60| undefined: constants.TestModuleIDTagName
ddtrace/tracer/civisibility_tslv.go|278 col 59| undefined: constants.TestSuiteIDTagName
ddtrace/tracer/civisibility_tslv.go|279 col 57| undefined: constants.ItrCorrelationIDTagName
ddtrace/tracer/civisibility_tslv.go|301 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|302 col 60| undefined: constants.TestModuleIDTagName
ddtrace/tracer/civisibility_tslv.go|303 col 59| undefined: constants.TestSuiteIDTagName
ddtrace/tracer/civisibility_tslv.go|323 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|323 col 61| too many errors (typecheck)
ddtrace/tracer/civisibility_transport.go|72 col 49| undefined: constants.CiVisibilityAgentlessEnabledEnvironmentVariable
ddtrace/tracer/civisibility_transport.go|87 col 31| undefined: constants.CiVisibilityAgentlessURLEnvironmentVariable
ddtrace/tracer/civisibility_tslv.go|276 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|277 col 60| undefined: constants.TestModuleIDTagName
ddtrace/tracer/civisibility_tslv.go|278 col 59| undefined: constants.TestSuiteIDTagName
ddtrace/tracer/civisibility_tslv.go|279 col 57| undefined: constants.ItrCorrelationIDTagName
ddtrace/tracer/civisibility_tslv.go|301 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|302 col 60| undefined: constants.TestModuleIDTagName
ddtrace/tracer/civisibility_tslv.go|303 col 59| undefined: constants.TestSuiteIDTagName
ddtrace/tracer/civisibility_tslv.go|323 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|323 col 61| too many errors) (typecheck)
ddtrace/tracer/civisibility_transport.go|72 col 49| undefined: constants.CiVisibilityAgentlessEnabledEnvironmentVariable
ddtrace/tracer/civisibility_transport.go|87 col 31| undefined: constants.CiVisibilityAgentlessURLEnvironmentVariable
ddtrace/tracer/civisibility_tslv.go|276 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|277 col 60| undefined: constants.TestModuleIDTagName
ddtrace/tracer/civisibility_tslv.go|278 col 59| undefined: constants.TestSuiteIDTagName
ddtrace/tracer/civisibility_tslv.go|279 col 57| undefined: constants.ItrCorrelationIDTagName
ddtrace/tracer/civisibility_tslv.go|301 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|302 col 60| undefined: constants.TestModuleIDTagName
ddtrace/tracer/civisibility_tslv.go|303 col 59| undefined: constants.TestSuiteIDTagName
ddtrace/tracer/civisibility_tslv.go|323 col 61| undefined: constants.TestSessionIDTagName
ddtrace/tracer/civisibility_tslv.go|323 col 61| too many errors) (typecheck)

ddtrace/tracer/civisibility_transport.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_transport.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_tslv.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_tslv.go Outdated Show resolved Hide resolved
ddtrace/tracer/civisibility_tslv.go Outdated Show resolved Hide resolved
func createTestEventFromSpan(span *span) *ciVisibilityEvent {
tSpan := createTslvSpan(span)
tSpan.SessionID = getAndRemoveMetaToUInt64(span, constants.TestSessionIDTagName)
tSpan.ModuleID = getAndRemoveMetaToUInt64(span, constants.TestModuleIDTagName)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestModuleIDTagName

tSpan := createTslvSpan(span)
tSpan.SessionID = getAndRemoveMetaToUInt64(span, constants.TestSessionIDTagName)
tSpan.ModuleID = getAndRemoveMetaToUInt64(span, constants.TestModuleIDTagName)
tSpan.SuiteID = getAndRemoveMetaToUInt64(span, constants.TestSuiteIDTagName)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestSuiteIDTagName

tSpan.SessionID = getAndRemoveMetaToUInt64(span, constants.TestSessionIDTagName)
tSpan.ModuleID = getAndRemoveMetaToUInt64(span, constants.TestModuleIDTagName)
tSpan.SuiteID = getAndRemoveMetaToUInt64(span, constants.TestSuiteIDTagName)
tSpan.CorrelationID = getAndRemoveMeta(span, constants.ItrCorrelationIDTagName)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.ItrCorrelationIDTagName

// A pointer to the created ciVisibilityEvent.
func createTestSuiteEventFromSpan(span *span) *ciVisibilityEvent {
tSpan := createTslvSpan(span)
tSpan.SessionID = getAndRemoveMetaToUInt64(span, constants.TestSessionIDTagName)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestSessionIDTagName

func createTestSuiteEventFromSpan(span *span) *ciVisibilityEvent {
tSpan := createTslvSpan(span)
tSpan.SessionID = getAndRemoveMetaToUInt64(span, constants.TestSessionIDTagName)
tSpan.ModuleID = getAndRemoveMetaToUInt64(span, constants.TestModuleIDTagName)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestModuleIDTagName

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

golangci

internal/civisibility/integrations/gotesting/testing_test.go|297 col 40| undefined: constants.TestModuleIDTagName (typecheck)
internal/civisibility/integrations/gotesting/testing_test.go|298 col 40| undefined: constants.TestSuiteIDTagName (typecheck)

func internalCiVisibilityInitialization(tracerInitializer func([]tracer.StartOption)) {
ciVisibilityInitializationOnce.Do(func() {
// Since calling this method indicates we are in CI Visibility mode, set the environment variable.
_ = os.Setenv(constants.CiVisibilityEnabledEnvironmentVariable, "1")
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.CiVisibilityEnabledEnvironmentVariable

_ = utils.GetCodeOwners()

// Preload all CI, Git, and CodeOwners tags.
ciTags := utils.GetCiTags()
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: utils.GetCiTags

}...)

// Apply CI tags
for k, v := range utils.GetCiTags() {
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: utils.GetCiTags


span, ctx := tracer.StartSpanFromContext(context.Background(), operationName, testOpts...)
if suite.module.session != nil {
span.SetTag(constants.TestSessionIDTagName, fmt.Sprint(suite.module.session.sessionID))
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestSessionIDTagName

if suite.module.session != nil {
span.SetTag(constants.TestSessionIDTagName, fmt.Sprint(suite.module.session.sessionID))
}
span.SetTag(constants.TestModuleIDTagName, fmt.Sprint(suite.module.moduleID))
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestModuleIDTagName

span.SetTag(constants.TestSessionIDTagName, fmt.Sprint(suite.module.session.sessionID))
}
span.SetTag(constants.TestModuleIDTagName, fmt.Sprint(suite.module.moduleID))
span.SetTag(constants.TestSuiteIDTagName, fmt.Sprint(suite.suiteID))
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestSuiteIDTagName

}

file, line := fn.FileLine(fn.Entry())
file = utils.GetRelativePathFromCiTagsSourceRoot(file)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: utils.GetRelativePathFromCiTagsSourceRoot


codeOwners := utils.GetCodeOwners()
if codeOwners != nil {
match := codeOwners.Match("/" + file)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
assignment mismatch: 1 variable but codeOwners.Match returns 2 values

span, ctx := tracer.StartSpanFromContext(context.Background(), operationName, testOpts...)
moduleID := span.Context().SpanID()
if session != nil {
span.SetTag(constants.TestSessionIDTagName, fmt.Sprint(session.sessionID))
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestSessionIDTagName

if session != nil {
span.SetTag(constants.TestSessionIDTagName, fmt.Sprint(session.sessionID))
}
span.SetTag(constants.TestModuleIDTagName, fmt.Sprint(moduleID))
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
undefined: constants.TestModuleIDTagName

@liashenko liashenko merged commit 1aba968 into tony/civisibility-part1-consts-and-utils Jul 8, 2024
156 checks passed
@liashenko liashenko deleted the tony/civisibility-part2-ddtrace-modifications branch July 8, 2024 09:32
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.

5 participants