Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/googlecloudmonitoringreceiver] Transform GCP Timeseries Data to OTel Metrics Conversion Pipeline #34677

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7b08cf8
Feat:
abhishek-at-cloudwerx Aug 13, 2024
534ccbe
Feat:
abhishek-at-cloudwerx Aug 13, 2024
7260457
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 14, 2024
fbea738
Fix:
abhishek-at-cloudwerx Aug 14, 2024
f6ca518
Refactor:
abhishek-at-cloudwerx Aug 16, 2024
7c9bbf4
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 20, 2024
3762de4
Refactor:
abhishek-at-cloudwerx Aug 20, 2024
9fde71a
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 21, 2024
4f86f3d
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 21, 2024
a4767a1
Fix:
abhishek-at-cloudwerx Aug 21, 2024
bfe78b7
Fix:
abhishek-at-cloudwerx Aug 21, 2024
55611cf
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 22, 2024
27714dc
Fix:
abhishek-at-cloudwerx Aug 22, 2024
993a72c
Fix:
abhishek-at-cloudwerx Aug 22, 2024
5d21d96
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 22, 2024
24fc659
Feat:
abhishek-at-cloudwerx Aug 23, 2024
3f2d886
Fix:
abhishek-at-cloudwerx Aug 23, 2024
44e67a2
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 23, 2024
370b576
Fix:
abhishek-at-cloudwerx Aug 27, 2024
eba276d
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 27, 2024
0e2ef74
Fix:
abhishek-at-cloudwerx Aug 27, 2024
8fb8745
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Aug 28, 2024
067ddf0
Fix:
abhishek-at-cloudwerx Aug 28, 2024
df1f1e1
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Sep 2, 2024
b878799
Merge branch 'main' into googlecloudmonitoringreceiver-phase2
abhishek-at-cloudwerx Sep 4, 2024
067124b
Refactor:
abhishek-at-cloudwerx Sep 4, 2024
5ba4881
Fix:
abhishek-at-cloudwerx Sep 5, 2024
7a969c9
Refactor:
abhishek-at-cloudwerx Sep 5, 2024
39cf4b2
Refactor:
abhishek-at-cloudwerx Sep 5, 2024
0917ba4
Fix:
abhishek-at-cloudwerx Sep 5, 2024
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
30 changes: 30 additions & 0 deletions .chloggen/googlecloudmonitoringreceiver-phase2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: googlecloudmonitoringreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Enhancing the Google Cloud monitoring receiver to establish a client connection, scrape GCP Cloud Metrics, and transform them into an OpenTelemetry compatible format for pipeline processing.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [33762]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
- Implements client connection to Google Cloud Monitoring API.
- Scrapes timeseries data based on configured metrics.
- Converts the data into OpenTelemetry format for use in the pipeline.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user, api]
7 changes: 2 additions & 5 deletions receiver/googlecloudmonitoringreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ The following configuration options are supported:
```yaml
receivers:
googlecloudmonitoring:
collection_interval: 120s
collection_interval: 2m # Can be specified in seconds (s), minutes (m), or hours (h)
project_id: my-project-id
metrics_list:
- metric_name: "compute.googleapis.com/instance/cpu/usage_time"
delay: 60s
- metric_name: "connectors.googleapis.com/flex/instance/cpu/usage_time"
delay: 60s
```

- `collection_interval` (Optional): The interval at which metrics are collected. Default is 60s.
- `collection_interval` (Optional): The interval at which metrics are collected. Default is 300s.
- `initial_delay` (default = `1s`): defines how long this receiver waits before starting.
- `timeout`: (default = `1m`) The timeout of running commands against the GCP Monitoring REST API.
- `project_id` (Required): The GCP project ID.
Expand All @@ -44,7 +42,6 @@ receivers:
Each single metric can have the following configuration:

- `metric_name` (Required): The specific metric name to collect.
- `delay` (Optional): The delay before starting the collection of metrics for this service. Default is 0s.


## Authentication with Google Cloud
Expand Down
16 changes: 7 additions & 9 deletions receiver/googlecloudmonitoringreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
"go.opentelemetry.io/collector/receiver/scraperhelper"
)

