Skip to content

Commit 2e67b80

Browse files
[receiver/googlecloudmonitoring] Allow overriding default monitoring endpoint (#47984)
Adds an `endpoint` property which overrides the default `monitoring.googleapis.com:443`. This is needed when targeting non-standard universe domains. (e.g. S3NS: https://docs.cloud.google.com/sovereign-controls-by-partners/docs/data-boundaries/france-data-boundary-s3ns)
1 parent 82f2e87 commit 2e67b80

7 files changed

Lines changed: 89 additions & 23 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component: receiver/googlecloudmonitoring
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Allow overriding default endpoint for googlecloudmonitoringreceiver
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [47984]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
Adds an endpoint property which overrides the default monitoring.googleapis.com:443 endpoint.
20+
This is needed when targeting non-standard universe domains (e.g. S3NS: https://docs.cloud.google.com/sovereign-controls-by-partners/docs/data-boundaries/france-data-boundary-s3ns)
21+
22+
# If your change doesn't affect end users or the exported elements of any package,
23+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
24+
# Optional: The change log or logs in which this entry should be included.
25+
# e.g. '[user]' or '[user, api]'
26+
# Include 'user' if the change is relevant to end users.
27+
# Include 'api' if there is a change to a library API.
28+
# Default: '[user]'
29+
change_logs: [user]

receiver/googlecloudmonitoringreceiver/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ receivers:
4141
- `initial_delay` (default = `1s`): defines how long this receiver waits before starting.
4242
- `timeout`: (default = `1m`) The timeout of running commands against the GCP Monitoring REST API.
4343
- `project_id` (Required): The GCP project ID.
44+
- `endpoint` (Optional): Overrides the default `monitoring.googleapis.com:443` endpoint. Use this when targeting non-standard universe domains.
4445
- `metrics_list` (Required): A list of services metrics to monitor.
4546

4647
Each single metric can have the following configuration:

receiver/googlecloudmonitoringreceiver/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ const (
2020
type Config struct {
2121
scraperhelper.ControllerConfig `mapstructure:",squash"`
2222

23-
ProjectID string `mapstructure:"project_id"`
23+
ProjectID string `mapstructure:"project_id"`
24+
// Overrides the default monitoring.googleapis.com:443 endpoint.
25+
// Use this when targeting non-standard universe domains.
26+
Endpoint string `mapstructure:"endpoint"`
2427
MetricsList []MetricConfig `mapstructure:"metrics_list"`
2528
}
2629

receiver/googlecloudmonitoringreceiver/config.schema.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ $defs:
99
type: string
1010
type: object
1111
properties:
12+
endpoint:
13+
description: Overrides the default monitoring.googleapis.com:443 endpoint. Use this when targeting non-standard universe domains.
14+
type: string
1215
metrics_list:
1316
type: array
1417
items:

receiver/googlecloudmonitoringreceiver/config_test.go

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,51 @@ func TestLoadConfig(t *testing.T) {
2121
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
2222
require.NoError(t, err)
2323
factory := NewFactory()
24-
cfg := factory.CreateDefaultConfig()
2524

26-
sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String())
27-
require.NoError(t, err)
28-
require.NoError(t, sub.Unmarshal(cfg))
29-
30-
assert.Equal(t,
31-
&Config{
32-
ControllerConfig: scraperhelper.ControllerConfig{
33-
CollectionInterval: 120 * time.Second,
34-
InitialDelay: 1 * time.Second,
35-
},
36-
ProjectID: "my-project-id",
37-
MetricsList: []MetricConfig{
38-
{
39-
MetricName: "compute.googleapis.com/instance/cpu/usage_time",
25+
tests := []struct {
26+
id component.ID
27+
expected *Config
28+
}{
29+
{
30+
id: component.NewIDWithName(metadata.Type, ""),
31+
expected: &Config{
32+
ControllerConfig: scraperhelper.ControllerConfig{
33+
CollectionInterval: 120 * time.Second,
34+
InitialDelay: 1 * time.Second,
4035
},
41-
{
42-
MetricName: "connectors.googleapis.com/flex/instance/cpu/usage_time",
36+
ProjectID: "my-project-id",
37+
MetricsList: []MetricConfig{
38+
{MetricName: "compute.googleapis.com/instance/cpu/usage_time"},
39+
{MetricName: "connectors.googleapis.com/flex/instance/cpu/usage_time"},
40+
{MetricDescriptorFilter: "metric.type = starts_with(\"compute.googleapis.com\")"},
4341
},
44-
{
45-
MetricDescriptorFilter: "metric.type = starts_with(\"compute.googleapis.com\")",
42+
},
43+
},
44+
{
45+
id: component.NewIDWithName(metadata.Type, "endpoint"),
46+
expected: &Config{
47+
ControllerConfig: scraperhelper.ControllerConfig{
48+
CollectionInterval: 120 * time.Second,
49+
InitialDelay: 1 * time.Second,
50+
},
51+
ProjectID: "my-project-id",
52+
Endpoint: "monitoring.example.com:443",
53+
MetricsList: []MetricConfig{
54+
{MetricName: "compute.googleapis.com/instance/cpu/usage_time"},
4655
},
4756
},
4857
},
49-
cfg,
50-
)
58+
}
59+
60+
for _, tt := range tests {
61+
t.Run(tt.id.String(), func(t *testing.T) {
62+
cfg := factory.CreateDefaultConfig()
63+
sub, err := cm.Sub(tt.id.String())
64+
require.NoError(t, err)
65+
require.NoError(t, sub.Unmarshal(cfg))
66+
assert.Equal(t, tt.expected, cfg)
67+
})
68+
}
5169
}
5270

5371
func TestValidateService(t *testing.T) {

receiver/googlecloudmonitoringreceiver/receiver.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,13 @@ func (mr *monitoringReceiver) initializeClient(ctx context.Context) error {
154154
return fmt.Errorf("failed to find default credentials: %w", err)
155155
}
156156

157+
opts := []option.ClientOption{option.WithCredentials(creds)}
158+
if mr.config.Endpoint != "" {
159+
opts = append(opts, option.WithEndpoint(mr.config.Endpoint))
160+
}
161+
157162
// Attempt to create the monitoring client
158-
client, err := monitoring.NewMetricClient(ctx, option.WithCredentials(creds))
163+
client, err := monitoring.NewMetricClient(ctx, opts...)
159164
if err != nil {
160165
return fmt.Errorf("failed to create a monitoring client: %w", err)
161166
}

receiver/googlecloudmonitoringreceiver/testdata/config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ googlecloudmonitoring:
55
- metric_name: "compute.googleapis.com/instance/cpu/usage_time"
66
- metric_name: "connectors.googleapis.com/flex/instance/cpu/usage_time"
77
- metric_descriptor_filter: "metric.type = starts_with(\"compute.googleapis.com\")"
8+
9+
googlecloudmonitoring/endpoint:
10+
collection_interval: 2m
11+
project_id: my-project-id
12+
endpoint: monitoring.example.com:443
13+
metrics_list:
14+
- metric_name: "compute.googleapis.com/instance/cpu/usage_time"

0 commit comments

Comments
 (0)