-
Notifications
You must be signed in to change notification settings - Fork 10
/
metrics.go
49 lines (41 loc) · 1.34 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"io"
mapset "github.com/deckarep/golang-set"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
"github.com/flomesh-io/fsm/pkg/constants"
)
const metricsDescription = `
This command consists of multiple subcommands related to managing metrics
associated with fsm.
`
func newMetricsCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "metrics",
Short: "manage metrics",
Long: metricsDescription,
Args: cobra.NoArgs,
}
cmd.AddCommand(newMetricsEnable(out))
cmd.AddCommand(newMetricsDisable(out))
return cmd
}
// isMonitoredNamespace returns true if the Namespace is correctly annotated for monitoring given a set of existing meshes
func isMonitoredNamespace(ns corev1.Namespace, meshList mapset.Set) (bool, error) {
// Check if the namespace has the resource monitor annotation
meshName, monitored := ns.Labels[constants.FSMKubeResourceMonitorAnnotation]
if !monitored {
return false, nil
}
if meshName == "" {
return false, fmt.Errorf("Label %q on namespace %q cannot be empty",
constants.FSMKubeResourceMonitorAnnotation, ns.Name)
}
if !meshList.Contains(meshName) {
return false, fmt.Errorf("Invalid mesh name %q used with label %q on namespace %q, must be one of %v",
meshName, constants.FSMKubeResourceMonitorAnnotation, ns.Name, meshList.ToSlice())
}
return true, nil
}