const minCollectionIntervalSeconds = 60
const (
defaultCollectionInterval = 300 * time.Second // Default value for collection interval
defaultFetchDelay = 60 * time.Second // Default value for fetch delay
)

type Config struct {
scraperhelper.ControllerConfig `mapstructure:",squash"`
Expand All @@ -21,13 +24,12 @@ type Config struct {
}

type MetricConfig struct {
MetricName string `mapstructure:"metric_name"`
Delay time.Duration `mapstructure:"delay"`
MetricName string `mapstructure:"metric_name"`
}

func (config *Config) Validate() error {
if config.CollectionInterval.Seconds() < minCollectionIntervalSeconds {
return fmt.Errorf("\"collection_interval\" must be not lower than %v seconds, current value is %v seconds", minCollectionIntervalSeconds, config.CollectionInterval.Seconds())
if config.CollectionInterval < defaultCollectionInterval {
return fmt.Errorf("\"collection_interval\" must be not lower than the collection interval: %v, current value is %v", defaultCollectionInterval, config.CollectionInterval)
}

if len(config.MetricsList) == 0 {
Expand All @@ -48,9 +50,5 @@ func (metric MetricConfig) Validate() error {
return errors.New("field \"metric_name\" is required and cannot be empty for metric configuration")
}

if metric.Delay < 0 {
return errors.New("field \"delay\" cannot be negative for metric configuration")
}

return nil
}
16 changes: 3 additions & 13 deletions receiver/googlecloudmonitoringreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ func TestLoadConfig(t *testing.T) {
MetricsList: []MetricConfig{
{
MetricName: "compute.googleapis.com/instance/cpu/usage_time",
Delay: 60 * time.Second,
},
{
MetricName: "connectors.googleapis.com/flex/instance/cpu/usage_time",
Delay: 60 * time.Second,
},
},
},
Expand All @@ -57,17 +55,10 @@ func TestValidateService(t *testing.T) {
"Valid Service": {
MetricConfig{
MetricName: "metric_name",
Delay: 0 * time.Second,
}, false},
"Empty MetricName": {
MetricConfig{
MetricName: "",
Delay: 0,
}, true},
"Negative Delay": {
MetricConfig{
MetricName: "metric_name",
Delay: -1 * time.Second,
}, true},
}

Expand All @@ -86,17 +77,16 @@ func TestValidateService(t *testing.T) {
func TestValidateConfig(t *testing.T) {
validMetric := MetricConfig{
MetricName: "metric_name",
Delay: 0 * time.Second,
}

testCases := map[string]struct {
metricsList []MetricConfig
collectionInterval time.Duration
requireError bool
}{
"Valid Config": {[]MetricConfig{validMetric}, 60 * time.Second, false},
"Empty Services": {nil, 60 * time.Second, true},
"Invalid Service in Services": {[]MetricConfig{{}}, 60 * time.Second, true},
"Valid Config": {[]MetricConfig{validMetric}, 300 * time.Second, false},
"Empty Services": {nil, 300 * time.Second, true},
"Invalid Service in Services": {[]MetricConfig{{}}, 300 * time.Second, true},
"Invalid Collection Interval": {[]MetricConfig{validMetric}, 0 * time.Second, true},
}

Expand Down
5 changes: 4 additions & 1 deletion receiver/googlecloudmonitoringreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ func NewFactory() receiver.Factory {

// createDefaultConfig creates the default exporter configuration
func createDefaultConfig() component.Config {
cfg := scraperhelper.NewDefaultControllerConfig()
cfg.CollectionInterval = defaultCollectionInterval

return &Config{
ControllerConfig: scraperhelper.NewDefaultControllerConfig(),
ControllerConfig: cfg,
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion receiver/googlecloudmonitoringreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,28 @@ require (
go.opentelemetry.io/collector/pdata v1.14.2-0.20240904075637-48b11ba1c5f8
go.opentelemetry.io/collector/receiver v0.108.2-0.20240904075637-48b11ba1c5f8
go.uber.org/zap v1.27.0
golang.org/x/oauth2 v0.22.0
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd
)

require (
cloud.google.com/go/auth v0.8.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20240730163845-b1a4ccb954bf // indirect
)

require (
cloud.google.com/go/monitoring v1.20.4
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -52,8 +71,9 @@ require (
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/api v0.191.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/grpc v1.66.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading