config.go 2.3 KB

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