Skip to content

Commit 2c80f91

Browse files
authored
feat: Add configurable site (#14266)
Add configurable site to allow other DDog regional sites to be used, if no site is specified the existing behaviour is preserved. fixes: #14265
1 parent 5dcf494 commit 2c80f91

4 files changed

Lines changed: 26 additions & 13 deletions

File tree

plugins/source/datadog/client/client.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ type Client struct {
1414
// It will be passed for each resource fetcher.
1515
logger zerolog.Logger
1616

17+
// The site to use for the API calls - see https://docs.datadoghq.com/getting_started/site/
18+
Site string
19+
1720
Accounts []Account
1821
// this is set by the table client multiplexer
1922
multiplexedAccount Account
@@ -29,22 +32,15 @@ func (c *Client) ID() string {
2932
}
3033

3134
func (c *Client) BuildContextV1(ctx context.Context) context.Context {
32-
return context.WithValue(
33-
ctx,
34-
datadog.ContextAPIKeys,
35-
map[string]datadog.APIKey{
36-
"apiKeyAuth": {
37-
Key: c.multiplexedAccount.APIKey,
38-
},
39-
"appKeyAuth": {
40-
Key: c.multiplexedAccount.AppKey,
41-
},
42-
},
43-
)
35+
return c.buildContext(ctx)
4436
}
4537

4638
func (c *Client) BuildContextV2(ctx context.Context) context.Context {
47-
return context.WithValue(
39+
return c.buildContext(ctx)
40+
}
41+
42+
func (c *Client) buildContext(ctx context.Context) context.Context {
43+
ctx = context.WithValue(
4844
ctx,
4945
datadog.ContextAPIKeys,
5046
map[string]datadog.APIKey{
@@ -56,11 +52,21 @@ func (c *Client) BuildContextV2(ctx context.Context) context.Context {
5652
},
5753
},
5854
)
55+
if c.Site != "" {
56+
ctx = context.WithValue(
57+
ctx,
58+
datadog.ContextServerVariables,
59+
map[string]string{
60+
"site": c.Site,
61+
})
62+
}
63+
return ctx
5964
}
6065

6166
func (c *Client) withAccount(account Account) schema.ClientMeta {
6267
return &Client{
6368
logger: c.logger.With().Str("id", account.Name).Logger(),
69+
Site: c.Site,
6470
Accounts: c.Accounts,
6571
multiplexedAccount: account,
6672
DDServices: c.DDServices,
@@ -81,6 +87,7 @@ func Configure(ctx context.Context, logger zerolog.Logger, spec *Spec) (schema.C
8187

8288
client := Client{
8389
logger: logger,
90+
Site: spec.Site,
8491
Accounts: spec.Accounts,
8592
DDServices: NewDatadogServices(apiClient),
8693
}

plugins/source/datadog/client/spec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package client
33
type Spec struct {
44
Accounts []Account `json:"accounts"`
55
Concurrency int `json:"concurrency"`
6+
Site string `json:"site"`
67
}
78

89
type Account struct {

website/pages/docs/plugins/sources/datadog/_configuration.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ spec:
1414
api_key: <DD_CLIENT_API_KEY> # Required. API key
1515
app_key: <DD_CLIENT_APP_KEY> # Required. App key
1616
# Optional parameters
17+
# site: datadoghq.eu
1718
# concurrency: 10000
1819
```

website/pages/docs/plugins/sources/datadog/configuration.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ This is the (nested) spec used by the Datadog source plugin.
1616

1717
Specify which accounts to sync data from.
1818

19+
- `site` (`string`, optional, default: "")
20+
21+
The Datadog site to connect to. This is usually one of `datadoghq.com` or `datadoghq.eu` - see [site](https://docs.datadoghq.com/getting_started/site/) documentation for more information.
22+
1923
- `concurrency` (`int`, optional, default: `10000`)
2024

2125
A best effort maximum number of Go routines to use. Lower this number to reduce memory usage.

0 commit comments

Comments
 (0)