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 3 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
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
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.0
go.opentelemetry.io/collector/component/componentstatus v0.111.0
Expand All @@ -14,7 +15,6 @@ require (
go.opentelemetry.io/collector/confmap v1.17.0
go.opentelemetry.io/collector/extension v0.111.0
go.opentelemetry.io/collector/extension/extensioncapabilities v0.111.0
go.opentelemetry.io/collector/pipeline v0.111.0
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.0 // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.0 // indirect
go.opentelemetry.io/collector/pdata v1.17.0 // indirect
go.opentelemetry.io/collector/pipeline v0.111.0 // 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
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
12 changes: 12 additions & 0 deletions pkg/status/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# pkg/status

evan-bradley marked this conversation as resolved.
Show resolved Hide resolved
## Overview

This module contains functionality for aggregating status information about components. Used by extensions that
implement the `extension.StatusWatcher` interface for collecting status information about the internal status of all
blakerouse marked this conversation as resolved.
Show resolved Hide resolved
components inside the collector.

### History

`status` was originally developed for the `healthcheckv2extension`. Other extensions that need to collector status
evan-bradley marked this conversation as resolved.
Show resolved Hide resolved
information needed to use this same implementation to aggregate status information.
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
32 changes: 32 additions & 0 deletions pkg/status/go.mod
Original file line number Diff line number Diff line change
@@ -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.0
go.opentelemetry.io/collector/component/componentstatus v0.111.0
go.opentelemetry.io/collector/pipeline v0.111.0
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.0 // indirect
go.opentelemetry.io/collector/internal/globalsignal v0.111.0 // indirect
go.opentelemetry.io/collector/pdata v1.17.0 // 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.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading