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

otel changes done for agent 08 release #23

Merged
merged 8 commits into from
Aug 23, 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
19 changes: 11 additions & 8 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/mezmoexporter v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opencensusexporter v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opensearchexporter v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/opsrampdebugexporter v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/otelarrowexporter v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter v0.106.1
Expand Down Expand Up @@ -108,6 +109,8 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricsgenerationprocessor v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstransformprocessor v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/processor/opsrampk8sattributesprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/opsrampk8sobjectsprocessor v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/processor/probabilisticsamplerprocessor v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/processor/redactionprocessor v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/processor/remotetapprocessor v0.106.1
Expand Down Expand Up @@ -238,7 +241,7 @@ require (
go.opentelemetry.io/collector/receiver v0.106.1
go.opentelemetry.io/collector/receiver/nopreceiver v0.106.1
go.opentelemetry.io/collector/receiver/otlpreceiver v0.106.1
golang.org/x/sys v0.22.0
golang.org/x/sys v0.24.0
)

require (
Expand Down Expand Up @@ -693,7 +696,7 @@ require (
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rabbitmq/amqp091-go v1.10.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/redis/go-redis/v9 v9.6.0 // indirect
github.com/redis/go-redis/v9 v9.6.1 // indirect
github.com/relvacode/iso8601 v1.4.0 // indirect
github.com/rs/cors v1.11.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
Expand Down Expand Up @@ -806,22 +809,22 @@ require (
go.uber.org/fx v1.18.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
google.golang.org/api v0.189.0 // indirect
google.golang.org/genproto v0.0.0-20240722135656-d784300faade // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240808171019-573a1156607a // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
32 changes: 16 additions & 16 deletions cmd/otelcontribcol/go.sum

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

24 changes: 24 additions & 0 deletions processor/k8sattributesprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/lru"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/redis"
)

var disallowFieldExtractConfigRegex = featuregate.GlobalRegistry().MustRegister(
Expand Down Expand Up @@ -49,6 +51,8 @@ type Config struct {

//Opsramp Metadata Addons Section
MetadataAddOn []AddOnMetadata `mapstructure:"metadata_addon"`

RedisConfig redis.OpsrampRedisConfig `mapstructure:"redis_config"`
}

func (cfg *Config) Validate() error {
Expand Down Expand Up @@ -130,6 +134,26 @@ func (cfg *Config) Validate() error {
}
}

if cfg.RedisConfig.RedisHost == "" || cfg.RedisConfig.RedisPort == "" || cfg.RedisConfig.RedisPass == "" {
return fmt.Errorf("redis host, redis port and redis pass is mandatory")
}

if cfg.RedisConfig.ClusterName == "" || cfg.RedisConfig.ClusterUid == "" {
return fmt.Errorf("cluster name and cluster uid is mandatory")
}

if cfg.RedisConfig.NodeName == "" {
return fmt.Errorf("node name is mandatory")
}

if cfg.RedisConfig.LruExpirationTime == 0 {
cfg.RedisConfig.LruExpirationTime = lru.DEFAULT_CACHE_EXPIRATION_INTERVAL
}

if cfg.RedisConfig.LruCacheSize == 0 {
cfg.RedisConfig.LruCacheSize = lru.DEFAULT_CACHE_SIZE
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions processor/k8sattributesprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func createProcessorOpts(cfg component.Config) []option {
//Opsramp Metadata Addons
opts = append(opts, withAddOnFields(oCfg.MetadataAddOn...))

opts = append(opts, withRedisConfigFields(oCfg.RedisConfig))

opts = append(opts, withExcludes(oCfg.Exclude))

return opts
Expand Down
3 changes: 3 additions & 0 deletions processor/k8sattributesprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ go 1.21.0
require (
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.106.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest v0.106.1
github.com/redis/go-redis/v9 v9.6.1
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/client v0.106.1
go.opentelemetry.io/collector/component v0.106.1
Expand Down Expand Up @@ -38,6 +40,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v26.1.4+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions processor/k8sattributesprocessor/go.sum

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

53 changes: 53 additions & 0 deletions processor/k8sattributesprocessor/internal/lru/lru.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package lru

import (
"fmt"
"sync"
"time"

cache "github.com/hashicorp/golang-lru/v2/expirable"
)

type Cache struct {
lrucache *cache.LRU[string, string]
}

const (
DEFAULT_CACHE_SIZE = 256
DEFAULT_CACHE_EXPIRATION_INTERVAL = 10 * time.Minute
)

var (
once sync.Once
instance *Cache
)

func New(size int, expirationInterval time.Duration) *Cache {
return &Cache{lrucache: cache.NewLRU[string, string](size, nil, expirationInterval)}
}

func GetInstance(size int, expirationInterval time.Duration) *Cache {
once.Do(func() {
instance = New(size, expirationInterval)
})
return instance
}

func (c *Cache) Get(key string) (string, bool) {
return c.lrucache.Get(key)
}

func (c *Cache) Add(key string, value string) {
c.lrucache.Add(key, value)
}

func (c *Cache) AddEvicted(key string, value string) (evicted bool) {
return c.lrucache.Add(key, value)
}

func (c *Cache) PrintKeys() {
fmt.Println(c.lrucache.Keys())
}
func (c *Cache) PrintValues() {
fmt.Println(c.lrucache.Values())
}
25 changes: 25 additions & 0 deletions processor/k8sattributesprocessor/internal/lru/lru_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package lru

import (
"testing"
)

func TestLRU(t *testing.T) {
cache := New(2, 0)

// Test cases
cache.Add("key1", "value1")
cache.Add("key2", "value2")

value, ok := cache.Get("key1")
if !ok || value != "value1" {
t.Errorf("Expected value1, got %v", value)
}

cache.Add("key3", "value3")

_, ok = cache.Get("key4")
if ok {
t.Errorf("Expected key1 to be evicted")
}
}
Loading
Loading