Skip to content

Commit

Permalink
name resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
edeNFed committed Feb 22, 2023
1 parent 5020d2b commit 0e191fc
Show file tree
Hide file tree
Showing 16 changed files with 1,289 additions and 3 deletions.
3 changes: 0 additions & 3 deletions cmd/otelcontribcol/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ RUN mkdir -p /tmp

FROM scratch

ARG USER_UID=10001
USER ${USER_UID}

COPY --from=prep /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY otelcontribcol /
EXPOSE 4317 55680 55679
Expand Down
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ processors:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/spanprocessor v0.71.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/tailsamplingprocessor v0.71.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor v0.71.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor v0.71.0

receivers:
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.71.0
Expand Down Expand Up @@ -331,6 +332,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/iisreceiver => ../../receiver/iisreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/bigipreceiver => ../../receiver/bigipreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor => ../../processor/probabilisticsamplerprocessor
- github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor => ../../processor/odigosresourcenameprocessor
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter => ../../exporter/fileexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry => ../../pkg/resourcetotelemetry
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opencensusexporter => ../../exporter/opencensusexporter
Expand Down
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/components.go

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

3 changes: 3 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricsgenerationprocessor v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstransformprocessor v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/redactionprocessor v0.71.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor v0.71.0
Expand Down Expand Up @@ -937,6 +938,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/bigip

replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor => ../../processor/probabilisticsamplerprocessor

replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor => ../../processor/odigosresourcenameprocessor

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter => ../../exporter/fileexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry => ../../pkg/resourcetotelemetry
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/tran

replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/schemaprocessor => ./processor/schemaprocessor

replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/odigosresourcenameprocessor => ./processor/odigosresourcenameprocessor

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/activedirectorydsreceiver => ./receiver/activedirectorydsreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/aerospikereceiver => ./receiver/aerospikereceiver
Expand Down
1 change: 1 addition & 0 deletions processor/odigosresourcenameprocessor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
3 changes: 3 additions & 0 deletions processor/odigosresourcenameprocessor/README.md
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.
13 changes: 13 additions & 0 deletions processor/odigosresourcenameprocessor/config.go
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)
1 change: 1 addition & 0 deletions processor/odigosresourcenameprocessor/doc.go
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"
138 changes: 138 additions & 0 deletions processor/odigosresourcenameprocessor/factory.go
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()
}
75 changes: 75 additions & 0 deletions processor/odigosresourcenameprocessor/go.mod
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
Loading

0 comments on commit 0e191fc

Please sign in to comment.