From 507be2f6ef0e80d90ce97b83d92e06a079c9e5a3 Mon Sep 17 00:00:00 2001 From: hanguobiao Date: Wed, 25 Oct 2023 15:24:08 +0800 Subject: [PATCH] fix: template render error and svc conflict --- .../monitor/builder/cue/engine/infra.cue | 117 ++++++++++++++++++ .../cue/receiver/metrics/app/pulsar.cue | 4 +- controllers/monitor/reconcile/deployment.go | 5 +- controllers/monitor/reconcile/oteld_agent.go | 5 +- controllers/monitor/reconcile/utils.go | 9 +- controllers/monitor/types/otel_config.go | 18 +-- pkg/constant/const.go | 3 + 7 files changed, 142 insertions(+), 19 deletions(-) diff --git a/controllers/monitor/builder/cue/engine/infra.cue b/controllers/monitor/builder/cue/engine/infra.cue index 8cd0bff626a9..03cc5bf7cb85 100644 --- a/controllers/monitor/builder/cue/engine/infra.cue +++ b/controllers/monitor/builder/cue/engine/infra.cue @@ -8,4 +8,121 @@ output: { collection_interval: parameters.collection_interval, initial_delay: parameters.initial_delay, timeout: parameters.timeout, + default_scrape_configs: { + "apecloud-mysql/mysql/mysql/mysql": { + enabled_metrics: true + enabled_logs: true + metrics_collector: { + collection_interval: "30s" + enable_metrics:["global_status", "global_variables", "slave_status"] + } + logs_collector: { + errorlog: + include: ["/data/mysql/log/mysqld-error.log"] + slow: + include: ["/data/mysql/log/mysqld-slowquery.log"] + } + + } + + "apecloud-mysql/mysql/vttablet/vttablet": { + enabled_metrics: true + enabled_logs: false + metrics_collector: + collection_interval: "30s" + } + + "apecloud-mysql/vtgate/vtgate/mysql": { + enabled_metrics: false + enabled_logs: true + logs_collector: { + errorlog: + include: ["/vtdataroot/vtgate.ERROR", "/vtdataroot/vtgate.WARNING", "/vtdataroot/vtgate.INFO"] + queryLog: + include: ["/vtdataroot/vtgate_querylog.txt"] + } + } + + "apecloud-mysql/vtcontroller/vtconsensus/vtcontroller": { + enabled_metrics: false + enabled_logs: true + logs_collector: + errorlog: + include: ["/vtdataroot/vtcontroller/vtcontroller.ERROR", "/vtdataroot/vtcontroller/vtcontroller.WARNING", "/vtdataroot/vtcontroller/vtcontroller.INFO"] + } + + "postgresql/postgresql/postgresql/postgresql": { + enabled_metrics: true + enabled_logs: true + metrics_collector: + collection_interval: "30s" + logs_collector: + runninglog: + include: ["/home/postgres/pgdata/pgroot/data/log/postgresql-*"] + } + + + "redis/redis/redis/redis": { + enabled_metrics: true + enabled_logs: true + metrics_collector: + collection_interval: "30s" + logs_collector: + runninglog: + include: ["/data/running.log"] + } + + "mongodb/mongodb/mongodb/mongodb": { + enabled_metrics: true + enabled_logs: true + metrics_collector: + collection_interval: "30s" + logs_collector: + runninglog: + include: ["/data/mongodb/logs/mongodb.log*"] + } + + "pulsar/pulsar-broker/broker/*": { + enabled_metrics: true + enabled_logs: false + metrics_collector: + collection_interval: "30s" + } + + "pulsar/pulsar-proxy/proxy/*": { + enabled_metrics: true + enabled_logs: false + metrics_collector: + collection_interval: "30s" + } + + "pulsar/bookies/bookies/*": { + enabled_metrics: true + enabled_logs: false + metrics_collector: + collection_interval: "30s" + } + + "pulsar/bookies-recovery/bookies-recovery/*":{ + enabled_metrics: true + enabled_logs: false + metrics_collector: + collection_interval: "30s" + } + + "pulsar/zookeeper/zookeeper/*": { + enabled_metrics: true + enabled_logs: false + metrics_collector: + collection_interval: "30s" + } + + "qdrant/qdrant/qdrant/prometheus": { + enabled_metrics: true + enabled_logs: false + metrics_collector: + collection_interval: "30s" + } + } } + diff --git a/controllers/monitor/builder/cue/receiver/metrics/app/pulsar.cue b/controllers/monitor/builder/cue/receiver/metrics/app/pulsar.cue index 5cadb0df24bc..96a6e4295c1c 100644 --- a/controllers/monitor/builder/cue/receiver/metrics/app/pulsar.cue +++ b/controllers/monitor/builder/cue/receiver/metrics/app/pulsar.cue @@ -23,7 +23,7 @@ output: { "prometheus_simple/pulsar": { rule: "type == \"container\" && config != nil && config.EnabledMetrics && config.ClusterDefName == \"pulsar\" && ( config.ComponentDefName == \"bookies-recovery\" || config.ComponentDefName == \"zookeeper\" || config.ComponentDefName == \"bookies\" )" config: { - collection_interval: "settings.CollectionInterval" + collection_interval: "`settings.CollectionInterval`" use_service_account: false endpoint: parameters.endpoint disable_keep_alives: false @@ -32,7 +32,7 @@ output: { "prometheus_simple/pulsar2": { rule: "type == \"container\" && config != nil && config.EnabledMetrics && config.ClusterDefName == \"pulsar\" && ( config.ComponentDefName == \"bookies-recovery\" || config.ComponentDefName == \"zookeeper\" || config.ComponentDefName == \"bookies\" )" config: { - collection_interval: "settings.CollectionInterval" + collection_interval: "`settings.CollectionInterval`" use_service_account: false endpoint: parameters.endpoint disable_keep_alives: false diff --git a/controllers/monitor/reconcile/deployment.go b/controllers/monitor/reconcile/deployment.go index 9b169d6dc32d..6a9d56c5d625 100644 --- a/controllers/monitor/reconcile/deployment.go +++ b/controllers/monitor/reconcile/deployment.go @@ -83,9 +83,10 @@ func buildDeploymentForOteld(instance *monitortypes.OteldInstance, namespace, na commonLabels := map[string]string{ constant.AppManagedByLabelKey: constant.AppName, - constant.AppNameLabelKey: OTeldName, - constant.AppInstanceLabelKey: name, + constant.AppNameLabelKey: "apecloudoteld", + constant.AppInstanceLabelKey: "apecloudoteld", constant.MonitorManagedByKey: "oteld", + constant.MonitorMode: string(monitorv1alpha1.ModeDeployment), } labelSelector := &metav1.LabelSelector{ diff --git a/controllers/monitor/reconcile/oteld_agent.go b/controllers/monitor/reconcile/oteld_agent.go index 9919486aa729..1815d5cda6e3 100644 --- a/controllers/monitor/reconcile/oteld_agent.go +++ b/controllers/monitor/reconcile/oteld_agent.go @@ -75,9 +75,10 @@ func OTeldAgent(reqCtx types.ReconcileCtx, params types.OTeldParams) error { func buildDaemonSetForOteld(instance *types.OteldInstance, namespace string, name string) *appsv1.DaemonSet { commonLabels := map[string]string{ constant.AppManagedByLabelKey: constant.AppName, - constant.AppNameLabelKey: OTeldName, - constant.AppInstanceLabelKey: name, + constant.AppNameLabelKey: "apecloudoteld", + constant.AppInstanceLabelKey: "apecloudoteld", constant.MonitorManagedByKey: "oteld", + constant.MonitorMode: string(monitorv1alpha1.ModeDaemonSet), } labelSelector := &metav1.LabelSelector{ diff --git a/controllers/monitor/reconcile/utils.go b/controllers/monitor/reconcile/utils.go index 2ac6ead6ca52..ff00b86ee2de 100644 --- a/controllers/monitor/reconcile/utils.go +++ b/controllers/monitor/reconcile/utils.go @@ -215,6 +215,7 @@ func buildSvcForOtel(oteld *v1alpha1.OTeld, namespace string, mode v1alpha1.Mode selectors = map[string]string{ constant.AppInstanceLabelKey: "apecloudoteld", constant.AppNameLabelKey: "apecloudoteld", + constant.MonitorMode: string(mode), } ) @@ -240,7 +241,7 @@ func buildConfigMapForOteld(instance *types.OteldInstance, namespace string, exp constant.AppInstanceLabelKey: name, } - configData, _ := gc.GenerateOteldConfiguration(instance, exporters.MetricsExporter, exporters.LogsExporter) + configData, _ := gc.GenerateOteldConfiguration(instance, exporters.MetricsExporter, exporters.LogsExporter, mode) marshal, err := yaml.Marshal(configData) if err != nil { return nil, err @@ -266,7 +267,7 @@ func buildEngineConfigForOteld(instance *types.OteldInstance, namespace string, constant.AppInstanceLabelKey: name, } - configData, _ := gc.GenerateEngineConfiguration(instance) + configData, _ := gc.GenerateEngineConfiguration(instance, mode) marshal, err := yaml.Marshal(configData) if err != nil { return nil, err @@ -292,7 +293,7 @@ func buildSecretForOteld(instance *types.OteldInstance, namespace string, export constant.AppInstanceLabelKey: name, } - configData, _ := gc.GenerateOteldConfiguration(instance, exporters.MetricsExporter, exporters.LogsExporter) + configData, _ := gc.GenerateOteldConfiguration(instance, exporters.MetricsExporter, exporters.LogsExporter, mode) marshal, err := yaml.Marshal(configData) if err != nil { return nil, err @@ -318,7 +319,7 @@ func buildEngineSecretForOteld(instance *types.OteldInstance, namespace string, constant.AppInstanceLabelKey: name, } - configData, _ := gc.GenerateEngineConfiguration(instance) + configData, _ := gc.GenerateEngineConfiguration(instance, mode) marshal, err := yaml.Marshal(configData) if err != nil { return nil, err diff --git a/controllers/monitor/types/otel_config.go b/controllers/monitor/types/otel_config.go index f6012b3622d0..050a4c2b2c87 100644 --- a/controllers/monitor/types/otel_config.go +++ b/controllers/monitor/types/otel_config.go @@ -62,15 +62,15 @@ func NewConfigGenerator() *OteldConfigGenerater { } } -func (cg *OteldConfigGenerater) GenerateOteldConfiguration(instance *OteldInstance, metricsExporterList []v1alpha1.MetricsExporterSink, logsExporterList []v1alpha1.LogsExporterSink) (yaml.MapSlice, error) { +func (cg *OteldConfigGenerater) GenerateOteldConfiguration(instance *OteldInstance, metricsExporterList []v1alpha1.MetricsExporterSink, logsExporterList []v1alpha1.LogsExporterSink, mode v1alpha1.Mode) (yaml.MapSlice, error) { var err error var cfg = yaml.MapSlice{} if instance == nil || instance.Oteld == nil { return nil, nil } - if cg.cache != nil && cg.cache[instance.Oteld.Spec.Mode] != nil { - return cg.cache[instance.Oteld.Spec.Mode], nil + if cg.cache != nil && cg.cache[mode] != nil { + return cg.cache[mode], nil } if cfg, err = cg.appendExtentions(cfg); err != nil { return nil, err @@ -88,7 +88,7 @@ func (cg *OteldConfigGenerater) GenerateOteldConfiguration(instance *OteldInstan return nil, err } - cg.cache[instance.Oteld.Spec.Mode] = cfg + cg.cache[mode] = cfg return cfg, nil } @@ -340,7 +340,7 @@ func buildSliceFromCUE(tplName string, valMap map[string]any) (yaml.MapSlice, er return extensionSlice, nil } -func (cg *OteldConfigGenerater) GenerateEngineConfiguration(instance *OteldInstance) (yaml.MapSlice, error) { +func (cg *OteldConfigGenerater) GenerateEngineConfiguration(instance *OteldInstance, mode v1alpha1.Mode) (yaml.MapSlice, error) { var err error var valMap map[string]any var cfg = yaml.MapSlice{} @@ -348,8 +348,8 @@ func (cg *OteldConfigGenerater) GenerateEngineConfiguration(instance *OteldInsta if instance == nil || instance.Oteld == nil { return nil, nil } - if cg.engineCache != nil && cg.engineCache[instance.Oteld.Spec.Mode] != nil { - return cg.engineCache[instance.Oteld.Spec.Mode], nil + if cg.engineCache != nil && cg.engineCache[mode] != nil { + return cg.engineCache[mode], nil } valMap = buildEngineInfraValMap(instance) @@ -368,8 +368,8 @@ func (cg *OteldConfigGenerater) GenerateEngineConfiguration(instance *OteldInsta } defaultConfigSlice = append(defaultConfigSlice, configSlice...) } - cfg = append(cfg, yaml.MapItem{Key: "default_config", Value: defaultConfigSlice}) - cg.engineCache[instance.Oteld.Spec.Mode] = cfg + cfg = append(cfg, yaml.MapItem{Key: "scrape_configs", Value: defaultConfigSlice}) + cg.engineCache[mode] = cfg return cfg, nil } diff --git a/pkg/constant/const.go b/pkg/constant/const.go index 4818d8792550..c582eaf8e5bc 100644 --- a/pkg/constant/const.go +++ b/pkg/constant/const.go @@ -171,6 +171,9 @@ const ( MonitorPathKey = "monitor.kubeblocks.io/path" MonitorSchemaKey = "monitor.kubeblocks.io/schema" MonitorManagedByKey = "monitor.kubeblocks.io/managed-by" + + // monitor.io labels + MonitorMode = "monitor.kubeblocks.io/mode" ) const (