Skip to content

Commit 20d5fe7

Browse files
committed
dev: rework CHI discovery process in monitoring
1 parent 6b74779 commit 20d5fe7

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

pkg/metrics/clickhouse/exporter.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -386,27 +386,32 @@ func (e *Exporter) DiscoveryWatchedCHIs(kubeClient kube.Interface, chopClient *c
386386

387387
// Walk over the list of ClickHouseInstallation objects and add them as watched
388388
for i := range list.Items {
389-
// Convenience wrapper
390-
chi := &list.Items[i]
389+
e.processDiscoveredCR(kubeClient, &list.Items[i])
390+
}
391+
}
391392

392-
if chi.IsStopped() {
393-
log.V(1).Infof("CHI %s/%s is stopped, skip it", chi.Namespace, chi.Name)
394-
continue
395-
}
393+
func (e *Exporter) processDiscoveredCR(kubeClient kube.Interface, chi *api.ClickHouseInstallation) {
394+
if e.shouldSkipDiscoveredCR(chi) {
395+
log.V(1).Infof("Skip discovered CHI: %s/%s", chi.Namespace, chi.Name)
396+
return
397+
}
396398

397-
if !chi.GetStatus().HasNormalizedCRCompleted() {
398-
log.V(1).Infof("CHI %s/%s is not completed yet, skip it", chi.Namespace, chi.Name)
399-
continue
400-
}
399+
log.V(1).Infof("Add discovered CHI: %s/%s", chi.Namespace, chi.Name)
400+
normalizer := chiNormalizer.New(func(namespace, name string) (*core.Secret, error) {
401+
return kubeClient.CoreV1().Secrets(namespace).Get(context.TODO(), name, controller.NewGetOptions())
402+
})
401403

402-
log.V(1).Infof("CHI %s/%s is completed, add it", chi.Namespace, chi.Name)
403-
normalizer := chiNormalizer.New(func(namespace, name string) (*core.Secret, error) {
404-
return kubeClient.CoreV1().Secrets(namespace).Get(context.TODO(), name, controller.NewGetOptions())
405-
})
404+
normalized, _ := normalizer.CreateTemplated(chi, normalizerCommon.NewOptions[api.ClickHouseInstallation]())
406405

407-
normalized, _ := normalizer.CreateTemplated(chi, normalizerCommon.NewOptions[api.ClickHouseInstallation]())
406+
watchedCHI := metrics.NewWatchedCR(normalized)
407+
e.updateWatched(watchedCHI)
408+
}
408409

409-
watchedCHI := metrics.NewWatchedCR(normalized)
410-
e.updateWatched(watchedCHI)
410+
func (e *Exporter) shouldSkipDiscoveredCR(chi *api.ClickHouseInstallation) bool {
411+
if chi.IsStopped() {
412+
log.V(1).Infof("CHI %s/%s is stopped, skip it", chi.Namespace, chi.Name)
413+
return true
411414
}
415+
416+
return false
412417
}

0 commit comments

Comments
 (0)