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: accept duplicated service definitions #94

Merged
merged 1 commit into from
Oct 16, 2020
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
9 changes: 8 additions & 1 deletion internal/integration/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ func LoadSpecFiles(filesPath string) (Specs, error) {
continue
}
logrus.Debugf("spec file loaded for service:%s", sd.Service)
specs.SpecsByName[sd.Service] = sd
if spec, ok := specs.SpecsByName[sd.Service]; ok {
spec.Entities = append(spec.Entities, sd.Entities...)
specs.SpecsByName[sd.Service] = spec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curiosity, do you have to re-assign the variable in the map? Wouldn't it be sufficient to just append the entities?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was complaining that it was possible , but I will dig into that

Copy link
Contributor Author

@gsanchezgavier gsanchezgavier Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the map references to a value and not a pointer. And there's no guarantee on the location of that value.
https://stackoverflow.com/questions/32751537/why-do-i-get-a-cannot-assign-error-when-setting-value-to-a-struct-as-a-value-i

//TODO how to manage defaultEntity for each spec?
} else {
specs.SpecsByName[sd.Service] = sd
}

}

return specs, nil
Expand Down
12 changes: 12 additions & 0 deletions internal/integration/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ func TestSpecs_getEntity(t *testing.T) {
Labels: []keyValue{}},
wantErr: false,
},
{
name: "redisBisMetric",
fields: fields{specs.SpecsByName},
args: args{
Metric{
name: "redis_metric_bis",
attributes: labels.Set{},
}},
wantProps: entityNameProps{Service: "redis", Name: "testbisredis", DisplayName: "Redis test bis", Type: "REDIS_TESTBISREDIS",
Labels: []keyValue{}},
wantErr: false,
},
{
name: "missingDimentions",
fields: fields{specs.SpecsByName},
Expand Down
10 changes: 10 additions & 0 deletions internal/integration/test/prometheus_redis_bis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
service: redis
display_name: Redis
entities:
- name: testbisredis
display_name: Redis test bis
metrics:
- provider_name: redis_metric_bis
description: Total amount of time in seconds spent per command
unit: Counter