Skip to content

Commit

Permalink
chore: refactor config generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kubeJocker committed Oct 24, 2023
1 parent 9c86eca commit 1189cc5
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
4 changes: 2 additions & 2 deletions apis/monitor/v1alpha1/appdatasource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ type InputConfig struct {
}

type LogsDataSource struct {
Enable bool `json:"enable,omitempty"`
Enable bool `json:"enabled,omitempty"`

LogCollector *InputConfig `json:"logCollector,omitempty"`
LogCollector map[string]InputConfig `json:"logCollector,omitempty"`
}

// AppDataSourceSpec defines the desired state of AppDataSource
Expand Down
6 changes: 4 additions & 2 deletions apis/monitor/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions config/crd/bases/monitor.kubeblocks.io_appdatasources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ spec:
logs:
description: LogsConfig is the logs config
properties:
enable:
enabled:
type: boolean
logCollector:
properties:
include:
items:
type: string
type: array
additionalProperties:
properties:
include:
items:
type: string
type: array
type: object
type: object
type: object
metrics:
Expand Down
4 changes: 4 additions & 0 deletions controllers/monitor/reconcile/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func ConfigMap(reqCtx types.ReconcileCtx, params types.OTeldParams) error {
if configmap != nil {
desired = append(desired, configmap)
}
engineConfig, _ := buildEngineConfigForOteld(deployment, reqCtx.OTeld.Namespace, cg)
if engineConfig != nil {
desired = append(desired, engineConfig)
}
}

if err := expectedConfigMap(reqCtx, params, desired); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/monitor/reconcile/oteld.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func BuildInstanceMapForPipline(datasources *v1alpha1.CollectorDataSourceList, a
}
oteldInstance.MetricsPipline = append(oteldInstance.MetricsPipline, pipline)

instanceMap[dataSource.Spec.Mode] = oteldInstance
instanceMap[mode] = oteldInstance
}

for _, dataSource := range appDatasources.Items {
Expand All @@ -111,7 +111,7 @@ func BuildInstanceMapForPipline(datasources *v1alpha1.CollectorDataSourceList, a
oteldInstance.AppDataSources = []v1alpha1.AppDataSource{}
}
oteldInstance.AppDataSources = append(oteldInstance.AppDataSources, dataSource)
instanceMap[dataSource.Spec.Mode] = oteldInstance
instanceMap[mode] = oteldInstance
}
return instanceMap, nil
}
13 changes: 6 additions & 7 deletions controllers/monitor/types/otel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (cg *OteldConfigGenerater) GenerateEngineConfiguration(instance *OteldInsta
cfg = append(cfg, infraSlice...)
defaultConfigSlice := yaml.MapSlice{}
for _, dataSource := range instance.AppDataSources {
valMap = buildEngineValMap(dataSource, instance)
valMap = buildEngineValMap(dataSource)
configSlice, err := buildSliceFromCUE(engineTplPath, valMap)
if err != nil {
return nil, err
Expand All @@ -307,19 +307,18 @@ func (cg *OteldConfigGenerater) GenerateEngineConfiguration(instance *OteldInsta
return cfg, nil
}

func buildEngineValMap(source v1alpha1.AppDataSource, instance *OteldInstance) map[string]any {
collectorInterval := instance.Oteld.Spec.CollectionInterval
if source.Spec.CollectionInterval != "" {
collectorInterval = source.Spec.CollectionInterval
}
func buildEngineValMap(source v1alpha1.AppDataSource) map[string]any {
return map[string]any{
"cluster_name": source.Spec.ClusterName,
"component_name": source.Spec.ComponentName,
"container_name": source.Spec.ContainerName,
"metrics.enabled": source.Spec.Metrics.Enable,
"metrics.collection_interval": collectorInterval,
"metrics.collection_interval": source.Spec.Metrics.MetricsCollector.CollectionInterval,
"logs.enabled": source.Spec.Logs.Enable,
"metrics.enabled_metrics": source.Spec.Metrics.MetricsCollector.EnabledMetrics,
"logs.include": source.Spec.Logs.LogCollector,
}

}

func buildEngineInfraValMap(instance *OteldInstance) map[string]any {
Expand Down
1 change: 1 addition & 0 deletions controllers/monitor/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func NewReconcileTask(name string, task ReconcileFunc) ReconcileTask {
},
// Config: reqCtx.Config,
// Namespace: reqCtx.Namespace,
OTeld: reqCtx.OTeld,
OteldCfgRef: reqCtx.OteldCfgRef,
}
return task(reqCtx)
Expand Down
14 changes: 8 additions & 6 deletions deploy/helm/crds/monitor.kubeblocks.io_appdatasources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ spec:
logs:
description: LogsConfig is the logs config
properties:
enable:
enabled:
type: boolean
logCollector:
properties:
include:
items:
type: string
type: array
additionalProperties:
properties:
include:
items:
type: string
type: array
type: object
type: object
type: object
metrics:
Expand Down

0 comments on commit 1189cc5

Please sign in to comment.