Skip to content

Commit

Permalink
feat: add labels from nri-winservices config as tags on UI. (#1989)
Browse files Browse the repository at this point in the history
* feat: add labels from nri-winservices config  as tags on UI.
  • Loading branch information
abhishuraina authored Jan 15, 2025
1 parent ad1d3a5 commit 204d29b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/entity/register/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,23 @@ func (w *worker) Run(ctx context.Context) {
}
}
}
func updateEntityMetadata(entity *entity.Fields, labels map[string]string) {
if len(labels) > 0 {
for key, value := range labels {
entity.Metadata[key] = value
}
}
}

func (w *worker) send(ctx context.Context, batch map[entity.Key]fwrequest.EntityFwRequest, batchSizeBytes *int) {
defer w.resetBatch(batch, batchSizeBytes)

var entities []entity.Fields
for _, r := range batch {
entities = append(entities, r.Data.Entity)
entity := r.Data.Entity
// Add labels to Metadata
updateEntityMetadata(&entity, r.Definition.Labels)
entities = append(entities, entity)
}

responses := w.registerEntitiesWithRetry(ctx, entities)
Expand Down
46 changes: 46 additions & 0 deletions pkg/entity/register/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,49 @@ func TestWorker_send_Logging_VerboseDisabled(t *testing.T) {

assert.Empty(t, hook.AllEntries())
}
func TestUpdateEntityMetadata(t *testing.T) {
t.Parallel()
expected := &entity.Fields{
Name: "WIN_SERVICE:testWindows:newrelic-infra",
Type: "WIN_SERVICE",
IDAttributes: nil,
DisplayName: "New Relic Infrastructure Agent",
Metadata: map[string]interface{}{
"environment": "dev",
"backup": "true",
},
}
labels := map[string]string{
"environment": "dev",
"backup": "true",
}
entity := &entity.Fields{
Name: "WIN_SERVICE:testWindows:newrelic-infra",
Type: "WIN_SERVICE",
IDAttributes: nil,
DisplayName: "New Relic Infrastructure Agent",
Metadata: map[string]interface{}{},
}
updateEntityMetadata(entity, labels)
assert.Equal(t, expected, entity)
}
func TestUpdateEntityMetadata_NilLabels(t *testing.T) {
t.Parallel()
expected := &entity.Fields{
Name: "WIN_SERVICE:testWindows:newrelic-infra",
Type: "WIN_SERVICE",
IDAttributes: nil,
DisplayName: "New Relic Infrastructure Agent",
Metadata: map[string]interface{}{},
}
var labels map[string]string
entity := &entity.Fields{
Name: "WIN_SERVICE:testWindows:newrelic-infra",
Type: "WIN_SERVICE",
IDAttributes: nil,
DisplayName: "New Relic Infrastructure Agent",
Metadata: map[string]interface{}{},
}
updateEntityMetadata(entity, labels)
assert.Equal(t, expected, entity)
}

0 comments on commit 204d29b

Please sign in to comment.