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

pkg/trace/api: add additional fields to info endpoint. #28861

Merged
merged 5 commits into from
Sep 17, 2024
Merged
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
17 changes: 16 additions & 1 deletion pkg/trace/api/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"encoding/json"
"fmt"
"net/http"
"slices"

"github.com/DataDog/datadog-agent/pkg/obfuscate"
"github.com/DataDog/datadog-agent/pkg/trace/stats"
)

// makeInfoHandler returns a new handler for handling the discovery endpoint.
Expand Down Expand Up @@ -61,6 +63,17 @@ func (r *HTTPReceiver) makeInfoHandler() (hash string, handler http.HandlerFunc)
oconf.Redis = o.Redis
oconf.Memcached = o.Memcached
}

// We check that endpoints contains stats, even though we know this version of the
// agent supports it. It's conceivable that the stats endpoint could be disabled at some point
// so this is defensive against that case.
canDropP0 := !r.conf.ProbabilisticSamplerEnabled && slices.Contains(all, "/v0.6/stats")

var spanKindsStatsComputed []string
if r.conf.ComputeStatsBySpanKind {
spanKindsStatsComputed = stats.KindsComputed
}

txt, err := json.MarshalIndent(struct {
Version string `json:"version"`
GitCommit string `json:"git_commit"`
Expand All @@ -72,15 +85,17 @@ func (r *HTTPReceiver) makeInfoHandler() (hash string, handler http.HandlerFunc)
EvpProxyAllowedHeaders []string `json:"evp_proxy_allowed_headers"`
Config reducedConfig `json:"config"`
PeerTags []string `json:"peer_tags"`
SpanKindsStatsComputed []string `json:"span_kinds_stats_computed"`
}{
Version: r.conf.AgentVersion,
GitCommit: r.conf.GitCommit,
Endpoints: all,
FeatureFlags: r.conf.AllFeatures(),
ClientDropP0s: true,
ClientDropP0s: canDropP0,
SpanMetaStructs: true,
LongRunningSpans: true,
EvpProxyAllowedHeaders: EvpProxyAllowedHeaders,
SpanKindsStatsComputed: spanKindsStatsComputed,
Config: reducedConfig{
DefaultEnv: r.conf.DefaultEnv,
TargetTPS: r.conf.TargetTPS,
Expand Down
1 change: 1 addition & 0 deletions pkg/trace/api/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func TestInfoHandler(t *testing.T) {
"long_running_spans": nil,
"evp_proxy_allowed_headers": nil,
"peer_tags": nil,
"span_kinds_stats_computed": nil,
"config": map[string]interface{}{
"default_env": nil,
"target_tps": nil,
Expand Down
17 changes: 11 additions & 6 deletions pkg/trace/stats/span_concentrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package stats

import (
"slices"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -159,12 +160,16 @@ func (sc *SpanConcentrator) NewStatSpan(
// computeStatsForSpanKind returns true if the span.kind value makes the span eligible for stats computation.
func computeStatsForSpanKind(kind string) bool {
k := strings.ToLower(kind)
switch k {
case "server", "consumer", "client", "producer":
return true
default:
return false
}
return slices.Contains(KindsComputed, k)
}

// KindsComputed is the list of span kinds that will have stats computed on them
// when computeStatsByKind is enabled in the concentrator.
var KindsComputed = []string{
"server",
"consumer",
"client",
"producer",
}

func (sc *SpanConcentrator) addSpan(s *StatSpan, aggKey PayloadAggregationKey, containerID string, containerTags []string, origin string, weight float64) {
Expand Down
Loading