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

[extension/healthcheckv2extension] Refactor internal/status to pkg/status #35648

Merged
merged 18 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions .chloggen/pkg-status.yaml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ body:
- pkg/sampling
- pkg/stanza
- pkg/stanza/fileconsumer
- pkg/status
- pkg/translator/azure
- pkg/translator/azurelogs
- pkg/translator/jaeger
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ body:
- pkg/sampling
- pkg/stanza
- pkg/stanza/fileconsumer
- pkg/status
- pkg/translator/azure
- pkg/translator/azurelogs
- pkg/translator/jaeger
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ body:
- pkg/sampling
- pkg/stanza
- pkg/stanza/fileconsumer
- pkg/status
- pkg/translator/azure
- pkg/translator/azurelogs
- pkg/translator/jaeger
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ body:
- pkg/sampling
- pkg/stanza
- pkg/stanza/fileconsumer
- pkg/status
- pkg/translator/azure
- pkg/translator/azurelogs
- pkg/translator/jaeger
Expand Down
1 change: 1 addition & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion extension/healthcheckv2extension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions extension/healthcheckv2extension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion extension/healthcheckv2extension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion extension/healthcheckv2extension/internal/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 5 additions & 4 deletions extension/healthcheckv2extension/internal/grpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())) })
Expand Down Expand Up @@ -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())) })
Expand Down
2 changes: 1 addition & 1 deletion extension/healthcheckv2extension/internal/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion extension/healthcheckv2extension/internal/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/status/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
23 changes: 23 additions & 0 deletions pkg/status/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# pkg/status

evan-bradley marked this conversation as resolved.
Show resolved Hide resolved
<!-- status autogenerated section -->
| 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
<!-- end autogenerated section -->

## 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.
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/status/doc.go
Original file line number Diff line number Diff line change
@@ -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"
13 changes: 13 additions & 0 deletions pkg/status/generated_package_test.go

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

Loading