Skip to content

Commit

Permalink
[receiver/googlecloudmonitoringreceiver] Transform GCP Timeseries Dat…
Browse files Browse the repository at this point in the history
…a to OTel Metrics Conversion Pipeline (#34677)

**Description:** Transform GCP Timeseries Data to OTel Metrics Pipeline
by establishing a client connection to the Google Cloud Monitoring API.
This PR scrapes timeseries data based on configured metrics and converts
it into the OpenTelemetry format for pipeline processing.

**Link to tracking Issue:** #33762

**Testing:** No additional test cases were added. Existing tests cover
the necessary functionality.

**Documentation:** The **README.md** file was previously added and
already includes relevant details about the component and the conversion
process.
  • Loading branch information
abhishek-at-cloudwerx authored Sep 5, 2024
1 parent 55482cb commit 7ec6396
Show file tree
Hide file tree
Showing 12 changed files with 608 additions and 64 deletions.
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
12 changes: 0 additions & 12 deletions receiver/googlecloudmonitoringreceiver/generated_component_test.go

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

0 comments on commit 7ec6396

Please sign in to comment.