Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions cmd/trace-agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func prepareConfig(path string) (*config.AgentConfig, error) {
cfg.LogFilePath = DefaultLogFilePath
cfg.DDAgentBin = defaultDDAgentBin
cfg.AgentVersion = version.AgentVersion
cfg.GitCommit = version.Commit
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
orch := fargate.GetOrchestrator(ctx)
cancel()
Expand Down
7 changes: 4 additions & 3 deletions cmd/trace-agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package main
import (
"context"
"fmt"
"github.com/DataDog/datadog-agent/pkg/version"
Comment thread
ajgajg1134 marked this conversation as resolved.
Outdated
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -50,7 +51,7 @@ to your datadog.yaml. Exiting...`
// Run is the entrypoint of our code, which starts the agent.
func Run(ctx context.Context) {
if flags.Version {
fmt.Print(info.VersionString())
fmt.Println(version.AgentVersion)
return
}

Expand Down Expand Up @@ -141,7 +142,7 @@ func Run(ctx context.Context) {
return
}

err = metrics.Configure(cfg, []string{"version:" + info.Version})
err = metrics.Configure(cfg, []string{"version:" + cfg.AgentVersion})
Comment thread
ajgajg1134 marked this conversation as resolved.
Outdated
if err != nil {
osutil.Exitf("cannot configure dogstatsd: %v", err)
}
Expand Down Expand Up @@ -296,6 +297,6 @@ func profilingConfig(cfg *config.AgentConfig) *profiling.Settings {
MutexProfileFraction: coreconfig.Datadog.GetInt("internal_profiling.mutex_profile_fraction"),
BlockProfileRate: coreconfig.Datadog.GetInt("internal_profiling.block_profile_rate"),
WithGoroutineProfile: coreconfig.Datadog.GetBool("internal_profiling.enable_goroutine_stacktraces"),
Tags: []string{fmt.Sprintf("version:%s", info.Version)},
Tags: []string{fmt.Sprintf("version:%s", cfg.AgentVersion)},
Comment thread
ajgajg1134 marked this conversation as resolved.
Outdated
}
}
1 change: 0 additions & 1 deletion omnibus/config/software/datadog-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
block do
# defer compilation step in a block to allow getting the project's build version, which is populated
# only once the software that the project takes its version from (i.e. `datadog-agent`) has finished building
env['TRACE_AGENT_VERSION'] = project.build_version.gsub(/[^0-9\.]/, '') # used by gorake.rb in the trace-agent, only keep digits and dots

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.

👍🏻

platform = windows_arch_i386? ? "x86" : "x64"
command "invoke trace-agent.build --python-runtimes #{py_runtimes_arg} --major-version #{major_version_arg} --arch #{platform} --flavor #{flavor_arg}", :env => env

Expand Down
1 change: 0 additions & 1 deletion omnibus/config/software/datadog-iot-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
if windows?
# defer compilation step in a block to allow getting the project's build version, which is populated
# only once the software that the project takes its version from (i.e. `datadog-agent`) has finished building
env['TRACE_AGENT_VERSION'] = project.build_version.gsub(/[^0-9\.]/, '') # used by gorake.rb in the trace-agent, only keep digits and dots
platform = windows_arch_i386? ? "x86" : "x64"
command "invoke trace-agent.build --major-version #{major_version_arg} --arch #{platform}", :env => env
Comment thread
gbbr marked this conversation as resolved.

Expand Down
6 changes: 3 additions & 3 deletions pkg/trace/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (r *HTTPReceiver) buildMux() *http.ServeMux {
if e.IsEnabled != nil && !e.IsEnabled(r.conf) {
continue
}
mux.Handle(e.Pattern, replyWithVersion(hash, e.Handler(r)))
mux.Handle(e.Pattern, replyWithVersion(hash, r.conf.AgentVersion, e.Handler(r)))
}
mux.HandleFunc("/info", infoHandler)

Expand All @@ -121,9 +121,9 @@ func (r *HTTPReceiver) buildMux() *http.ServeMux {

// replyWithVersion returns an http.Handler which calls h with an addition of some
// HTTP headers containing version and state information.
func replyWithVersion(hash string, h http.Handler) http.Handler {
func replyWithVersion(hash string, version string, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Datadog-Agent-Version", info.Version)
w.Header().Set("Datadog-Agent-Version", version)
w.Header().Set("Datadog-Agent-State", hash)
h.ServeHTTP(w, r)
})
Expand Down
6 changes: 4 additions & 2 deletions pkg/trace/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func TestListenTCP(t *testing.T) {

func TestStateHeaders(t *testing.T) {
assert := assert.New(t)
r := newTestReceiverFromConfig(config.New())
cfg := config.New()
cfg.AgentVersion = "testVersion"
r := newTestReceiverFromConfig(cfg)
r.Start()
defer r.Stop()
data := msgpTraces(t, pb.Traces{
Expand All @@ -168,7 +170,7 @@ func TestStateHeaders(t *testing.T) {
_, ok := resp.Header["Datadog-Agent-Version"]
assert.True(ok)
v := resp.Header.Get("Datadog-Agent-Version")
assert.Equal(v, info.Version)
assert.Equal("testVersion", v)

_, ok = resp.Header["Datadog-Agent-State"]
assert.True(ok)
Expand Down
3 changes: 1 addition & 2 deletions pkg/trace/api/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"time"

"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
"github.com/DataDog/datadog-agent/pkg/trace/log"
"github.com/DataDog/datadog-agent/pkg/trace/metrics"
)
Expand All @@ -28,7 +27,7 @@ const (
// debuggerProxyHandler returns an http.Handler proxying requests to the logs intake. If the logs intake url cannot be
// parsed, the returned handler will always return http.StatusInternalServerError with a clarifying message.
func (r *HTTPReceiver) debuggerProxyHandler() http.Handler {
tags := fmt.Sprintf("host:%s,default_env:%s,agent_version:%s", r.conf.Hostname, r.conf.DefaultEnv, info.Version)
tags := fmt.Sprintf("host:%s,default_env:%s,agent_version:%s", r.conf.Hostname, r.conf.DefaultEnv, r.conf.AgentVersion)
if orch := r.conf.FargateOrchestrator; orch != config.OrchestratorUnknown {
tags = tags + ",orchestrator:fargate_" + strings.ToLower(string(orch))
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/trace/api/evp_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/DataDog/datadog-agent/pkg/trace/api/apiutil"
"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
"github.com/DataDog/datadog-agent/pkg/trace/log"
"github.com/DataDog/datadog-agent/pkg/trace/metrics"
)
Expand Down Expand Up @@ -139,7 +138,7 @@ func (t *evpProxyTransport) RoundTrip(req *http.Request) (rresp *http.Response,
req.Header = http.Header{}

// Set standard headers
req.Header.Set("Via", fmt.Sprintf("trace-agent %s", info.Version))
req.Header.Set("Via", fmt.Sprintf("trace-agent %s", t.conf.AgentVersion))
if contentType != "" {
req.Header.Set("Content-Type", contentType)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/trace/api/evp_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"testing"

"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
"github.com/DataDog/datadog-agent/pkg/trace/metrics"
"github.com/DataDog/datadog-agent/pkg/trace/testutil"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -73,6 +72,7 @@ func TestEVPProxyForwarder(t *testing.T) {
conf.Hostname = "test_hostname"
conf.DefaultEnv = "test_env"
conf.Site = "us3.datadoghq.com"
conf.AgentVersion = "testVersion"
conf.Endpoints[0].APIKey = "test_api_key"

req := httptest.NewRequest("POST", "/mypath/mysubpath?arg=test", bytes.NewReader(randBodyBuf))
Expand All @@ -93,7 +93,7 @@ func TestEVPProxyForwarder(t *testing.T) {
assert.Equal(t, "test_api_key", proxyreq.Header.Get("DD-API-KEY"))
assert.Equal(t, conf.Hostname, proxyreq.Header.Get("X-Datadog-Hostname"))
assert.Equal(t, conf.DefaultEnv, proxyreq.Header.Get("X-Datadog-AgentDefaultEnv"))
assert.Equal(t, fmt.Sprintf("trace-agent %s", info.Version), proxyreq.Header.Get("Via"))
assert.Equal(t, "trace-agent testVersion", proxyreq.Header.Get("Via"))
assert.Equal(t, "test_user_agent", proxyreq.Header.Get("User-Agent"))
assert.Equal(t, "text/json", proxyreq.Header.Get("Content-Type"))
assert.NotContains(t, proxyreq.Header, "Unexpected-Header")
Expand Down
13 changes: 6 additions & 7 deletions pkg/trace/api/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/config/features"
"github.com/DataDog/datadog-agent/pkg/trace/info"
)

// makeInfoHandler returns a new handler for handling the discovery endpoint.
Expand Down Expand Up @@ -64,19 +63,19 @@ func (r *HTTPReceiver) makeInfoHandler() (hash string, handler http.HandlerFunc)
oconf.Memcached = o.Memcached.Enabled
}
txt, err := json.MarshalIndent(struct {
Version string `json:"version"`
GitCommit string `json:"git_commit"`
BuildDate string `json:"build_date"`
Version string `json:"version"`
GitCommit string `json:"git_commit"`
// BuildDate string `json:"build_date"`
Endpoints []string `json:"endpoints"`
FeatureFlags []string `json:"feature_flags,omitempty"`
ClientDropP0s bool `json:"client_drop_p0s"`
SpanMetaStructs bool `json:"span_meta_structs"`
LongRunningSpans bool `json:"long_running_spans"`
Config reducedConfig `json:"config"`
}{
Version: info.Version,
GitCommit: info.GitCommit,
BuildDate: info.BuildDate,
Version: r.conf.AgentVersion,
GitCommit: r.conf.GitCommit,
// BuildDate: info.BuildDate, // TODO: this would be a breaking change, it doesn't appear this is used by any of the tracers I searched through
Comment thread
ajgajg1134 marked this conversation as resolved.
Outdated
Endpoints: all,
FeatureFlags: features.All(),
ClientDropP0s: true,
Expand Down
21 changes: 7 additions & 14 deletions pkg/trace/api/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"time"

"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
"github.com/DataDog/datadog-agent/pkg/trace/testutil"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -49,10 +48,12 @@ func TestInfoHandler(t *testing.T) {
Memcached: config.Enablable{Enabled: false},
}
conf := &config.AgentConfig{
Enabled: true,
Hostname: "test.host.name",
DefaultEnv: "prod",
ConfigPath: "/path/to/config",
Enabled: true,
AgentVersion: "0.99.0",
GitCommit: "fab047e10",
Hostname: "test.host.name",
DefaultEnv: "prod",
ConfigPath: "/path/to/config",
Endpoints: []*config.Endpoint{{
APIKey: "123",
Host: "https://target-intake.datadoghq.com",
Expand Down Expand Up @@ -115,7 +116,6 @@ func TestInfoHandler(t *testing.T) {
expected: `{
"version": "0.99.0",
"git_commit": "fab047e10",
"build_date": "2020-12-04 15:57:06.74187 +0200 EET m=+0.029001792",
"endpoints": [
"/v0.3/traces",
"/v0.3/services",
Expand Down Expand Up @@ -175,7 +175,6 @@ func TestInfoHandler(t *testing.T) {
expected: `{
"version": "0.99.0",
"git_commit": "fab047e10",
"build_date": "2020-12-04 15:57:06.74187 +0200 EET m=+0.029001792",
"endpoints": [
"/v0.3/traces",
"/v0.3/services",
Expand Down Expand Up @@ -235,17 +234,11 @@ func TestInfoHandler(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
rcv := newTestReceiverFromConfig(conf)
defer testutil.WithFeatures("feature_flag")()
defer func(old string) { info.Version = old }(info.Version)
defer func(old string) { info.GitCommit = old }(info.GitCommit)
defer func(old string) { info.BuildDate = old }(info.BuildDate)
info.Version = "0.99.0"
info.GitCommit = "fab047e10"
info.BuildDate = "2020-12-04 15:57:06.74187 +0200 EET m=+0.029001792"
_, h := rcv.makeInfoHandler()
rec := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/info", nil)
h.ServeHTTP(rec, req)
assert.Equal(t, rec.Body.String(), tt.expected)
assert.Equal(t, tt.expected, rec.Body.String())
if rec.Body.String() != tt.expected {
t.Fatalf("Output of /info has changed. Changing the keys "+
"is not allowed because the client rely on them and "+
Expand Down
5 changes: 2 additions & 3 deletions pkg/trace/api/pipeline_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"time"

"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
"github.com/DataDog/datadog-agent/pkg/trace/log"
"github.com/DataDog/datadog-agent/pkg/trace/metrics"
)
Expand Down Expand Up @@ -45,7 +44,7 @@ func (r *HTTPReceiver) pipelineStatsProxyHandler() http.Handler {
log.Errorf("Failed to start pipeline stats proxy handler: %v", err)
return pipelineStatsErrorHandler(err)
}
tags := fmt.Sprintf("host:%s,default_env:%s,agent_version:%s", r.conf.Hostname, r.conf.DefaultEnv, info.Version)
tags := fmt.Sprintf("host:%s,default_env:%s,agent_version:%s", r.conf.Hostname, r.conf.DefaultEnv, r.conf.AgentVersion)
if orch := r.conf.FargateOrchestrator; orch != config.OrchestratorUnknown {
tag := fmt.Sprintf("orchestrator:fargate_%s", strings.ToLower(string(orch)))
tags = tags + "," + tag
Expand All @@ -64,7 +63,7 @@ func pipelineStatsErrorHandler(err error) http.Handler {
// The tags will be added as a header to all proxied requests.
func newPipelineStatsProxy(conf *config.AgentConfig, target *url.URL, key string, tags string) *httputil.ReverseProxy {
director := func(req *http.Request) {
req.Header.Set("Via", fmt.Sprintf("trace-agent %s", info.Version))
req.Header.Set("Via", fmt.Sprintf("trace-agent %s", conf.AgentVersion))
if _, ok := req.Header["User-Agent"]; !ok {
// explicitly disable User-Agent so it's not set to the default value
// that net/http gives it: Go-http-client/1.1
Expand Down
5 changes: 2 additions & 3 deletions pkg/trace/api/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"time"

"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
"github.com/DataDog/datadog-agent/pkg/trace/log"
"github.com/DataDog/datadog-agent/pkg/trace/metrics"
)
Expand Down Expand Up @@ -78,7 +77,7 @@ func (r *HTTPReceiver) profileProxyHandler() http.Handler {
if err != nil {
return errorHandler(err)
}
tags := fmt.Sprintf("host:%s,default_env:%s,agent_version:%s", r.conf.Hostname, r.conf.DefaultEnv, info.Version)
tags := fmt.Sprintf("host:%s,default_env:%s,agent_version:%s", r.conf.Hostname, r.conf.DefaultEnv, r.conf.AgentVersion)
if orch := r.conf.FargateOrchestrator; orch != config.OrchestratorUnknown {
tag := fmt.Sprintf("orchestrator:fargate_%s", strings.ToLower(string(orch)))
tags = tags + "," + tag
Expand All @@ -103,7 +102,7 @@ func errorHandler(err error) http.Handler {
// For more details please see multiTransport.
func newProfileProxy(conf *config.AgentConfig, targets []*url.URL, keys []string, tags string) *httputil.ReverseProxy {
director := func(req *http.Request) {
req.Header.Set("Via", fmt.Sprintf("trace-agent %s", info.Version))
req.Header.Set("Via", fmt.Sprintf("trace-agent %s", conf.AgentVersion))
if _, ok := req.Header["User-Agent"]; !ok {
// explicitly disable User-Agent so it's not set to the default value
// that net/http gives it: Go-http-client/1.1
Expand Down
3 changes: 1 addition & 2 deletions pkg/trace/api/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
"github.com/DataDog/datadog-agent/pkg/trace/log"
"github.com/DataDog/datadog-agent/pkg/trace/metrics"
)
Expand Down Expand Up @@ -68,7 +67,7 @@ func (r *HTTPReceiver) telemetryProxyHandler() http.Handler {
limitedLogger := log.NewThrottled(5, 10*time.Second) // limit to 5 messages every 10 seconds
logger := stdlog.New(limitedLogger, "telemetry.Proxy: ", 0)
director := func(req *http.Request) {
req.Header.Set("Via", fmt.Sprintf("trace-agent %s", info.Version))
req.Header.Set("Via", fmt.Sprintf("trace-agent %s", r.conf.AgentVersion))
if _, ok := req.Header["User-Agent"]; !ok {
// explicitly disable User-Agent so it's not set to the default value
// that net/http gives it: Go-http-client/1.1
Expand Down
7 changes: 3 additions & 4 deletions pkg/trace/appsec/appsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/DataDog/datadog-agent/pkg/trace/api/apiutil"
"github.com/DataDog/datadog-agent/pkg/trace/config"
"github.com/DataDog/datadog-agent/pkg/trace/info"
"github.com/DataDog/datadog-agent/pkg/trace/log"
"github.com/DataDog/datadog-agent/pkg/trace/metrics"
)
Expand All @@ -43,16 +42,16 @@ func NewIntakeReverseProxy(conf *config.AgentConfig) (http.Handler, error) {
log.Info("AppSec proxy disabled by configuration")
return disabled("appsec agent disabled by configuration"), nil
}
return newIntakeReverseProxy(cfg.IntakeURL, cfg.APIKey, cfg.MaxPayloadSize, conf.NewHTTPTransport()), nil
return newIntakeReverseProxy(cfg.IntakeURL, cfg.APIKey, cfg.MaxPayloadSize, conf.NewHTTPTransport(), conf.AgentVersion), nil
}

// newIntakeReverseProxy creates a reverse proxy to the intake backend using the
// given transport round-tripper.
// The reverse proxy handler also limits the request body size and adds extra
// headers such as Dd-Api-Key and Via.
func newIntakeReverseProxy(target *url.URL, apiKey string, maxPayloadSize int64, transport http.RoundTripper) http.Handler {
func newIntakeReverseProxy(target *url.URL, apiKey string, maxPayloadSize int64, transport http.RoundTripper, agentVersion string) http.Handler {
proxy := httputil.NewSingleHostReverseProxy(target)
via := fmt.Sprintf("trace-agent %s", info.Version)
via := fmt.Sprintf("trace-agent %s", agentVersion)
// Wrap and overwrite the returned director to add extra headers
director := proxy.Director
proxy.Director = func(req *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/trace/appsec/appsec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestIntakeReverseProxy(t *testing.T) {
)

requireProxyHeaders := func(t *testing.T, req *http.Request) {
require.Contains(t, "trace-agent", req.Header.Get("Via"))
require.Contains(t, "trace-agent 0.99.0", req.Header.Get("Via"))
require.Equal(t, expectedAPIKey, req.Header.Get("Dd-Api-Key"))
}
requireRequest := func(t *testing.T, req *http.Request, expectedMethod, expectedEndpoint string, expectedBody []byte) {
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestIntakeReverseProxy(t *testing.T) {

url, err := url.Parse(srv.URL + expectedServerEndpoint)
require.NoError(t, err)
proxy := newIntakeReverseProxy(url, expectedAPIKey, expectedMaxPayloadSize, http.DefaultTransport)
proxy := newIntakeReverseProxy(url, expectedAPIKey, expectedMaxPayloadSize, http.DefaultTransport, "0.99.0")

req := tc.prepareServerRequest(t)
rec := httptest.NewRecorder()
Expand Down
1 change: 1 addition & 0 deletions pkg/trace/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ type DebuggerProxyConfig struct {
type AgentConfig struct {
Enabled bool
AgentVersion string
GitCommit string
Site string // the intake site to use (e.g. "datadoghq.com")

// FargateOrchestrator specifies the name of the Fargate orchestrator. e.g. "ECS", "EKS", "Unknown"
Expand Down
Loading