diff --git a/receiver/gitlabreceiver/README.md b/receiver/gitlabreceiver/README.md index ed8e89284c91..de6f9f2b720c 100644 --- a/receiver/gitlabreceiver/README.md +++ b/receiver/gitlabreceiver/README.md @@ -1,5 +1,17 @@ # GitLab Receiver + +| Status | | +| ------------- |-----------| +| Stability | [development]: traces | +| Distributions | [] | +| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fgitlab%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fgitlab) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fgitlab%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fgitlab) | +| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@adrielp](https://www.github.com/adrielp), [@atoulme](https://www.github.com/atoulme) | + +[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development +[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib + + ## Traces - Getting Started Workflow tracing support is actively being added to the GitLab receiver. @@ -7,7 +19,7 @@ This is accomplished through the processing of GitLab webhook events for pipelines. The [`pipeline`](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#pipeline-events) event payloads are then constructed into `trace` telemetry. -Each GitLab pipeline, along with it's jobs, are converted +Each GitLab pipeline, along with its jobs, is converted into trace spans, allowing the observation of workflow execution times, success, and failure rates. diff --git a/receiver/gitlabreceiver/config.go b/receiver/gitlabreceiver/config.go index 556c77b48143..2247bf36f889 100644 --- a/receiver/gitlabreceiver/config.go +++ b/receiver/gitlabreceiver/config.go @@ -9,6 +9,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confighttp" + "go.opentelemetry.io/collector/config/configopaque" "go.uber.org/multierr" ) @@ -33,16 +34,11 @@ type Config struct { } type WebHook struct { - confighttp.ServerConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct - Path string `mapstructure:"path"` // path for data collection. Default is /events - HealthPath string `mapstructure:"health_path"` // path for health check api. Default is /health_check - RequiredHeader RequiredHeader `mapstructure:"required_header"` // optional setting to set a required header for all requests to have - Secret string `mapstructure:"secret"` // secret for webhook -} - -type RequiredHeader struct { - Key string `mapstructure:"key"` - Value string `mapstructure:"value"` + confighttp.ServerConfig `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct + Path string `mapstructure:"path"` // path for data collection. Default is /events + HealthPath string `mapstructure:"health_path"` // path for health check api. Default is /health_check + RequiredHeaders map[string]configopaque.String `mapstructure:"required_headers"` // optional setting to set one or more required headers for all requests to have + Secret string `mapstructure:"secret"` // secret for webhook } func createDefaultConfig() component.Config { @@ -72,8 +68,10 @@ func (cfg *Config) Validate() error { errs = multierr.Append(errs, errWriteTimeoutExceedsMaxValue) } - if (cfg.WebHook.RequiredHeader.Key != "" && cfg.WebHook.RequiredHeader.Value == "") || (cfg.WebHook.RequiredHeader.Value != "" && cfg.WebHook.RequiredHeader.Key == "") { - errs = multierr.Append(errs, errRequiredHeader) + for key, value := range cfg.WebHook.RequiredHeaders { + if key == "" || value == "" { + errs = multierr.Append(errs, errRequiredHeader) + } } return errs diff --git a/receiver/gitlabreceiver/config_test.go b/receiver/gitlabreceiver/config_test.go index 4541d652c344..420746b69683 100644 --- a/receiver/gitlabreceiver/config_test.go +++ b/receiver/gitlabreceiver/config_test.go @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/confighttp" + "go.opentelemetry.io/collector/config/configopaque" "go.opentelemetry.io/collector/otelcol/otelcoltest" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitlabreceiver/internal/metadata" @@ -62,9 +63,8 @@ func TestLoadConfig(t *testing.T) { }, Path: "some/path", HealthPath: "health/path", - RequiredHeader: RequiredHeader{ - Key: "key-present", - Value: "value-present", + RequiredHeaders: map[string]configopaque.String{ + "key-present": "value-present", }, }, } @@ -73,6 +73,11 @@ func TestLoadConfig(t *testing.T) { assert.Equal(t, expectedConfig, r0) + expectedConfig.WebHook.RequiredHeaders = map[string]configopaque.String{ + "key-present": "value-present", + "key2-present": "value2-present", + } + r1 := cfg.Receivers[component.NewIDWithName(metadata.Type, "customname")].(*Config) assert.Equal(t, expectedConfig, r1) diff --git a/receiver/gitlabreceiver/factory.go b/receiver/gitlabreceiver/factory.go index dbcd3b23334f..282d87e6da5f 100644 --- a/receiver/gitlabreceiver/factory.go +++ b/receiver/gitlabreceiver/factory.go @@ -6,11 +6,10 @@ package gitlabreceiver // import "github.com/open-telemetry/opentelemetry-collec import ( "context" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitlabreceiver/internal/metadata" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/receiver" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitlabreceiver/internal/metadata" ) func createTracesReceiver(_ context.Context, params receiver.Settings, cfg component.Config, consumer consumer.Traces) (receiver.Traces, error) { diff --git a/receiver/gitlabreceiver/generated_package_test.go b/receiver/gitlabreceiver/generated_package_test.go index 7224acad01dc..ee31eb1bb61e 100644 --- a/receiver/gitlabreceiver/generated_package_test.go +++ b/receiver/gitlabreceiver/generated_package_test.go @@ -3,9 +3,8 @@ package gitlabreceiver import ( - "testing" - "go.uber.org/goleak" + "testing" ) func TestMain(m *testing.M) { diff --git a/receiver/gitlabreceiver/metadata.yaml b/receiver/gitlabreceiver/metadata.yaml index e04dae8a0a3e..185134234551 100644 --- a/receiver/gitlabreceiver/metadata.yaml +++ b/receiver/gitlabreceiver/metadata.yaml @@ -4,6 +4,10 @@ status: class: receiver stability: development: [traces] - distributions: [contrib] + distributions: [] codeowners: active: [adrielp, atoulme] +tests: + config: + webhook: + endpoint: "localhost:8080" \ No newline at end of file diff --git a/receiver/gitlabreceiver/testdata/config.yaml b/receiver/gitlabreceiver/testdata/config.yaml index 21e4aa691baa..0f3ed2377b71 100644 --- a/receiver/gitlabreceiver/testdata/config.yaml +++ b/receiver/gitlabreceiver/testdata/config.yaml @@ -6,9 +6,8 @@ receivers: write_timeout: "500ms" path: "some/path" health_path: "health/path" - required_header: - key: key-present - value: value-present + required_headers: + key-present: value-present gitlab/customname: webhook: @@ -17,10 +16,10 @@ receivers: write_timeout: "500ms" path: "some/path" health_path: "health/path" - required_header: - key: key-present - value: value-present - + required_headers: + key-present: value-present + key2-present: value2-present + processors: nop: diff --git a/receiver/gitlabreceiver/traces_receiver.go b/receiver/gitlabreceiver/traces_receiver.go index 6856d79f2da3..7d753700cef1 100644 --- a/receiver/gitlabreceiver/traces_receiver.go +++ b/receiver/gitlabreceiver/traces_receiver.go @@ -19,7 +19,7 @@ import ( "go.uber.org/zap" ) -const healthyResponse = `{"text": "Gitlab receiver webhook is healthy"}` +const healthyResponse = `{"text": "GitLab receiver webhook is healthy"}` type gitlabTracesReceiver struct { cfg *Config