-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parameter encoding issue in TA (#930)
* logging * Fixed encoding issue of params * Do string replacement * Another test * Removed dockerfile changes * Fix broken test * Newline * Change placement of the log import
- Loading branch information
1 parent
7a4ec4e
commit ddeac3d
Showing
6 changed files
with
211 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package allocation | ||
|
||
import ( | ||
"github.com/prometheus/common/model" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestGetAllTargetsByCollectorAndJob(t *testing.T) { | ||
baseAllocator := NewAllocator(logger) | ||
baseAllocator.SetCollectors([]string{"test-collector"}) | ||
statefulAllocator := NewAllocator(logger) | ||
statefulAllocator.SetCollectors([]string{"test-collector-0"}) | ||
type args struct { | ||
collector string | ||
job string | ||
cMap map[string][]TargetItem | ||
allocator *Allocator | ||
} | ||
var tests = []struct { | ||
name string | ||
args args | ||
want []targetGroupJSON | ||
}{ | ||
{ | ||
name: "Empty target map", | ||
args: args{ | ||
collector: "test-collector", | ||
job: "test-job", | ||
cMap: map[string][]TargetItem{}, | ||
allocator: baseAllocator, | ||
}, | ||
want: nil, | ||
}, | ||
{ | ||
name: "Single entry target map", | ||
args: args{ | ||
collector: "test-collector", | ||
job: "test-job", | ||
cMap: map[string][]TargetItem{ | ||
"test-collectortest-job": { | ||
TargetItem{ | ||
JobName: "test-job", | ||
Label: model.LabelSet{ | ||
"test-label": "test-value", | ||
}, | ||
TargetURL: "test-url", | ||
Collector: &collector{ | ||
Name: "test-collector", | ||
NumTargets: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
allocator: baseAllocator, | ||
}, | ||
want: []targetGroupJSON{ | ||
{ | ||
Targets: []string{"test-url"}, | ||
Labels: map[model.LabelName]model.LabelValue{ | ||
"test-label": "test-value", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Multiple entry target map", | ||
args: args{ | ||
collector: "test-collector", | ||
job: "test-job", | ||
cMap: map[string][]TargetItem{ | ||
"test-collectortest-job": { | ||
TargetItem{ | ||
JobName: "test-job", | ||
Label: model.LabelSet{ | ||
"test-label": "test-value", | ||
}, | ||
TargetURL: "test-url", | ||
Collector: &collector{ | ||
Name: "test-collector", | ||
NumTargets: 1, | ||
}, | ||
}, | ||
}, | ||
"test-collectortest-job2": { | ||
TargetItem{ | ||
JobName: "test-job2", | ||
Label: model.LabelSet{ | ||
"test-label": "test-value", | ||
}, | ||
TargetURL: "test-url", | ||
Collector: &collector{ | ||
Name: "test-collector", | ||
NumTargets: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
allocator: baseAllocator, | ||
}, | ||
want: []targetGroupJSON{ | ||
{ | ||
Targets: []string{"test-url"}, | ||
Labels: map[model.LabelName]model.LabelValue{ | ||
"test-label": "test-value", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := GetAllTargetsByCollectorAndJob(tt.args.collector, tt.args.job, tt.args.cMap, tt.args.allocator); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("GetAllTargetsByCollectorAndJob() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
pkg/collector/testdata/http_sd_config_servicemonitor_test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
processors: | ||
receivers: | ||
prometheus: | ||
config: | ||
scrape_configs: | ||
- job_name: serviceMonitor/test/test/0 | ||
|
||
static_configs: | ||
- targets: ["prom.domain:1001", "prom.domain:1002", "prom.domain:1003"] | ||
labels: | ||
my: label | ||
|
||
file_sd_configs: | ||
- files: | ||
- file2.json | ||
|
||
exporters: | ||
logging: | ||
|
||
service: | ||
pipelines: | ||
metrics: | ||
receivers: [prometheus] | ||
processors: [] | ||
exporters: [logging] |