From 22491acef5d80f2bae56590a7947bbe6ab1739f2 Mon Sep 17 00:00:00 2001 From: Wan Kai Date: Thu, 25 Jan 2024 09:06:12 +0800 Subject: [PATCH] Add hierarchy relations auto-matching for MYSQL/POSTGRESQL/SO11Y_OAP/VIRTUAL_DATABASE (#159) --- Makefile.in | 4 ++-- .../kubernetes/templates/feature-agent/resources.yaml | 11 +++++++++-- .../feature-mysql-monitor/opentelemetry-config.yaml | 5 ++++- .../opentelemetry-config.yaml | 5 ++++- .../templates/feature-so11y/opentelemetry-config.yaml | 2 +- services/songs-service/build.gradle | 1 + .../songs-service/src/main/resources/application.yaml | 11 +++++++++++ 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Makefile.in b/Makefile.in index d01c419..983ed3b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -29,10 +29,10 @@ ES_IMAGE ?= docker.elastic.co/elasticsearch/elasticsearch-oss ES_IMAGE_TAG ?= 7.10.2 SW_OAP_IMAGE ?= ghcr.io/apache/skywalking/oap -SW_OAP_IMAGE_TAG ?= cc79bf688cd6e3faf091be9103f8254fbec0befe +SW_OAP_IMAGE_TAG ?= df3b0960914ae2cad43f96b110833032d0ff7109 SW_UI_IMAGE ?= ghcr.io/apache/skywalking/ui -SW_UI_IMAGE_TAG ?= cc79bf688cd6e3faf091be9103f8254fbec0befe +SW_UI_IMAGE_TAG ?= df3b0960914ae2cad43f96b110833032d0ff7109 SW_CLI_IMAGE ?= ghcr.io/apache/skywalking-cli/skywalking-cli:0883266bfaa36612927b69e35781b64ea181758d SW_EVENT_EXPORTER_IMAGE ?= ghcr.io/apache/skywalking-kubernetes-event-exporter/skywalking-kubernetes-event-exporter:8a012a3f968cb139f817189afb9b3748841bba22 diff --git a/deploy/platform/kubernetes/templates/feature-agent/resources.yaml b/deploy/platform/kubernetes/templates/feature-agent/resources.yaml index b6963c8..f3b6811 100644 --- a/deploy/platform/kubernetes/templates/feature-agent/resources.yaml +++ b/deploy/platform/kubernetes/templates/feature-agent/resources.yaml @@ -153,7 +153,14 @@ spec: value: tcp://activemq:61616 - name: ACTIVE_MQ_QUEUE value: queue-songs-ping - + {{- if .Values.features.postgresqlMonitor.enabled }} + - name: DATA_SOURCE_URL + value: jdbc:postgresql://psql.{{ .Release.Namespace }}.svc.cluster.local:5432/postgres + - name: DATA_SOURCE_USER + value: postgres + - name: DATA_SOURCE_PASSWORD + value: password + {{- end }} --- apiVersion: v1 kind: Service @@ -510,4 +517,4 @@ spec: ports: - protocol: TCP port: 80 - targetPort: 80 \ No newline at end of file + targetPort: 80 diff --git a/deploy/platform/kubernetes/templates/feature-mysql-monitor/opentelemetry-config.yaml b/deploy/platform/kubernetes/templates/feature-mysql-monitor/opentelemetry-config.yaml index c79697c..cad4d2d 100644 --- a/deploy/platform/kubernetes/templates/feature-mysql-monitor/opentelemetry-config.yaml +++ b/deploy/platform/kubernetes/templates/feature-mysql-monitor/opentelemetry-config.yaml @@ -28,8 +28,11 @@ - source_labels: [ __meta_kubernetes_pod_container_name, __meta_kubernetes_pod_container_port_name ] action: keep regex: mysqld-exporter;metrics # @feature: mysql; reference the name of the metrics port - - source_labels: [ __meta_kubernetes_pod_name ] + - source_labels: [ ] target_label: host_name + replacement: mysql.{{ .Release.Namespace }} + - source_labels: [ __meta_kubernetes_pod_name ] + target_label: service_instance_id regex: (.+) replacement: $$1 diff --git a/deploy/platform/kubernetes/templates/feature-postgresql-monitor/opentelemetry-config.yaml b/deploy/platform/kubernetes/templates/feature-postgresql-monitor/opentelemetry-config.yaml index 46b2a76..9cb0f63 100644 --- a/deploy/platform/kubernetes/templates/feature-postgresql-monitor/opentelemetry-config.yaml +++ b/deploy/platform/kubernetes/templates/feature-postgresql-monitor/opentelemetry-config.yaml @@ -28,8 +28,11 @@ - source_labels: [ __meta_kubernetes_pod_container_name, __meta_kubernetes_pod_container_port_name ] action: keep regex: psql-exporter;metrics # @feature: postgresql; reference the name of the metrics port - - source_labels: [ __meta_kubernetes_pod_name ] + - source_labels: [ ] target_label: host_name + replacement: psql.{{ .Release.Namespace }} + - source_labels: [ __meta_kubernetes_pod_name ] + target_label: service_instance_id regex: (.+) replacement: $$1 diff --git a/deploy/platform/kubernetes/templates/feature-so11y/opentelemetry-config.yaml b/deploy/platform/kubernetes/templates/feature-so11y/opentelemetry-config.yaml index 50c31da..f208708 100644 --- a/deploy/platform/kubernetes/templates/feature-so11y/opentelemetry-config.yaml +++ b/deploy/platform/kubernetes/templates/feature-so11y/opentelemetry-config.yaml @@ -28,7 +28,7 @@ regex: oap;metrics # @feature: so11y; reference the name of the metrics port - source_labels: [ ] target_label: service - replacement: oap-server + replacement: {{ include "skywalking.oap.fullname" .Subcharts.skywalking }}.{{ .Release.Namespace }} - source_labels: [ __meta_kubernetes_pod_name ] target_label: host_name regex: (.+) diff --git a/services/songs-service/build.gradle b/services/songs-service/build.gradle index 6afddb2..9c9c443 100644 --- a/services/songs-service/build.gradle +++ b/services/songs-service/build.gradle @@ -45,6 +45,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.kafka:spring-kafka' implementation 'com.h2database:h2' + runtimeOnly 'org.postgresql:postgresql' implementation 'org.apache.skywalking:apm-toolkit-logback-1.x:8.11.0' implementation 'org.apache.skywalking:apm-toolkit-micrometer-registry:8.11.0' implementation 'com.google.guava:guava:23.0' diff --git a/services/songs-service/src/main/resources/application.yaml b/services/songs-service/src/main/resources/application.yaml index 29835e0..e162faf 100644 --- a/services/songs-service/src/main/resources/application.yaml +++ b/services/songs-service/src/main/resources/application.yaml @@ -20,5 +20,16 @@ server: address: 0.0.0.0 spring: + sql: + init: + data-locations: classpath:data.sql + mode: always + datasource: + url: ${DATA_SOURCE_URL:jdbc:h2:mem:mem-db;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=FALSE} + username: ${DATA_SOURCE_USER:} + password: ${DATA_SOURCE_PASSWORD:} jpa: defer-datasource-initialization: true + hibernate: + ddl-auto: create +