diff --git a/.chloggen/pkg-status.yaml b/.chloggen/pkg-status.yaml new file mode 100644 index 000000000000..0e3a45ceb50d --- /dev/null +++ b/.chloggen/pkg-status.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: new_component + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/status + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Refactors the extension/healthcheckv2extension/internal/status into pkg/status + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [34692] + +# (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: + +# 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: [api] diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 587df26bad20..5087e38e9272 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -156,6 +156,7 @@ pkg/resourcetotelemetry/ @open-teleme pkg/sampling/ @open-telemetry/collector-contrib-approvers @kentquirk @jmacd pkg/stanza/ @open-telemetry/collector-contrib-approvers @djaglowski pkg/stanza/fileconsumer/ @open-telemetry/collector-contrib-approvers @djaglowski +pkg/status/ @open-telemetry/collector-contrib-approvers @jpkrohling @mwear pkg/translator/azure/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers @atoulme @cparkins pkg/translator/azurelogs/ @open-telemetry/collector-contrib-approvers @atoulme @cparkins @MikeGoldsmith pkg/translator/jaeger/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers @frzifus diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 414d3b55dd18..359cb4a6b06a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -152,6 +152,7 @@ body: - pkg/sampling - pkg/stanza - pkg/stanza/fileconsumer + - pkg/status - pkg/translator/azure - pkg/translator/azurelogs - pkg/translator/jaeger diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index e7735b4741c0..5203d2e7659b 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -146,6 +146,7 @@ body: - pkg/sampling - pkg/stanza - pkg/stanza/fileconsumer + - pkg/status - pkg/translator/azure - pkg/translator/azurelogs - pkg/translator/jaeger diff --git a/.github/ISSUE_TEMPLATE/other.yaml b/.github/ISSUE_TEMPLATE/other.yaml index cf05bfa8a075..11380d858eaa 100644 --- a/.github/ISSUE_TEMPLATE/other.yaml +++ b/.github/ISSUE_TEMPLATE/other.yaml @@ -146,6 +146,7 @@ body: - pkg/sampling - pkg/stanza - pkg/stanza/fileconsumer + - pkg/status - pkg/translator/azure - pkg/translator/azurelogs - pkg/translator/jaeger diff --git a/.github/ISSUE_TEMPLATE/unmaintained.yaml b/.github/ISSUE_TEMPLATE/unmaintained.yaml index ef8383e2d661..ef4baccf3a5c 100644 --- a/.github/ISSUE_TEMPLATE/unmaintained.yaml +++ b/.github/ISSUE_TEMPLATE/unmaintained.yaml @@ -151,6 +151,7 @@ body: - pkg/sampling - pkg/stanza - pkg/stanza/fileconsumer + - pkg/status - pkg/translator/azure - pkg/translator/azurelogs - pkg/translator/jaeger diff --git a/cmd/otelcontribcol/builder-config.yaml b/cmd/otelcontribcol/builder-config.yaml index 97c311a10817..9dcc6cc77991 100644 --- a/cmd/otelcontribcol/builder-config.yaml +++ b/cmd/otelcontribcol/builder-config.yaml @@ -496,3 +496,4 @@ replaces: - github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver => ../../receiver/githubreceiver - github.com/open-telemetry/opentelemetry-collector-contrib/internal/grpcutil => ../../internal/grpcutil - github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudmonitoringreceiver => ../../receiver/googlecloudmonitoringreceiver + - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status => ../../pkg/status diff --git a/extension/healthcheckv2extension/extension.go b/extension/healthcheckv2extension/extension.go index afcaceb36cb9..23a307c9a9cf 100644 --- a/extension/healthcheckv2extension/extension.go +++ b/extension/healthcheckv2extension/extension.go @@ -16,7 +16,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/grpc" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/http" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" ) type eventSourcePair struct { diff --git a/extension/healthcheckv2extension/extension_test.go b/extension/healthcheckv2extension/extension_test.go index bb15441a1aae..c15acc269245 100644 --- a/extension/healthcheckv2extension/extension_test.go +++ b/extension/healthcheckv2extension/extension_test.go @@ -20,9 +20,9 @@ import ( "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/extension/extensiontest" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/testhelpers" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status/testhelpers" ) func TestComponentStatus(t *testing.T) { diff --git a/extension/healthcheckv2extension/go.mod b/extension/healthcheckv2extension/go.mod index 2d52fe18d108..600b083fc74c 100644 --- a/extension/healthcheckv2extension/go.mod +++ b/extension/healthcheckv2extension/go.mod @@ -4,6 +4,7 @@ go 1.22.0 require ( github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.111.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status v0.111.0 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/component/componentstatus v0.111.1-0.20241008154146-ea48c09c31ae @@ -14,7 +15,6 @@ require ( go.opentelemetry.io/collector/confmap v1.17.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/extension v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/extension/extensioncapabilities v0.111.1-0.20241008154146-ea48c09c31ae - go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae go.uber.org/goleak v1.3.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 @@ -51,6 +51,7 @@ require ( go.opentelemetry.io/collector/featuregate v1.17.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.55.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect go.opentelemetry.io/otel v1.30.0 // indirect @@ -67,3 +68,5 @@ require ( ) replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common + +replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status => ../../pkg/status diff --git a/extension/healthcheckv2extension/internal/grpc/grpc.go b/extension/healthcheckv2extension/internal/grpc/grpc.go index b457c18e7d4a..2f8ad037c490 100644 --- a/extension/healthcheckv2extension/internal/grpc/grpc.go +++ b/extension/healthcheckv2extension/internal/grpc/grpc.go @@ -12,7 +12,7 @@ import ( healthpb "google.golang.org/grpc/health/grpc_health_v1" grpcstatus "google.golang.org/grpc/status" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" ) var ( diff --git a/extension/healthcheckv2extension/internal/grpc/grpc_test.go b/extension/healthcheckv2extension/internal/grpc/grpc_test.go index f6f689b01c0a..837a58ebdf63 100644 --- a/extension/healthcheckv2extension/internal/grpc/grpc_test.go +++ b/extension/healthcheckv2extension/internal/grpc/grpc_test.go @@ -22,9 +22,10 @@ import ( grpcstatus "google.golang.org/grpc/status" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/common" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/testhelpers" + internalhelpers "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/testhelpers" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status/testhelpers" ) func TestCheck(t *testing.T) { @@ -695,7 +696,7 @@ func TestCheck(t *testing.T) { config, tc.componentHealthSettings, componenttest.NewNopTelemetrySettings(), - status.NewAggregator(testhelpers.ErrPriority(tc.componentHealthSettings)), + status.NewAggregator(internalhelpers.ErrPriority(tc.componentHealthSettings)), ) require.NoError(t, server.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, server.Shutdown(context.Background())) }) @@ -1532,7 +1533,7 @@ func TestWatch(t *testing.T) { config, tc.componentHealthSettings, componenttest.NewNopTelemetrySettings(), - status.NewAggregator(testhelpers.ErrPriority(tc.componentHealthSettings)), + status.NewAggregator(internalhelpers.ErrPriority(tc.componentHealthSettings)), ) require.NoError(t, server.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, server.Shutdown(context.Background())) }) diff --git a/extension/healthcheckv2extension/internal/grpc/server.go b/extension/healthcheckv2extension/internal/grpc/server.go index e9a9e3ff92ee..2c69e5fb9e61 100644 --- a/extension/healthcheckv2extension/internal/grpc/server.go +++ b/extension/healthcheckv2extension/internal/grpc/server.go @@ -13,7 +13,7 @@ import ( healthpb "google.golang.org/grpc/health/grpc_health_v1" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/common" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" ) type Server struct { diff --git a/extension/healthcheckv2extension/internal/http/handlers.go b/extension/healthcheckv2extension/internal/http/handlers.go index 186add81504b..2ae041558038 100644 --- a/extension/healthcheckv2extension/internal/http/handlers.go +++ b/extension/healthcheckv2extension/internal/http/handlers.go @@ -6,7 +6,7 @@ package http // import "github.com/open-telemetry/opentelemetry-collector-contri import ( "net/http" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" ) func (s *Server) statusHandler() http.Handler { diff --git a/extension/healthcheckv2extension/internal/http/responders.go b/extension/healthcheckv2extension/internal/http/responders.go index 6cb4ed6e3dd0..5dfc3b2cfe09 100644 --- a/extension/healthcheckv2extension/internal/http/responders.go +++ b/extension/healthcheckv2extension/internal/http/responders.go @@ -12,7 +12,7 @@ import ( "go.opentelemetry.io/collector/component/componentstatus" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/common" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" ) var responseCodes = map[componentstatus.Status]int{ diff --git a/extension/healthcheckv2extension/internal/http/serialization.go b/extension/healthcheckv2extension/internal/http/serialization.go index ce98541e3678..a1a61c72ebfc 100644 --- a/extension/healthcheckv2extension/internal/http/serialization.go +++ b/extension/healthcheckv2extension/internal/http/serialization.go @@ -8,7 +8,7 @@ import ( "go.opentelemetry.io/collector/component/componentstatus" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" ) type healthyFunc func(status.Event) bool diff --git a/extension/healthcheckv2extension/internal/http/server.go b/extension/healthcheckv2extension/internal/http/server.go index 42e6b943b3c8..d38f9f3944c0 100644 --- a/extension/healthcheckv2extension/internal/http/server.go +++ b/extension/healthcheckv2extension/internal/http/server.go @@ -20,7 +20,7 @@ import ( "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/common" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" ) type Server struct { diff --git a/extension/healthcheckv2extension/internal/http/server_test.go b/extension/healthcheckv2extension/internal/http/server_test.go index fb3e671a7fd3..4a11d0138d55 100644 --- a/extension/healthcheckv2extension/internal/http/server_test.go +++ b/extension/healthcheckv2extension/internal/http/server_test.go @@ -23,9 +23,10 @@ import ( "go.opentelemetry.io/collector/confmap/confmaptest" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/common" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/testhelpers" + internalhelpers "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/testhelpers" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status/testhelpers" ) // These are used for the legacy test assertions @@ -2942,7 +2943,7 @@ func TestStatus(t *testing.T) { tc.legacyConfig, tc.componentHealthConfig, componenttest.NewNopTelemetrySettings(), - status.NewAggregator(testhelpers.ErrPriority(tc.componentHealthConfig)), + status.NewAggregator(internalhelpers.ErrPriority(tc.componentHealthConfig)), ) require.NoError(t, server.Start(context.Background(), componenttest.NewNopHost())) diff --git a/extension/healthcheckv2extension/internal/status/package_test.go b/extension/healthcheckv2extension/internal/status/package_test.go deleted file mode 100644 index 312e32157c05..000000000000 --- a/extension/healthcheckv2extension/internal/status/package_test.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright The OpenTelemetry Authors -// SPDX-License-Identifier: Apache-2.0 - -package status // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" - -import ( - "testing" - - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) -} diff --git a/extension/healthcheckv2extension/internal/testhelpers/helpers.go b/extension/healthcheckv2extension/internal/testhelpers/helpers.go index 57d44301b985..1377c040d84f 100644 --- a/extension/healthcheckv2extension/internal/testhelpers/helpers.go +++ b/extension/healthcheckv2extension/internal/testhelpers/helpers.go @@ -4,61 +4,10 @@ package testhelpers // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/testhelpers" import ( - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componentstatus" - "go.opentelemetry.io/collector/pipeline" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/common" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" ) -// PipelineMetadata groups together component and instance IDs for a hypothetical pipeline used -// for testing purposes. -type PipelineMetadata struct { - PipelineID pipeline.ID - ReceiverID *componentstatus.InstanceID - ProcessorID *componentstatus.InstanceID - ExporterID *componentstatus.InstanceID -} - -// InstanceIDs returns a slice of instanceIDs for components within the hypothetical pipeline. -func (p *PipelineMetadata) InstanceIDs() []*componentstatus.InstanceID { - return []*componentstatus.InstanceID{p.ReceiverID, p.ProcessorID, p.ExporterID} -} - -// NewPipelineMetadata returns a metadata for a hypothetical pipeline. -func NewPipelineMetadata(typestr string) *PipelineMetadata { - pipelineID := pipeline.MustNewID(typestr) - return &PipelineMetadata{ - PipelineID: pipelineID, - ReceiverID: componentstatus.NewInstanceID(component.NewIDWithName(component.MustNewType(typestr), "in"), component.KindReceiver).WithPipelines(pipelineID), - ProcessorID: componentstatus.NewInstanceID(component.MustNewID("batch"), component.KindProcessor).WithPipelines(pipelineID), - ExporterID: componentstatus.NewInstanceID(component.NewIDWithName(component.MustNewType(typestr), "out"), component.KindExporter).WithPipelines(pipelineID), - } -} - -// NewPipelines returns a map of hypothetical pipelines identified by their stringified typeVal. -func NewPipelines(typestrs ...string) map[string]*PipelineMetadata { - result := make(map[string]*PipelineMetadata, len(typestrs)) - for _, typestr := range typestrs { - result[typestr] = NewPipelineMetadata(typestr) - } - return result -} - -// SeedAggregator records a status event for each instanceID. -func SeedAggregator( - agg *status.Aggregator, - instanceIDs []*componentstatus.InstanceID, - statuses ...componentstatus.Status, -) { - for _, st := range statuses { - for _, id := range instanceIDs { - agg.RecordStatus(id, componentstatus.NewEvent(st)) - } - } -} - func ErrPriority(config *common.ComponentHealthConfig) status.ErrorPriority { if config != nil && config.IncludeRecoverable && !config.IncludePermanent { return status.PriorityRecoverable diff --git a/pkg/status/Makefile b/pkg/status/Makefile new file mode 100644 index 000000000000..ded7a36092dc --- /dev/null +++ b/pkg/status/Makefile @@ -0,0 +1 @@ +include ../../Makefile.Common diff --git a/pkg/status/README.md b/pkg/status/README.md new file mode 100644 index 000000000000..eb65edbe7516 --- /dev/null +++ b/pkg/status/README.md @@ -0,0 +1,23 @@ +# pkg/status + + +| Status | | +| ------------- |-----------| +| Stability | [development]: extension | +| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Apkg%2Fstatus%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Apkg%2Fstatus) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Apkg%2Fstatus%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Apkg%2Fstatus) | +| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@jpkrohling](https://www.github.com/jpkrohling), [@mwear](https://www.github.com/mwear) | + +[development]: https://github.com/open-telemetry/opentelemetry-collector#development + + +## Overview + +This module contains functionality for aggregating status information about components. Used by extensions that +implement the `componentstatus.Watcher` interface for collecting status information about the internal status of all +components inside the collector. + +### History + +`pkg/status` was originally developed for the `healthcheckv2extension`. It provided a generic way of aggregating +status information for components. Other extensions that need to implement the `componentstatus.Watcher` can now use +the same implementation `healthcheckv2extension` uses. diff --git a/extension/healthcheckv2extension/internal/status/aggregation.go b/pkg/status/aggregation.go similarity index 98% rename from extension/healthcheckv2extension/internal/status/aggregation.go rename to pkg/status/aggregation.go index 072b55565e7e..c1af5a4c0c7d 100644 --- a/extension/healthcheckv2extension/internal/status/aggregation.go +++ b/pkg/status/aggregation.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package status // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" +package status // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" import ( "time" diff --git a/extension/healthcheckv2extension/internal/status/aggregation_test.go b/pkg/status/aggregation_test.go similarity index 100% rename from extension/healthcheckv2extension/internal/status/aggregation_test.go rename to pkg/status/aggregation_test.go diff --git a/extension/healthcheckv2extension/internal/status/aggregator.go b/pkg/status/aggregator.go similarity index 99% rename from extension/healthcheckv2extension/internal/status/aggregator.go rename to pkg/status/aggregator.go index 7a80717e0682..13193876055d 100644 --- a/extension/healthcheckv2extension/internal/status/aggregator.go +++ b/pkg/status/aggregator.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package status // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" +package status // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" import ( "container/list" diff --git a/extension/healthcheckv2extension/internal/status/aggregator_test.go b/pkg/status/aggregator_test.go similarity index 98% rename from extension/healthcheckv2extension/internal/status/aggregator_test.go rename to pkg/status/aggregator_test.go index d099588c56b2..255c3c1f3dff 100644 --- a/extension/healthcheckv2extension/internal/status/aggregator_test.go +++ b/pkg/status/aggregator_test.go @@ -14,8 +14,8 @@ import ( "go.opentelemetry.io/collector/component/componentstatus" "go.opentelemetry.io/collector/pipeline" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/status" - "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckv2extension/internal/testhelpers" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status/testhelpers" ) func TestAggregateStatus(t *testing.T) { diff --git a/pkg/status/doc.go b/pkg/status/doc.go new file mode 100644 index 000000000000..0f73d96762c5 --- /dev/null +++ b/pkg/status/doc.go @@ -0,0 +1,6 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +//go:generate mdatagen metadata.yaml + +package status // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" diff --git a/pkg/status/generated_package_test.go b/pkg/status/generated_package_test.go new file mode 100644 index 000000000000..015146739dba --- /dev/null +++ b/pkg/status/generated_package_test.go @@ -0,0 +1,13 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package status + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +} diff --git a/pkg/status/go.mod b/pkg/status/go.mod new file mode 100644 index 000000000000..9239308b71bf --- /dev/null +++ b/pkg/status/go.mod @@ -0,0 +1,32 @@ +module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status + +go 1.22.0 + +require ( + github.com/stretchr/testify v1.9.0 + go.opentelemetry.io/collector/component v0.111.1-0.20241008154146-ea48c09c31ae + go.opentelemetry.io/collector/component/componentstatus v0.111.1-0.20241008154146-ea48c09c31ae + go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae + go.uber.org/goleak v1.3.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + go.opentelemetry.io/collector/config/configtelemetry v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae // indirect + go.opentelemetry.io/otel v1.30.0 // indirect + go.opentelemetry.io/otel/metric v1.30.0 // indirect + go.opentelemetry.io/otel/trace v1.30.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.17.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect + google.golang.org/grpc v1.67.1 // indirect + google.golang.org/protobuf v1.35.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/pkg/status/go.sum b/pkg/status/go.sum new file mode 100644 index 000000000000..86d58b5023a7 --- /dev/null +++ b/pkg/status/go.sum @@ -0,0 +1,90 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/collector/component v0.111.1-0.20241008154146-ea48c09c31ae h1:dXAMqXGJp1vWG7qwS/2sjIyJgmyOSfEOm6Gcmkzp1cQ= +go.opentelemetry.io/collector/component v0.111.1-0.20241008154146-ea48c09c31ae/go.mod h1:iWUfPxpVwZhkI4v3/Gh5wt4iKyJn4lriPFAug8iLXno= +go.opentelemetry.io/collector/component/componentstatus v0.111.1-0.20241008154146-ea48c09c31ae h1:BVTz/s8fmI5UA4Q6zAndl0Pds4RrkhxEXkx9TMelleM= +go.opentelemetry.io/collector/component/componentstatus v0.111.1-0.20241008154146-ea48c09c31ae/go.mod h1:fwY2NdXkOw07ObusogFZChVyyvqXqCJBlGaWwwDJAtI= +go.opentelemetry.io/collector/config/configtelemetry v0.111.1-0.20241008154146-ea48c09c31ae h1:NmNYRBSP+IUK9CsU1Q/1eS/tXmYTPMYxmGQsxEprq/s= +go.opentelemetry.io/collector/config/configtelemetry v0.111.1-0.20241008154146-ea48c09c31ae/go.mod h1:R0MBUxjSMVMIhljuDHWIygzzJWQyZHXXWIgQNxcFwhc= +go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae h1:fublc0EO06p79/OWw2jWVPSPNBMiBcB+0QpLes587DU= +go.opentelemetry.io/collector/internal/globalsignal v0.111.1-0.20241008154146-ea48c09c31ae/go.mod h1:GqMXodPWOxK5uqpX8MaMXC2389y2XJTa5nPwf8FYDK8= +go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae h1:PcwZe1RD8tC4SZExhf0f5HqK+ZuWGsowHaBBU4PiUv0= +go.opentelemetry.io/collector/pdata v1.17.1-0.20241008154146-ea48c09c31ae/go.mod h1:Ox1YVLe87cZDB/TL30i4SUz1cA5s6AM6SpFMfY61ICs= +go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae h1:/NNb1rBd/Y42FzIjpLjlRSb7bPANHyI3/3DnPg5p50U= +go.opentelemetry.io/collector/pipeline v0.111.1-0.20241008154146-ea48c09c31ae/go.mod h1:ZZMU3019geEU283rTW5M/LkcqLqHp/YI2Nl6/Vp68PQ= +go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts= +go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc= +go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w= +go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ= +go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc= +go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/status/metadata.yaml b/pkg/status/metadata.yaml new file mode 100644 index 000000000000..dea0fc8ce9ef --- /dev/null +++ b/pkg/status/metadata.yaml @@ -0,0 +1,8 @@ +type: status + +status: + class: pkg + stability: + development: [extension] + codeowners: + active: [jpkrohling, mwear] diff --git a/pkg/status/testhelpers/helpers.go b/pkg/status/testhelpers/helpers.go new file mode 100644 index 000000000000..cb5ef286734a --- /dev/null +++ b/pkg/status/testhelpers/helpers.go @@ -0,0 +1,59 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package testhelpers // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status/testhelpers" + +import ( + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componentstatus" + "go.opentelemetry.io/collector/pipeline" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status" +) + +// PipelineMetadata groups together component and instance IDs for a hypothetical pipeline used +// for testing purposes. +type PipelineMetadata struct { + PipelineID pipeline.ID + ReceiverID *componentstatus.InstanceID + ProcessorID *componentstatus.InstanceID + ExporterID *componentstatus.InstanceID +} + +// InstanceIDs returns a slice of instanceIDs for components within the hypothetical pipeline. +func (p *PipelineMetadata) InstanceIDs() []*componentstatus.InstanceID { + return []*componentstatus.InstanceID{p.ReceiverID, p.ProcessorID, p.ExporterID} +} + +// NewPipelineMetadata returns a metadata for a hypothetical pipeline. +func NewPipelineMetadata(typestr string) *PipelineMetadata { + pipelineID := pipeline.MustNewID(typestr) + return &PipelineMetadata{ + PipelineID: pipelineID, + ReceiverID: componentstatus.NewInstanceID(component.NewIDWithName(component.MustNewType(typestr), "in"), component.KindReceiver).WithPipelines(pipelineID), + ProcessorID: componentstatus.NewInstanceID(component.MustNewID("batch"), component.KindProcessor).WithPipelines(pipelineID), + ExporterID: componentstatus.NewInstanceID(component.NewIDWithName(component.MustNewType(typestr), "out"), component.KindExporter).WithPipelines(pipelineID), + } +} + +// NewPipelines returns a map of hypothetical pipelines identified by their stringified typeVal. +func NewPipelines(typestrs ...string) map[string]*PipelineMetadata { + result := make(map[string]*PipelineMetadata, len(typestrs)) + for _, typestr := range typestrs { + result[typestr] = NewPipelineMetadata(typestr) + } + return result +} + +// SeedAggregator records a status event for each instanceID. +func SeedAggregator( + agg *status.Aggregator, + instanceIDs []*componentstatus.InstanceID, + statuses ...componentstatus.Status, +) { + for _, st := range statuses { + for _, id := range instanceIDs { + agg.RecordStatus(id, componentstatus.NewEvent(st)) + } + } +} diff --git a/versions.yaml b/versions.yaml index e6fee73f2ea2..30cb52a4201e 100644 --- a/versions.yaml +++ b/versions.yaml @@ -149,6 +149,7 @@ module-sets: - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog + - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azure - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/azurelogs - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger