-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,289 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Odigos Resource Name Processor | ||
|
||
This processor replaces the device uuid with the device name. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package odigosresourcenameprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor" | ||
|
||
import ( | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" | ||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
// Config defines configuration for Resource processor. | ||
type Config struct { | ||
k8sconfig.APIConfig `mapstructure:",squash"` | ||
} | ||
|
||
var _ component.Config = (*Config)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package odigosresourcenameprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package odigosresourcenameprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor" | ||
|
||
import ( | ||
"context" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/processor" | ||
"go.opentelemetry.io/collector/processor/processorhelper" | ||
"go.uber.org/zap" | ||
"sync" | ||
) | ||
|
||
const ( | ||
// The value of "type" key in configuration. | ||
typeStr = "odigosresourcename" | ||
// The stability level of the processor. | ||
stability = component.StabilityLevelBeta | ||
) | ||
|
||
var processorCapabilities = consumer.Capabilities{MutatesData: true} | ||
var nameResolver *NameResolver | ||
|
||
// NewFactory returns a new factory for the Resource processor. | ||
func NewFactory() processor.Factory { | ||
return processor.NewFactory( | ||
typeStr, | ||
createDefaultConfig, | ||
processor.WithTraces(createTracesProcessor, stability), | ||
processor.WithMetrics(createMetricsProcessor, stability), | ||
processor.WithLogs(createLogsProcessor, stability)) | ||
} | ||
|
||
func createDefaultConfig() component.Config { | ||
return &Config{ | ||
APIConfig: k8sconfig.APIConfig{AuthType: k8sconfig.AuthTypeServiceAccount}, | ||
} | ||
} | ||
|
||
func createTracesProcessor( | ||
ctx context.Context, | ||
set processor.CreateSettings, | ||
cfg component.Config, | ||
nextConsumer consumer.Traces) (processor.Traces, error) { | ||
|
||
if err := initNameResolver(cfg, set.Logger); err != nil { | ||
return nil, err | ||
} | ||
|
||
proc := &resourceProcessor{logger: set.Logger, nameResolver: nameResolver} | ||
return processorhelper.NewTracesProcessor( | ||
ctx, | ||
set, | ||
cfg, | ||
nextConsumer, | ||
proc.processTraces, | ||
processorhelper.WithCapabilities(processorCapabilities)) | ||
} | ||
|
||
func createMetricsProcessor( | ||
ctx context.Context, | ||
set processor.CreateSettings, | ||
cfg component.Config, | ||
nextConsumer consumer.Metrics) (processor.Metrics, error) { | ||
|
||
if err := initNameResolver(cfg, set.Logger); err != nil { | ||
return nil, err | ||
} | ||
|
||
proc := &resourceProcessor{logger: set.Logger, nameResolver: nameResolver} | ||
return processorhelper.NewMetricsProcessor( | ||
ctx, | ||
set, | ||
cfg, | ||
nextConsumer, | ||
proc.processMetrics, | ||
processorhelper.WithCapabilities(processorCapabilities)) | ||
} | ||
|
||
func createLogsProcessor( | ||
ctx context.Context, | ||
set processor.CreateSettings, | ||
cfg component.Config, | ||
nextConsumer consumer.Logs) (processor.Logs, error) { | ||
|
||
if err := initNameResolver(cfg, set.Logger); err != nil { | ||
return nil, err | ||
} | ||
|
||
proc := &resourceProcessor{logger: set.Logger, nameResolver: nameResolver} | ||
return processorhelper.NewLogsProcessor( | ||
ctx, | ||
set, | ||
cfg, | ||
nextConsumer, | ||
proc.processLogs, | ||
processorhelper.WithCapabilities(processorCapabilities)) | ||
} | ||
|
||
func initNameResolver(cfg component.Config, logger *zap.Logger) error { | ||
if nameResolver != nil { | ||
return nil | ||
} | ||
|
||
pCfg := cfg.(*Config) | ||
kubeClient, err := k8sconfig.MakeClient(pCfg.APIConfig) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
kubelet, err := NewKubeletClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
nameResolver = &NameResolver{ | ||
kc: kubeClient, | ||
logger: logger, | ||
devicesToPods: map[string]string{}, | ||
mu: sync.RWMutex{}, | ||
kubelet: kubelet, | ||
} | ||
return nameResolver.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
module github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.71.0 | ||
go.opentelemetry.io/collector v0.71.0 | ||
go.opentelemetry.io/collector/component v0.71.0 | ||
go.opentelemetry.io/collector/consumer v0.71.0 | ||
go.opentelemetry.io/collector/pdata v1.0.0-rc5 | ||
go.opentelemetry.io/otel v1.13.0 | ||
go.uber.org/zap v1.24.0 | ||
google.golang.org/grpc v1.52.3 | ||
k8s.io/api v0.26.1 | ||
k8s.io/apimachinery v0.26.1 | ||
k8s.io/client-go v0.26.1 | ||
k8s.io/kubelet v0.26.1 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.20.0 // indirect | ||
github.com/go-openapi/swag v0.19.14 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/gnostic v0.5.7-v3refs // indirect | ||
github.com/google/go-cmp v0.5.9 // indirect | ||
github.com/google/gofuzz v1.2.0 // indirect | ||
github.com/imdario/mergo v0.3.11 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/knadh/koanf v1.5.0 // indirect | ||
github.com/kr/pretty v0.3.0 // indirect | ||
github.com/mailru/easyjson v0.7.6 // indirect | ||
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/openshift/api v0.0.0-20210521075222-e273a339932a // indirect | ||
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
go.opencensus.io v0.24.0 // indirect | ||
go.opentelemetry.io/collector/confmap v0.71.0 // indirect | ||
go.opentelemetry.io/collector/featuregate v0.71.0 // indirect | ||
go.opentelemetry.io/otel/metric v0.36.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.13.0 // indirect | ||
go.uber.org/atomic v1.10.0 // indirect | ||
go.uber.org/multierr v1.9.0 // indirect | ||
golang.org/x/net v0.5.0 // indirect | ||
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect | ||
golang.org/x/sys v0.4.0 // indirect | ||
golang.org/x/term v0.4.0 // indirect | ||
golang.org/x/text v0.6.0 // indirect | ||
golang.org/x/time v0.3.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/klog/v2 v2.80.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect | ||
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect | ||
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | ||
sigs.k8s.io/yaml v1.3.0 // indirect | ||
) | ||
|
||
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig => ./../../internal/k8sconfig |
Oops, something went wrong.