Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support clustersync component #47

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about add a var like var supportedComponentType map[string]struct{}?

Copy link
Contributor Author

@kqzh kqzh Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, but there won't be many instances in one exporter, and this function only exec once, so I think it's optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so I approved.

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