Skip to content

Commit

Permalink
fix: Cache node labels being overwritten
Browse files Browse the repository at this point in the history
The previous code was using the same instance of `LabelSet` for creating
labels for all cache nodes, this would overwrite all cache nodes to use
the same labelset as the last one.

This solution simply clones one instance of the `CacheCluster` label set
to each of `CacheClusterNode`.
  • Loading branch information
mateusduboli committed Dec 6, 2022
1 parent 95eb011 commit cad9422
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,15 @@ func (d *ElasticacheDiscovery) refresh(ctx context.Context) ([]*targetgroup.Grou
}

for _, cn := range cc.CacheNodes {
labels[model.LabelName(ecLabelCacheNodeID)] = model.LabelValue(*cn.CacheNodeId)
labels[model.LabelName(ecLabelCacheNodeStatus)] = model.LabelValue(*cn.CacheNodeStatus)
labels[model.LabelName(ecLabelCustomerAZ)] = model.LabelValue(*cn.CustomerAvailabilityZone)
labels[model.LabelName(ecLabelEndpointAddress)] = model.LabelValue(*cn.Endpoint.Address)
labels[model.LabelName(ecLabelEndpointPort)] = model.LabelValue(fmt.Sprintf("%d", cn.Endpoint.Port))
nodeLabels := labels.Clone()
nodeLabels[model.LabelName(ecLabelCacheNodeID)] = model.LabelValue(*cn.CacheNodeId)
nodeLabels[model.LabelName(ecLabelCacheNodeStatus)] = model.LabelValue(*cn.CacheNodeStatus)
nodeLabels[model.LabelName(ecLabelCustomerAZ)] = model.LabelValue(*cn.CustomerAvailabilityZone)
nodeLabels[model.LabelName(ecLabelEndpointAddress)] = model.LabelValue(*cn.Endpoint.Address)
nodeLabels[model.LabelName(ecLabelEndpointPort)] = model.LabelValue(fmt.Sprintf("%d", cn.Endpoint.Port))

// Placeholder address
labels[model.AddressLabel] = model.LabelValue("undefined")
nodeLabels[model.AddressLabel] = model.LabelValue("undefined")

source := fmt.Sprintf("%s/%s", *cc.ARN, *cn.CacheNodeId)
level.Debug(d.logger).Log("msg", "target added", "source", source)
Expand All @@ -230,7 +231,7 @@ func (d *ElasticacheDiscovery) refresh(ctx context.Context) ([]*targetgroup.Grou

tgs = append(tgs, &targetgroup.Group{
Source: source,
Labels: labels,
Labels: nodeLabels,
Targets: []model.LabelSet{
{model.AddressLabel: model.LabelValue("undefined")},
},
Expand Down

0 comments on commit cad9422

Please sign in to comment.