Skip to content

Commit 204d29b

Browse files
authored
feat: add labels from nri-winservices config as tags on UI. (#1989)
* feat: add labels from nri-winservices config as tags on UI.
1 parent ad1d3a5 commit 204d29b

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

pkg/entity/register/worker.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,23 @@ func (w *worker) Run(ctx context.Context) {
106106
}
107107
}
108108
}
109+
func updateEntityMetadata(entity *entity.Fields, labels map[string]string) {
110+
if len(labels) > 0 {
111+
for key, value := range labels {
112+
entity.Metadata[key] = value
113+
}
114+
}
115+
}
109116

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

113120
var entities []entity.Fields
114121
for _, r := range batch {
115-
entities = append(entities, r.Data.Entity)
122+
entity := r.Data.Entity
123+
// Add labels to Metadata
124+
updateEntityMetadata(&entity, r.Definition.Labels)
125+
entities = append(entities, entity)
116126
}
117127

118128
responses := w.registerEntitiesWithRetry(ctx, entities)

pkg/entity/register/worker_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,49 @@ func TestWorker_send_Logging_VerboseDisabled(t *testing.T) {
566566

567567
assert.Empty(t, hook.AllEntries())
568568
}
569+
func TestUpdateEntityMetadata(t *testing.T) {
570+
t.Parallel()
571+
expected := &entity.Fields{
572+
Name: "WIN_SERVICE:testWindows:newrelic-infra",
573+
Type: "WIN_SERVICE",
574+
IDAttributes: nil,
575+
DisplayName: "New Relic Infrastructure Agent",
576+
Metadata: map[string]interface{}{
577+
"environment": "dev",
578+
"backup": "true",
579+
},
580+
}
581+
labels := map[string]string{
582+
"environment": "dev",
583+
"backup": "true",
584+
}
585+
entity := &entity.Fields{
586+
Name: "WIN_SERVICE:testWindows:newrelic-infra",
587+
Type: "WIN_SERVICE",
588+
IDAttributes: nil,
589+
DisplayName: "New Relic Infrastructure Agent",
590+
Metadata: map[string]interface{}{},
591+
}
592+
updateEntityMetadata(entity, labels)
593+
assert.Equal(t, expected, entity)
594+
}
595+
func TestUpdateEntityMetadata_NilLabels(t *testing.T) {
596+
t.Parallel()
597+
expected := &entity.Fields{
598+
Name: "WIN_SERVICE:testWindows:newrelic-infra",
599+
Type: "WIN_SERVICE",
600+
IDAttributes: nil,
601+
DisplayName: "New Relic Infrastructure Agent",
602+
Metadata: map[string]interface{}{},
603+
}
604+
var labels map[string]string
605+
entity := &entity.Fields{
606+
Name: "WIN_SERVICE:testWindows:newrelic-infra",
607+
Type: "WIN_SERVICE",
608+
IDAttributes: nil,
609+
DisplayName: "New Relic Infrastructure Agent",
610+
Metadata: map[string]interface{}{},
611+
}
612+
updateEntityMetadata(entity, labels)
613+
assert.Equal(t, expected, entity)
614+
}

0 commit comments

Comments
 (0)