mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2026-05-30 08:15:25 +00:00
Fix case when backend is not set
Signed-off-by: Arjun Naik <arjun.rn@gmail.com>
This commit is contained in:
@@ -85,12 +85,12 @@ func getAnnotationWeight(backendWeights string, backend string) float64 {
|
|||||||
var weightsMap map[string]int
|
var weightsMap map[string]int
|
||||||
err := json.Unmarshal([]byte(backendWeights), &weightsMap)
|
err := json.Unmarshal([]byte(backendWeights), &weightsMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0
|
return 1
|
||||||
}
|
}
|
||||||
if weight, ok := weightsMap[backend]; ok {
|
if weight, ok := weightsMap[backend]; ok {
|
||||||
return float64(weight) / 100
|
return float64(weight) / 100
|
||||||
}
|
}
|
||||||
return 0
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWeights(ingressAnnotations map[string]string, backendAnnotations []string, backend string) float64 {
|
func getWeights(ingressAnnotations map[string]string, backendAnnotations []string, backend string) float64 {
|
||||||
|
|||||||
@@ -174,6 +174,18 @@ func TestSkipperCollector(t *testing.T) {
|
|||||||
readyReplicas: 5,
|
readyReplicas: 5,
|
||||||
backendAnnotations: []string{testBackendWeightsAnnotation, testStacksetWeightsAnnotation},
|
backendAnnotations: []string{testBackendWeightsAnnotation, testStacksetWeightsAnnotation},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
msg: "test backend is not set",
|
||||||
|
metrics: []int{100, 1500, 700},
|
||||||
|
ingressName: "dummy-ingress",
|
||||||
|
collectedMetric: 1500,
|
||||||
|
namespace: "default",
|
||||||
|
backend: "",
|
||||||
|
backendWeights: map[string]map[string]int{testBackendWeightsAnnotation: {"backend2": 100, "backend1": 0}},
|
||||||
|
replicas: 1,
|
||||||
|
readyReplicas: 1,
|
||||||
|
backendAnnotations: []string{testBackendWeightsAnnotation},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.msg, func(tt *testing.T) {
|
t.Run(tc.msg, func(tt *testing.T) {
|
||||||
client := fake.NewSimpleClientset()
|
client := fake.NewSimpleClientset()
|
||||||
|
|||||||
Reference in New Issue
Block a user