mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01:00
Show gce sdconfig zone on vmagent:8429/config (#2178)
* vmagent: add test for marshalling gce sdconfig with ZoneYAML * vmagent: implement MarshalYAML for ZoneYAML on gce sdconfig
This commit is contained in:
parent
d107f86fbc
commit
943fc056ca
@ -54,6 +54,11 @@ func (z *ZoneYAML) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalYAML implements yaml.Marshaler
|
||||||
|
func (z ZoneYAML) MarshalYAML() (interface{}, error) {
|
||||||
|
return z.zones, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetLabels returns gce labels according to sdc.
|
// GetLabels returns gce labels according to sdc.
|
||||||
func (sdc *SDConfig) GetLabels(baseDir string) ([]map[string]string, error) {
|
func (sdc *SDConfig) GetLabels(baseDir string) ([]map[string]string, error) {
|
||||||
cfg, err := getAPIConfig(sdc)
|
cfg, err := getAPIConfig(sdc)
|
||||||
|
27
lib/promscrape/discovery/gce/gce_test.go
Normal file
27
lib/promscrape/discovery/gce/gce_test.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package gce
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMarshallingSDConfigWithZoneYAML(t *testing.T) {
|
||||||
|
sdConfig := SDConfig{
|
||||||
|
Project: "test-project",
|
||||||
|
Zone: ZoneYAML{
|
||||||
|
zones: []string{"zone-a", "zone-b"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := yaml.Marshal(sdConfig)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected non-nil error")
|
||||||
|
}
|
||||||
|
|
||||||
|
strData := string(data)
|
||||||
|
expected := "project: test-project\nzone:\n- zone-a\n- zone-b\n"
|
||||||
|
if strData != expected {
|
||||||
|
t.Fatalf("unexpected marshal:\ngot \n%vwant\n%v", strData, expected)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user