From cf50130bce9dcf2d69c22b468e67474b2962991e Mon Sep 17 00:00:00 2001 From: Kenshin <35095889+kqzh@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:51:21 +0800 Subject: [PATCH] support clustersync component (#47) --- deploy/bare-metal/config.yaml | 14 +++++++++++++- exporter/exporter.go | 2 +- exporter/type.go | 25 +++++++++++++++++++++++++ main.go | 4 ++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/deploy/bare-metal/config.yaml b/deploy/bare-metal/config.yaml index a927ce6..9b01b47 100644 --- a/deploy/bare-metal/config.yaml +++ b/deploy/bare-metal/config.yaml @@ -28,4 +28,16 @@ clusters: - name: storaged2 endpointIP: 192.168.10.133 endpointPort: 19779 - componentType: storaged \ No newline at end of file + componentType: storaged + - name: meta-listener-0 + endpointIP: 192.168.10.134 + endpointPort: 19569 + componentType: meta_listener + - name: storage-listener-0 + endpointIP: 192.168.10.134 + endpointPort: 19789 + componentType: storage_listener + - name: drainer0 + endpointIP: 192.168.10.134 + endpointPort: 19889 + componentType: drainer \ No newline at end of file diff --git a/exporter/exporter.go b/exporter/exporter.go index 6d35308..e09390a 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -159,7 +159,7 @@ func (e *NebulaExporter) collect(wg *sync.WaitGroup, namespace, clusterName stri instance.Name, instance.EndpointPort) wg.Add(2) - if instance.ComponentType == "storaged" { + if instance.ComponentType == ComponentTypeStoraged { wg.Add(1) go func() { defer wg.Done() diff --git a/exporter/type.go b/exporter/type.go index 07d178e..5b299b6 100644 --- a/exporter/type.go +++ b/exporter/type.go @@ -1,5 +1,7 @@ package exporter +import "fmt" + const ( DefaultClusterName = "default" @@ -13,6 +15,13 @@ const ( // FQNamespace represents the prometheus FQName FQNamespace = "nebula" NonNamespace = "none_namespace" + + ComponentTypeGraphd = "graphd" + ComponentTypeMetad = "metad" + ComponentTypeStoraged = "storaged" + ComponentTypeMetaListener = "meta_listener" + ComponentTypeStorageListener = "storage_listener" + ComponentTypeDrainer = "drainer" ) type ( @@ -33,3 +42,19 @@ type ( ComponentType string `yaml:"componentType"` } ) + +func (s *StaticConfig) Validate() error { + for _, cluster := range s.Clusters { + for _, instance := range cluster.Instances { + switch instance.ComponentType { + case ComponentTypeGraphd, ComponentTypeMetad, ComponentTypeStoraged, ComponentTypeMetaListener, ComponentTypeStorageListener, ComponentTypeDrainer: + continue + default: + return fmt.Errorf("invalid component type: %s", instance.ComponentType) + } + } + + } + + return nil +} diff --git a/main.go b/main.go index 4067391..cce6134 100644 --- a/main.go +++ b/main.go @@ -96,6 +96,10 @@ func main() { if err := yaml.Unmarshal(raw, &nebulaExporter.Config); err != nil { klog.Fatalf("unmarshal failed: %v", err) } + + if err := nebulaExporter.Config.Validate(); err != nil { + klog.Fatalf("bare-metal config validation failed: %v", err) + } } else { config, err := buildConfig(*kubeconfig) if err != nil {