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

telemetry: submit orchestrion_usage counter metric #3015

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 38 additions & 14 deletions ddtrace/tracer/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ func startTelemetry(c *config) {
// Do not do extra work populating config data if instrumentation telemetry is disabled.
return
}
telemetry.GlobalClient.ApplyOps(
telemetry.WithService(c.serviceName),
telemetry.WithEnv(c.env),
telemetry.WithHTTPClient(c.httpClient),
// c.logToStdout is true if serverless is turned on
// c.ciVisibilityAgentless is true if ci visibility mode is turned on and agentless writer is configured
telemetry.WithURL(c.logToStdout || c.ciVisibilityAgentless, c.agentURL.String()),
telemetry.WithVersion(c.version),
)

telemetryConfigs := []telemetry.Configuration{
{Name: "trace_debug_enabled", Value: c.debug},
{Name: "agent_feature_drop_p0s", Value: c.agent.DropP0s},
Expand Down Expand Up @@ -71,6 +63,34 @@ func startTelemetry(c *config) {
c.traceSampleRules.toTelemetry(),
telemetry.Sanitize(telemetry.Configuration{Name: "span_sample_rules", Value: c.spanRules}),
}

// Process orchestrion enablement metric emission...
const orchestrionEnabledMetric = "orchestrion.enabled"
var (
orchestrionEnabledValue float64
orchestrionEnabledTags []string
)
if c.orchestrionCfg.Enabled {
orchestrionEnabledValue = 1
orchestrionEnabledTags = make([]string, 0, len(c.orchestrionCfg.Metadata))
for k, v := range c.orchestrionCfg.Metadata {
telemetryConfigs = append(telemetryConfigs, telemetry.Configuration{Name: "orchestrion_" + k, Value: v})
orchestrionEnabledTags = append(orchestrionEnabledTags, k+":"+v)
}
}

// Apply the GlobalClient options...
telemetry.GlobalClient.ApplyOps(
telemetry.WithService(c.serviceName),
telemetry.WithEnv(c.env),
telemetry.WithHTTPClient(c.httpClient),
// c.logToStdout is true if serverless is turned on
// c.ciVisibilityAgentless is true if ci visibility mode is turned on and agentless writer is configured
telemetry.WithURL(c.logToStdout || c.ciVisibilityAgentless, c.agentURL.String()),
telemetry.WithVersion(c.version),
telemetry.WithHeartbeatMetric(telemetry.NamespaceTracers, telemetry.MetricKindGauge, orchestrionEnabledMetric, func() float64 { return orchestrionEnabledValue }, orchestrionEnabledTags, false),
)

var peerServiceMapping []string
for key, value := range c.peerServiceMappings {
peerServiceMapping = append(peerServiceMapping, fmt.Sprintf("%s:%s", key, value))
Expand Down Expand Up @@ -107,11 +127,15 @@ func startTelemetry(c *config) {
telemetry.Configuration{Name: fmt.Sprintf("sr_%s_(%s)_(%s)", rule.ruleType.String(), service, name),
Value: fmt.Sprintf("rate:%f_maxPerSecond:%f", rule.Rate, rule.MaxPerSecond)})
}
if c.orchestrionCfg.Enabled {
for k, v := range c.orchestrionCfg.Metadata {
telemetryConfigs = append(telemetryConfigs, telemetry.Configuration{Name: "orchestrion_" + k, Value: v})
}
}

// Submit the initial metric tick
telemetry.GlobalClient.Gauge(
telemetry.NamespaceTracers,
orchestrionEnabledMetric, telemetry.GlobalClient.HeartbeatInterval(), orchestrionEnabledValue,
orchestrionEnabledTags,
false, // Go-specific
)

telemetryConfigs = append(telemetryConfigs, additionalConfigs...)
telemetry.GlobalClient.ProductChange(telemetry.NamespaceTracers, true, telemetryConfigs)
}
7 changes: 7 additions & 0 deletions ddtrace/tracer/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package tracer
import (
"fmt"
"testing"
"time"

"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"
Expand Down Expand Up @@ -160,5 +161,11 @@ func TestTelemetryEnabled(t *testing.T) {
telemetry.Check(t, telemetryClient.Configuration, "orchestrion_enabled", true)
telemetry.Check(t, telemetryClient.Configuration, "orchestrion_k1", "v1")
telemetry.Check(t, telemetryClient.Configuration, "orchestrion_k2", "v2")
telemetryClient.AssertCalled(t, "Gauge",
telemetry.NamespaceTracers,
"orchestrion.enabled", time.Second, 1.0,
[]string{"k1:v1", "k2:v2"},
false,
)
})
}
32 changes: 16 additions & 16 deletions internal/civisibility/utils/telemetry/telemetry_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,96 +9,96 @@ import "gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"

