Skip to content

Commit

Permalink
support clustersync component (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
kqzh authored Aug 1, 2022
1 parent 289aef1 commit cf50130
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
14 changes: 13 additions & 1 deletion deploy/bare-metal/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ clusters:
- name: storaged2
endpointIP: 192.168.10.133
endpointPort: 19779
componentType: storaged
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
2 changes: 1 addition & 1 deletion exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 25 additions & 0 deletions exporter/type.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package exporter

import "fmt"

const (
DefaultClusterName = "default"

Expand All @@ -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 (
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cf50130

Please sign in to comment.