From 467f38d837aef364aa5c6c3ff0c44f55a4620069 Mon Sep 17 00:00:00 2001 From: Durgababu Neelam Date: Mon, 16 Sep 2024 12:45:49 +0530 Subject: [PATCH 1/2] redis getuuidvalue function changes to handle redis key-value of structure type --- .../internal/redis/client.go | 15 +++++++++++++-- processor/k8sattributesprocessor/processor.go | 8 ++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/processor/k8sattributesprocessor/internal/redis/client.go b/processor/k8sattributesprocessor/internal/redis/client.go index 041b66abcdc4..5318c38339c5 100644 --- a/processor/k8sattributesprocessor/internal/redis/client.go +++ b/processor/k8sattributesprocessor/internal/redis/client.go @@ -2,6 +2,7 @@ package redis import ( "context" + "encoding/json" "time" lru "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/lru" @@ -95,7 +96,7 @@ func (c *Client) TestConnection(ctx context.Context) error { return err } -func (c *Client) GetValueInString(ctx context.Context, key string) string { +func (c *Client) GetUuidValueInString(ctx context.Context, key string) string { logger := c.logger // Try to init the cache if it is firt time @@ -113,7 +114,17 @@ func (c *Client) GetValueInString(ctx context.Context, key string) string { logger.Error("Failed to fetch the key from redis ", zap.Error(err)) } else { logger.Debug("Got value from redis ", zap.Any("key", key), zap.Any("value", value)) - value = val + type RedisData struct { + ResourceUuid string `json:"resourceUuid,omitempty"` + ResourceHash string `json:"resourceHash,omitempty"` + } + var redisData RedisData + err = json.Unmarshal([]byte(val), &redisData) + if err != nil { + logger.Error("Could not unmarshal data:", zap.Error(err)) + return "" + } + value = redisData.ResourceUuid } } diff --git a/processor/k8sattributesprocessor/processor.go b/processor/k8sattributesprocessor/processor.go index c292a50bafe6..f90d5b75e6f6 100644 --- a/processor/k8sattributesprocessor/processor.go +++ b/processor/k8sattributesprocessor/processor.go @@ -260,7 +260,7 @@ func (op *kubernetesprocessor) GetResourceUuidUsingPodMoid(ctx context.Context, podMoidKey := podMoid.PodMoid() - resourceUuid = op.redisClient.GetValueInString(ctx, podMoidKey) + resourceUuid = op.redisClient.GetUuidValueInString(ctx, podMoidKey) op.logger.Debug("redis KV ", zap.Any("key", podMoidKey), zap.Any("value", resourceUuid)) return } @@ -274,7 +274,7 @@ func (op *kubernetesprocessor) GetResourceUuidUsingResourceNodeMoid(ctx context. nodeMoidKey := moid.NewMoid(op.redisConfig.ClusterName).WithNodeName(nodename.Str()).NodeMoid() - resourceUuid = op.redisClient.GetValueInString(ctx, nodeMoidKey) + resourceUuid = op.redisClient.GetUuidValueInString(ctx, nodeMoidKey) op.logger.Debug("redis KV ", zap.Any("key", nodeMoidKey), zap.Any("value", resourceUuid)) return } @@ -283,7 +283,7 @@ func (op *kubernetesprocessor) GetResourceUuidUsingCurrentNodeMoid(ctx context.C nodeMoidKey := moid.NewMoid(op.redisConfig.ClusterName).WithNodeName(op.redisConfig.NodeName).NodeMoid() - resourceUuid = op.redisClient.GetValueInString(ctx, nodeMoidKey) + resourceUuid = op.redisClient.GetUuidValueInString(ctx, nodeMoidKey) op.logger.Debug("redis KV ", zap.Any("key", nodeMoidKey), zap.Any("value", resourceUuid)) return } @@ -292,7 +292,7 @@ func (op *kubernetesprocessor) GetResourceUuidUsingClusterMoid(ctx context.Conte nodeMoidKey := moid.NewMoid(op.redisConfig.ClusterName).WithNodeName(op.redisConfig.NodeName).NodeMoid() - resourceUuid = op.redisClient.GetValueInString(ctx, nodeMoidKey) + resourceUuid = op.redisClient.GetUuidValueInString(ctx, nodeMoidKey) op.logger.Debug("redis KV ", zap.Any("key", nodeMoidKey), zap.Any("value", resourceUuid)) return } From da0ba190bf1a11f24728018ba527dd1046df7ac3 Mon Sep 17 00:00:00 2001 From: Durgababu Neelam Date: Mon, 16 Sep 2024 12:48:51 +0530 Subject: [PATCH 2/2] redis getuuidvalue function changes to handle redis key-value of structure type --- processor/k8sattributesprocessor/internal/redis/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/k8sattributesprocessor/internal/redis/client.go b/processor/k8sattributesprocessor/internal/redis/client.go index 5318c38339c5..385fe272a20d 100644 --- a/processor/k8sattributesprocessor/internal/redis/client.go +++ b/processor/k8sattributesprocessor/internal/redis/client.go @@ -116,7 +116,7 @@ func (c *Client) GetUuidValueInString(ctx context.Context, key string) string { logger.Debug("Got value from redis ", zap.Any("key", key), zap.Any("value", value)) type RedisData struct { ResourceUuid string `json:"resourceUuid,omitempty"` - ResourceHash string `json:"resourceHash,omitempty"` + ResourceHash uint64 `json:"resourceHash,omitempty"` } var redisData RedisData err = json.Unmarshal([]byte(val), &redisData)