// EndpointPayloadBytes records the size in bytes of the serialized payload by CI Visibility.
func EndpointPayloadBytes(endpointType EndpointType, value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "endpoint_payload.bytes", value, removeEmptyStrings([]string{
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "endpoint_payload.bytes", value, removeEmptyStrings([]string{
(string)(endpointType),
}), true)
}

// EndpointPayloadRequestsMs records the time it takes to send the payload sent to the endpoint in ms by CI Visibility.
func EndpointPayloadRequestsMs(endpointType EndpointType, value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "endpoint_payload.requests_ms", value, removeEmptyStrings([]string{
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "endpoint_payload.requests_ms", value, removeEmptyStrings([]string{
(string)(endpointType),
}), true)
}

// EndpointPayloadEventsCount records the number of events in the payload sent to the endpoint by CI Visibility.
func EndpointPayloadEventsCount(endpointType EndpointType, value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "endpoint_payload.events_count", value, removeEmptyStrings([]string{
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "endpoint_payload.events_count", value, removeEmptyStrings([]string{
(string)(endpointType),
}), true)
}

// EndpointEventsSerializationMs records the time it takes to serialize the events in the payload sent to the endpoint in ms by CI Visibility.
func EndpointEventsSerializationMs(endpointType EndpointType, value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "endpoint_payload.events_serialization_ms", value, removeEmptyStrings([]string{
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "endpoint_payload.events_serialization_ms", value, removeEmptyStrings([]string{
(string)(endpointType),
}), true)
}

// GitCommandMs records the time it takes to execute a git command in ms by CI Visibility.
func GitCommandMs(commandType CommandType, value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "git.command_ms", value, removeEmptyStrings([]string{
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "git.command_ms", value, removeEmptyStrings([]string{
(string)(commandType),
}), true)
}

// GitRequestsSearchCommitsMs records the time it takes to get the response of the search commit quest in ms by CI Visibility.
func GitRequestsSearchCommitsMs(responseCompressedType ResponseCompressedType, value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "git_requests.search_commits_ms", value, removeEmptyStrings([]string{
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "git_requests.search_commits_ms", value, removeEmptyStrings([]string{
(string)(responseCompressedType),
}), true)
}

// GitRequestsObjectsPackMs records the time it takes to get the response of the objects pack request in ms by CI Visibility.
func GitRequestsObjectsPackMs(value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "git_requests.objects_pack_ms", value, nil, true)
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "git_requests.objects_pack_ms", value, nil, true)
}

// GitRequestsObjectsPackBytes records the sum of the sizes of the object pack files inside a single payload by CI Visibility
func GitRequestsObjectsPackBytes(value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "git_requests.objects_pack_bytes", value, nil, true)
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "git_requests.objects_pack_bytes", value, nil, true)
}

// GitRequestsObjectsPackFiles records the number of files sent in the object pack payload by CI Visibility.
func GitRequestsObjectsPackFiles(value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "git_requests.objects_pack_files", value, nil, true)
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "git_requests.objects_pack_files", value, nil, true)
}

// GitRequestsSettingsMs records the time it takes to get the response of the settings endpoint request in ms by CI Visibility.
func GitRequestsSettingsMs(value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "git_requests.settings_ms", value, nil, true)
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "git_requests.settings_ms", value, nil, true)
}

// ITRSkippableTestsRequestMs records the time it takes to get the response of the itr skippable tests endpoint request in ms by CI Visibility.
func ITRSkippableTestsRequestMs(value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "itr_skippable_tests.request_ms", value, nil, true)
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "itr_skippable_tests.request_ms", value, nil, true)
}

// ITRSkippableTestsResponseBytes records the number of bytes received by the endpoint. Tagged with a boolean flag set to true if response body is compressed.
func ITRSkippableTestsResponseBytes(responseCompressedType ResponseCompressedType, value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "itr_skippable_tests.response_bytes", value, removeEmptyStrings([]string{
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "itr_skippable_tests.response_bytes", value, removeEmptyStrings([]string{
(string)(responseCompressedType),
}), true)
}

// CodeCoverageFiles records the number of files in the code coverage report by CI Visibility.
func CodeCoverageFiles(value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "code_coverage.files", value, nil, true)
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "code_coverage.files", value, nil, true)
}

// EarlyFlakeDetectionRequestMs records the time it takes to get the response of the early flake detection endpoint request in ms by CI Visibility.
func EarlyFlakeDetectionRequestMs(value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "early_flake_detection.request_ms", value, nil, true)
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "early_flake_detection.request_ms", value, nil, true)
}

// EarlyFlakeDetectionResponseBytes records the number of bytes received by the endpoint. Tagged with a boolean flag set to true if response body is compressed.
func EarlyFlakeDetectionResponseBytes(responseCompressedType ResponseCompressedType, value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "early_flake_detection.response_bytes", value, removeEmptyStrings([]string{
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "early_flake_detection.response_bytes", value, removeEmptyStrings([]string{
(string)(responseCompressedType),
}), true)
}

// EarlyFlakeDetectionResponseTests records the number of tests in the response of the early flake detection endpoint by CI Visibility.
func EarlyFlakeDetectionResponseTests(value float64) {
telemetry.GlobalClient.Record(telemetry.NamespaceCiVisibility, telemetry.MetricKindDist, "early_flake_detection.response_tests", value, nil, true)
telemetry.GlobalClient.Distribution(telemetry.NamespaceCiVisibility, "early_flake_detection.response_tests", value, nil, true)
}
Loading
Loading