forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_stats.go
49 lines (41 loc) · 1.26 KB
/
set_stats.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 surveyutils
import (
"context"
skclients "github.com/solo-io/solo-kit/pkg/api/v1/clients"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
"github.com/solo-io/supergloo/cli/pkg/helpers/clients"
"github.com/solo-io/supergloo/cli/pkg/options"
)
func SurveySetStats(ctx context.Context, in *options.SetStats) error {
mesh, err := SurveyMesh("select the mesh for which you wish to propagate metrics", ctx)
if err != nil {
return err
}
promCfgs, err := SurveyPrometheusConfigs(ctx)
if err != nil {
return err
}
in.TargetMesh = options.ResourceRefValue(mesh)
in.PrometheusConfigMaps = options.ResourceRefsValue(promCfgs)
return nil
}
func SurveyPrometheusConfigs(ctx context.Context) ([]core.ResourceRef, error) {
// collect prom configmaps list
promClient := clients.MustPrometheusConfigClient()
promCfgs, err := promClient.List("", skclients.ListOpts{Ctx: ctx})
if err != nil {
return nil, err
}
var selected []core.ResourceRef
for {
cfg, err := surveyResources("prometheus configmaps", "add a prometheus configmap (choose <done> to finish): ", "<done>", promCfgs.AsResources())
if err != nil {
return nil, err
}
// the user chose <done>
if cfg.Namespace == "" {
return selected, nil
}
selected = append(selected, cfg)
}
}