-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(metrics): add additional labels to metrics
feat(metrics): change additionalLabelsArray to array and use regex to extract labels feat(metrics): add unit tests for BuildAdditionalLabelsValues function
- Loading branch information
1 parent
9bdcaf1
commit 889923c
Showing
5 changed files
with
109 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package probe | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestBuildAdditionalLabelsValues1(t *testing.T) { | ||
type args struct { | ||
podLabels map[string]string | ||
additionalLabels []string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want []string | ||
}{ | ||
{"common", args{map[string]string{"l1": "v1", "l2": "v2"}, []string{"n1=alv1", "n2=alv2"}}, []string{"alv1", "alv2"}}, | ||
{"match", args{map[string]string{"l1": "v1", "l2": "v2"}, []string{"n1=${labels:l1}", "n2=alv2"}}, []string{"v1", "alv2"}}, | ||
{"submatch", args{map[string]string{"l1": "v1", "l2": "v2"}, []string{"n1=prefix_${labels:l1}_${labels:l2}_suffix"}}, []string{"prefix_v1_v2_suffix"}}, | ||
{"nomatch", args{map[string]string{"l1": "v1", "l2": "v2"}, []string{"n1=${labels:ln}"}}, []string{""}}, | ||
{"empty", args{map[string]string{"l1": "v1", "l2": "v2"}, []string{}}, []string{}}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
AdditionalLabelValueExpr = []string{} | ||
InitAdditionalLabels(tt.args.additionalLabels) | ||
|
||
if got := BuildAdditionalLabelsValues(tt.args.podLabels); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("BuildAdditionalLabelsValues() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |