Skip to content

Commit

Permalink
Refactor extension/healthcheckv2extension/internal/status to pkg/status
Browse files Browse the repository at this point in the history
  • Loading branch information
blakerouse committed Oct 7, 2024
1 parent 5edf2fe commit b102db7
Show file tree
Hide file tree
Showing 22 changed files with 222 additions and 74 deletions.
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
2 changes: 1 addition & 1 deletion extension/healthcheckv2extension/internal/http/handlers.go
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
7 changes: 4 additions & 3 deletions extension/healthcheckv2extension/internal/http/server_test.go
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
53 changes: 1 addition & 52 deletions extension/healthcheckv2extension/internal/testhelpers/helpers.go
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

## 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
components inside the collector.

### History

`status` was originally developed for the `healthcheckv2extension`. Other extensions that need to collector status
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
File renamed without changes.
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

0 comments on commit b102db7

Please sign in to comment.