Skip to content

Commit

Permalink
fix: adapt to the latest configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kubeJocker committed Oct 10, 2023
1 parent 4197e6b commit df4d453
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 234 deletions.
1 change: 1 addition & 0 deletions controllers/monitor/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func BuildFromCUEForOTel(tplName string, fillMap map[string]any, lookupKey strin
}

value := cueValue.Value.LookupPath(cue.ParsePath(lookupKey))

bytes, err := value.MarshalJSON()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion controllers/monitor/builder/cue/exporter/prometheus.cue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ output: {
endpoint: parameters.endpoint
send_timestamps: parameters.send_timestamps
metric_expiration: parameters.metric_expiration
enable_open_metrics: prarameters.enable_open_metrics
enable_open_metrics: parameters.enable_open_metrics
resource_to_telemetry_conversion:
enabled: parameters.resource_to_telemetry_conversion_enabled
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,34 @@ parameters: {
container_runtime_type: *"containerd" | string
}


output:
runtime_contaienr: {
enable: parameters.enable
container_runtime_type: parameters.container_runtime_type
output: {
extensions: {
memory_ballast:
size_mib: 32
apecloud_k8s_observer: {
auth_type: "kubeConfig"
node: "${env:NODE_NAME}"
observe_pods: true
observe_nodes: false
}
"apecloud_k8s_observer/node": {
auth_type: "kubeConfig"
node: "${env:NODE_NAME}"
observe_pods: false
observe_nodes: true
}
runtime_container: {
enable: true
auth_type: "kubeConfig"
kubernetes_node: "${env:NODE_NAME}"
}
apecloud_engine_observer: {
pod_observer: "apecloud_k8s_observer"
container_observer: "runtime_container"
scraper_config_file: "/tmp/oteld_test_work/kb_engine.yaml"
}
}
}



6 changes: 6 additions & 0 deletions controllers/monitor/builder/cue/processor/processors.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
output:
memory_limiter:{
limit_mib: 512
spike_limit_mib: 128
check_interval: "10s"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

parameters: {
auth_type: *"service_account" | string
collection_interval: *"10s" | string
endpoint: *"http://localhost:10255" | string
auth_type: *"serviceAccount" | string
collection_interval: *"15s" | string
endpoint: *"`endpoint`:`kubelet_endpoint_port`" | string
}

output:
apecloudkubeletstats: {
auth_type: parameters.auth_type
collection_interval: parameters.collection_interval
endpoint: parameters.endpoint
extra_metadata_labels:
- k8s.volume.type
- kubeblocks
metric_groups:
- container
- pod
- volume
rule: "type == \"k8s.node\""
config: {
auth_type: parameters.auth_type
collection_interval: parameters.collection_interval
endpoint: parameters.endpoint
extra_metadata_labels: ["k8s.volume.type", "kubeblocks"]
metric_groups: ["container", "pod", "volume"]
resource_attributes:
receiver: "apecloudkubeletstats"
}
}


25 changes: 15 additions & 10 deletions controllers/monitor/builder/cue/receiver/metrics/apecloudmysql.cue
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

parameters: {
username: *"${env:MYSQL_USER}" | string
password: *"${env:MYSQL_PASSWORD}" | string
endpoint: *"`endpoint`:3306" | string
username: *"`envs[\"MYSQL_ROOT_USER\"]`" | string
password: *"`envs[\"MYSQL_ROOT_PASSWORD\"]" | string
allow_native_passwords: *true | bool
transport: *"tcp" | string
collection_interval: *"${env:COLLECTION_INTERVAL}" | string
collection_interval: *"`settings.CollectionInterval`" | string
}



output:
apecloudmysql: {
username: parameters.username
password: parameters.password
allow_native_passwords: parameters.allow_native_passwords
transport: parameters.transport
collection_interval: parameters.collection_interval
rule: "type == \"pod\" && monitor_type == \"mysql\""
config:{
endpoint: parameters.endpoint
username: parameters.username
password: parameters.password
allow_native_passwords: parameters.allow_native_passwords
transport: parameters.transport
collection_interval: parameters.collection_interval
}
resource_attributes:
receiver: "apecloudmysql"
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ parameters: {

output:
apecloudnode: {
collection_interval: parameters.collection_interval
rule: "type == \"k8s.node\""
config:
collection_interval: parameters.collection_interval
resource_attributes:
receiver: "apecloudnode"
}

22 changes: 22 additions & 0 deletions controllers/monitor/builder/cue/receiver/resource_attributes.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
output:
resource_attributes:
pod: {
app_kubernetes_io_component: "`labels[\"app.kubernetes.io/component\"]`"
app_kubernetes_io_instance: "`labels[\"app.kubernetes.io/instance\"]`"
app_kubernetes_io_managed_by: "`labels[\"app.kubernetes.io/managed-by\"]`"
app_kubernetes_io_name: "`labels[\"app.kubernetes.io/name\"]`"
app_kubernetes_io_version: "`labels[\"app.kubernetes.io/version\"]`"
apps_kubeblocks_io_component_name: "`labels[\"apps.kubeblocks.io/component-name\"]`"
node: "${env:NODE_NAME}"
namespace: "`namespace`"
pod: "`name`"
job: "oteld-app"
}
"k8s.node": {
kubernetes_io_arch: "`labels[\"kubernetes.io/arch\"]`"
kubernetes_io_hostname: "`labels[\"kubernetes.io/hostname\"]`"
kubernetes_io_os: "`labels[\"kubernetes.io/os\"]`"
node: "`name`"
hostname: "`hostname`"
job: "oteld-system"
}
16 changes: 16 additions & 0 deletions controllers/monitor/builder/cue/service/service.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters: {
logLevel: *"debug" | string
metricsPort: *6668 | int
}

output:
telemetry: {
logs:
level: parameters.logLevel
metrics:
address: "${env:HOST_IP}:" + "\(parameters.metricsPort)"
resource:
node: "${env:NODE_NAME}"
job: "oteld-telemetry"
}
extensions: ["memory_ballast", "apecloud_k8s_observer", "apecloud_k8s_observer/node", "runtime_container", "apecloud_engine_observer"]
123 changes: 0 additions & 123 deletions controllers/monitor/builder/otel_config_test.go

This file was deleted.

14 changes: 8 additions & 6 deletions controllers/monitor/reconcile/oteld.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ func buildOteldInstance(
datasources *v1alpha1.CollectorDataSourceList,
templates *v1alpha1.OTeldCollectorTemplateList,
) error {
err := mergeDatasourceForPipline(reqCtx, datasources)
instanceMap, err := BuildInstanceMapForPipline(datasources)
if err != nil {
return err
}
reqCtx.SetOteldInstanceMap(instanceMap)

for _, template := range templates.Items {
instance := reqCtx.GetOteldInstance(template.Spec.Mode)
Expand All @@ -89,14 +90,15 @@ func buildOteldInstance(
return nil
}

func mergeDatasourceForPipline(reqCtx monitortype.ReconcileCtx, datasources *v1alpha1.CollectorDataSourceList) error {
func BuildInstanceMapForPipline(datasources *v1alpha1.CollectorDataSourceList) (map[v1alpha1.Mode]*monitortype.OteldInstance, error) {
instanceMap := map[v1alpha1.Mode]*monitortype.OteldInstance{}
for _, dataSource := range datasources.Items {
mode := dataSource.Spec.Mode
if mode == "" {
mode = DefaultMode
}
oteldInstance := reqCtx.GetOteldInstance(mode)
if oteldInstance == nil {
oteldInstance, ok := instanceMap[mode]
if !ok {
oteldInstance = monitortype.NewOteldInstance()
}
switch dataSource.Spec.Type {
Expand Down Expand Up @@ -125,7 +127,7 @@ func mergeDatasourceForPipline(reqCtx monitortype.ReconcileCtx, datasources *v1a
}
oteldInstance.LogsPipline = append(oteldInstance.LogsPipline, pipline)
}
reqCtx.SetOteldInstance(dataSource.Spec.Mode, oteldInstance)
instanceMap[dataSource.Spec.Mode] = oteldInstance
}
return nil
return instanceMap, nil
}
Loading

0 comments on commit df4d453

Please sign in to comment.