-
Notifications
You must be signed in to change notification settings - Fork 7
/
metrics.go
37 lines (32 loc) · 970 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package injector
import (
"fmt"
"strings"
"github.com/flomesh-io/fsm/pkg/constants"
"github.com/flomesh-io/fsm/pkg/k8s"
)
// IsMetricsEnabled return whether metrics is enabled.
func IsMetricsEnabled(kubeController k8s.Controller, namespace string) (enabled bool, err error) {
ns := kubeController.GetNamespace(namespace)
if ns == nil {
log.Error().Err(errNamespaceNotFound).Msgf("Error retrieving namespace %s", namespace)
return false, errNamespaceNotFound
}
metrics, ok := ns.Annotations[constants.MetricsAnnotation]
if !ok {
return false, nil
}
log.Trace().Msgf("Metrics annotation: '%s:%s'", constants.MetricsAnnotation, metrics)
metrics = strings.ToLower(metrics)
if metrics != "" {
switch metrics {
case "enabled", "yes", "true":
enabled = true
case "disabled", "no", "false":
enabled = false
default:
err = fmt.Errorf("Invalid value specified for annotation %q: %s", constants.MetricsAnnotation, metrics)
}
}
return
}