Skip to content

Commit

Permalink
fix: template render error and svc conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
kubeJocker committed Oct 25, 2023
1 parent 6c82698 commit 507be2f
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 19 deletions.
117 changes: 117 additions & 0 deletions controllers/monitor/builder/cue/engine/infra.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions controllers/monitor/reconcile/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions controllers/monitor/reconcile/oteld_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
9 changes: 5 additions & 4 deletions controllers/monitor/reconcile/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions controllers/monitor/types/otel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -340,16 +340,16 @@ 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{}

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)
Expand All @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/constant/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 507be2f

Please sign in to comment.