From 42ce5345f6ef7500bffbc2e146d8477ffdb9f42a Mon Sep 17 00:00:00 2001 From: Julien Pinsonneau <91894519+jpinsonneau@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:31:59 +0200 Subject: [PATCH] NETOBSERV-1522 & NETOBSERV-1750 FLP otel fixes (#684) * fix open telemetry attributes * skip callback if nil --- .../encode/opentelemetry/opentelemetry.go | 40 +++++++++++++++---- pkg/pipeline/utils/timed_cache.go | 4 +- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/pkg/pipeline/encode/opentelemetry/opentelemetry.go b/pkg/pipeline/encode/opentelemetry/opentelemetry.go index e7372a19a..246a9d767 100644 --- a/pkg/pipeline/encode/opentelemetry/opentelemetry.go +++ b/pkg/pipeline/encode/opentelemetry/opentelemetry.go @@ -275,19 +275,45 @@ func obtainAttributesFromEntry(entry config.GenericMap) *[]attribute.KeyValue { var att = make([]attribute.KeyValue, len(entry)) index := 0 for k, v := range entry { - switch v.(type) { + switch v := v.(type) { + case []string: + att[index] = attribute.StringSlice(k, v) case string: - valString := v - att[index] = attribute.String(k, valString.(string)) - case int, int32, int64, int16, uint, uint8, uint16, uint32, uint64: + att[index] = attribute.String(k, v) + case []int: + att[index] = attribute.IntSlice(k, v) + case []int32: + valInt64Slice := []int64{} + for _, valInt32 := range v { + valInt64, _ := utils.ConvertToInt64(valInt32) + valInt64Slice = append(valInt64Slice, valInt64) + } + att[index] = attribute.Int64Slice(k, valInt64Slice) + case []int64: + att[index] = attribute.Int64Slice(k, v) + case int: + att[index] = attribute.Int(k, v) + case int32, int64, int16, uint, uint8, uint16, uint32, uint64: valInt, _ := utils.ConvertToInt64(v) att[index] = attribute.Int64(k, valInt) - case float32, float64: + case []float32: + valFloat64Slice := []float64{} + for _, valFloat32 := range v { + valFloat64, _ := utils.ConvertToFloat64(valFloat32) + valFloat64Slice = append(valFloat64Slice, valFloat64) + } + att[index] = attribute.Float64Slice(k, valFloat64Slice) + case []float64: + att[index] = attribute.Float64Slice(k, v) + case float32: valFloat, _ := utils.ConvertToFloat64(v) att[index] = attribute.Float64(k, valFloat) + case float64: + att[index] = attribute.Float64(k, v) + case []bool: + att[index] = attribute.BoolSlice(k, v) case bool: - valBool := v - att[index] = attribute.Bool(k, valBool.(bool)) + att[index] = attribute.Bool(k, v) case nil: // skip this field continue diff --git a/pkg/pipeline/utils/timed_cache.go b/pkg/pipeline/utils/timed_cache.go index df945f4b6..bac404664 100644 --- a/pkg/pipeline/utils/timed_cache.go +++ b/pkg/pipeline/utils/timed_cache.go @@ -141,7 +141,9 @@ func (tc *TimedCache) CleanupExpiredEntries(expiry time.Duration, callback Cache return } deleted++ - callback(pCacheInfo.SourceEntry) + if callback != nil { + callback(pCacheInfo.SourceEntry) + } delete(tc.cacheMap, pCacheInfo.key) tc.cacheList.Remove(listEntry) if tc.cacheLenMetric != nil {