forked from DataDog/dd-trace-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
68 lines (61 loc) · 2.15 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023 Datadog, Inc.
package remoteconfig
import (
"net/http"
"os"
"time"
"gopkg.in/DataDog/dd-trace-go.v1/internal"
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/version"
)
const (
envPollIntervalSec = "DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS"
)
// ClientConfig contains the required values to configure a remoteconfig client
type ClientConfig struct {
// The address at which the agent is listening for remoteconfig update requests on
AgentURL string
// The semantic version of the user's application
AppVersion string
// The env this tracer is running in
Env string
// The time interval between two client polls to the agent for updates
PollInterval time.Duration
// The tracer's runtime id
RuntimeID string
// The name of the user's application
ServiceName string
// The semantic version of the tracer
TracerVersion string
// The base TUF root metadata file
TUFRoot string
// HTTP is the HTTP client used to receive config updates
HTTP *http.Client
}
// DefaultClientConfig returns the default remote config client configuration
func DefaultClientConfig() ClientConfig {
return ClientConfig{
Env: os.Getenv("DD_ENV"),
HTTP: &http.Client{Timeout: 10 * time.Second},
PollInterval: pollIntervalFromEnv(),
RuntimeID: globalconfig.RuntimeID(),
ServiceName: globalconfig.ServiceName(),
TracerVersion: version.Tag,
TUFRoot: os.Getenv("DD_RC_TUF_ROOT"),
}
}
func pollIntervalFromEnv() time.Duration {
interval := internal.FloatEnv(envPollIntervalSec, 5.0)
if interval < 0 {
log.Debug("Remote config: cannot use a negative poll interval: %s = %f. Defaulting to 5s.", envPollIntervalSec, interval)
interval = 5.0
} else if interval == 0 {
log.Debug("Remote config: poll interval set to 0. Polling will be continuous.")
return time.Nanosecond
}
return time.Duration(interval * float64(time.Second))
}