From bd64974daf833d2255bc87b6ab42c2e91048baa1 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Tue, 12 Mar 2024 08:55:36 -0700 Subject: [PATCH] [chore][CONTRIBUTING.md] Add goleak to new component requirements (#31689) **Description:** The goal is for `goleak` to be required for every package, and also to be [generated by mdatagen](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/30483). Once this is generated by `mdatagen` we'll be able to remove this from manual steps done by the user, but for now it would be good to state the it's required in docs. **Link to tracking Issue:** #30438 --- CONTRIBUTING.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7a7efcb7d413..dd639d9a55a3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -119,7 +119,7 @@ Components refer to connectors, exporters, extensions, processors, and receivers * Implement the [component.Component](https://pkg.go.dev/go.opentelemetry.io/collector/component#Component) interface * Provide a configuration structure which defines the configuration of the component * Provide the implementation which performs the component operation -* Have a `metadata.yaml` file and its generated code (using [mdatadgen](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/cmd/mdatagen/README.md)). +* Have a `metadata.yaml` file and its generated code (using [mdatadgen](https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/mdatagen/README.md)). Familiarize yourself with the interface of the component that you want to write, and use existing implementations as a reference. [Building a Trace Receiver](https://opentelemetry.io/docs/collector/trace-receiver/) tutorial provides a detailed example of building a component. @@ -152,7 +152,26 @@ and its contributors. and in the respective testing harnesses. To align with the test goal of the project, components must be testable within the framework defined within the folder. If a component can not be properly tested within the existing framework, it must increase the non testable components number with a comment within the PR explaining as to why it can not be tested. -- Create a `metadata.yaml` file with at minimum the required fields defined in [metadata-schema.yaml](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/cmd/mdatagen/metadata-schema.yaml). +- Enable [goleak checks](https://github.com/uber-go/goleak) to help ensure your component does not leak goroutines. This + requires adding a file named `package_test.go` to every sub-directory containing tests. This file should have the following contents by default: +``` +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package fooreceiver + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} +``` + +- Create a `metadata.yaml` file with at minimum the required fields defined in [metadata-schema.yaml](https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/mdatagen/metadata-schema.yaml). Here is a minimal representation: ``` type: @@ -181,7 +200,7 @@ status: // Package fooreceiver bars. package fooreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/fooreceiver" ``` -- Type `make update-codeowners`. This will trigger the regeneration of the `.github/CODEOWNERS` file and the [metadata generator](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/cmd/mdatagen/README.md#using-the-metadata-generator) to generate the associated code/documentation. +- Type `make update-codeowners`. This will trigger the regeneration of the `.github/CODEOWNERS` file and the [metadata generator](https://github.com/open-telemetry/opentelemetry-collector/blob/main/cmd/mdatagen/README.md#using-the-metadata-generator) to generate the associated code/documentation. When submitting a component to the community, consider breaking it down into separate PRs as follows: