Skip to content

Commit

Permalink
Merge pull request #27 from opsramp/release/v0.104.x
Browse files Browse the repository at this point in the history
Release/v0.104.x
  • Loading branch information
opsrampdeveloper authored Sep 16, 2024
2 parents 8676a76 + da0ba19 commit b40cd9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 13 additions & 2 deletions processor/k8sattributesprocessor/internal/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redis

import (
"context"
"encoding/json"
"time"

lru "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/lru"
Expand Down Expand Up @@ -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
Expand All @@ -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 uint64 `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
}
}

Expand Down
8 changes: 4 additions & 4 deletions processor/k8sattributesprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,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
}
Expand All @@ -285,7 +285,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
}
Expand All @@ -294,7 +294,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
}
Expand All @@ -303,7 +303,7 @@ func (op *kubernetesprocessor) GetResourceUuidUsingClusterMoid(ctx context.Conte

nodeMoidKey := moid.NewMoid(op.redisConfig.ClusterName).WithClusterUuid(op.redisConfig.ClusterUid).ClusterMoid()

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
}
Expand Down

0 comments on commit b40cd9e

Please sign in to comment.