Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add labels from nri-winservices config as tags on UI. #1989

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
abhishuraina marked this conversation as resolved.
Show resolved Hide resolved
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)
}
Loading