You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2022/10/14 13:31:46 UTC

[skywalking-showcase] 01/01: Polish and fix apisix case

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-showcase.git

commit 83e063947830d86c9f4d1b492386bae0f5e48360
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Fri Oct 14 21:31:38 2022 +0800

    Polish and fix apisix case
---
 .../kubernetes/feature-agent/resources.yaml        | 135 ++++++++++-----------
 .../feature-apisix-monitor/resources.yaml          |  12 +-
 services/app/frontend/Dockerfile                   |   6 +-
 services/app/frontend/Dockerfile.agentless         |   5 +-
 4 files changed, 79 insertions(+), 79 deletions(-)

diff --git a/deploy/platform/kubernetes/feature-agent/resources.yaml b/deploy/platform/kubernetes/feature-agent/resources.yaml
index 0d6cca4..dc4989d 100644
--- a/deploy/platform/kubernetes/feature-agent/resources.yaml
+++ b/deploy/platform/kubernetes/feature-agent/resources.yaml
@@ -246,79 +246,72 @@ metadata:
 data:
   apisix: |
       routes:
-          -
-              uri: /browser/*
-              service_id: 1
-          -
-              uri: /v3/*
-              service_id: 1
-          -
-              uri: /homepage
-              service_id: 2
-              plugins:
-                  skywalking:
-                      service_name: agent::frontend
-                      service_instance_name: "$hostname"
-                      endpoint_addr: http://oap:12800
-          -
-              uri: /test
-              service_id: 2
-              plugins:
-                  skywalking:
-                      service_name: agent::frontend
-                      service_instance_name: "$hostname"
-                      endpoint_addr: http://oap:12800
+      - uri: /browser/*
+        service_id: 1
+      - uri: /v3/*
+        service_id: 1
+      - uri: /homepage
+        service_id: 2
+        plugins:
+          skywalking:
+            service_name: "${{SW_AGENT_SERVICE}}"
+            service_instance_name: "${{SW_AGENT_SERVICE_INSTANCE}}"
+            endpoint_addr: http://oap:12800
+      - uri: /test
+        service_id: 2
+        plugins:
+          skywalking:
+            service_name: "${{SW_AGENT_SERVICE}}"
+            service_instance_name: "${{SW_AGENT_SERVICE_INSTANCE}}"
+            endpoint_addr: http://oap:12800
       services:
-          -
-              id: 1
-              upstream_id: 1
-          -
-              id: 2
-              upstream_id: 2
+      - id: 1
+        upstream_id: 1
+      - id: 2
+        upstream_id: 2
 
       upstreams:
-          - id: 1
-            nodes:
-              "oap:12800": 1
-            type: roundrobin
-          - id: 2
-            nodes:
-              "app:80": 1
-            type: roundrobin
+      - id: 1
+        nodes:
+          "oap:12800": 1
+        type: roundrobin
+      - id: 2
+        nodes:
+          "app:80": 1
+        type: roundrobin
 
       global_rules:
-          -
-              id: 1
-              plugins:
-                  prometheus:
-                      export_addr:
-                        ip: "0.0.0.0"
-                        port: 9091
+      - id: 1
+        plugins:
+          prometheus:
+            export_addr:
+              ip: "0.0.0.0"
+              port: 9091
       #END
   config: |
-      apisix:
-        node_listen: 80
-        enable_ipv6: false
-        enable_admin: false
-        config_center: yaml
-      plugin_attr:
-        prometheus:
-          export_addr:
-            ip: "0.0.0.0"
-            port: 9091
-        skywalking:
-          service_name: agent::frontend
-          service_instance_name: "$hostname"
-          endpoint_addr: http://oap:12800
-      plugins:
-        - prometheus
-        - skywalking
-      nginx_config:
-          http_server_configuration_snippet: |
-              location ~ \.(gif|jpg|png|js|css|html)$ {
-                root /app/build;
-                index index.html;
-              }
+    apisix:
+      node_listen: 80
+      enable_ipv6: false
+      enable_admin: false
+      config_center: yaml
+    plugin_attr:
+      prometheus:
+        export_addr:
+          ip: "0.0.0.0"
+          port: 9091
+      skywalking:
+        service_name: "${{SW_AGENT_SERVICE}}"
+        service_instance_name: "${{SW_AGENT_SERVICE_INSTANCE}}"
+        endpoint_addr: http://oap:12800
+    plugins:
+      - prometheus
+      - skywalking
+    nginx_config:
+      http_server_configuration_snippet: |
+        location ~ \.(gif|jpg|png|js|css|html)$ {
+          root /app/build;
+          index index.html;
+        }
 ---
 apiVersion: apps/v1
 kind: Deployment
@@ -350,15 +343,17 @@ spec:
               cpu: 500m
               memory: "256Mi"
           ports:
-            -
-              containerPort: 80
+            - containerPort: 80
               name: http
-            -
-              containerPort: 9091 # APISIX Prometheus pulgin port
+            - containerPort: 9091 # APISIX Prometheus pulgin port
               name: metrics
           env:
             - name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
               value: ${BACKEND_SERVICE}:11800
+            - name: SW_SERVICE_INSTANCE
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.name
           volumeMounts:
             - name: apisix-config
               mountPath: /usr/local/apisix/conf/config.yaml
diff --git a/deploy/platform/kubernetes/feature-apisix-monitor/resources.yaml b/deploy/platform/kubernetes/feature-apisix-monitor/resources.yaml
index afd97c0..9c82bca 100644
--- a/deploy/platform/kubernetes/feature-apisix-monitor/resources.yaml
+++ b/deploy/platform/kubernetes/feature-apisix-monitor/resources.yaml
@@ -27,7 +27,7 @@ data:
   otel-collector-config: |
       receivers:
         prometheus:
-          config: 
+          config:
             scrape_configs:
               - job_name: 'apisix-monitoring'
                 scrape_interval: 5s
@@ -39,7 +39,7 @@ data:
                     action: keep
                     regex: frontend;metrics # @feature: apisix-monitor; reference the name of the metrics port
                   - source_labels: [__meta_kubernetes_pod_name]
-                    target_label: host_name
+                    target_label: service_instance_id
                     regex: (.+)
                     replacement: $$1
                   - target_label: skywalking_service
@@ -48,7 +48,7 @@ data:
         batch:
       exporters:
         otlp:
-          endpoint: ${BACKEND_SERVICE}:11800
+          endpoint: oap:11800
           tls:
             insecure: true
       service:
@@ -60,7 +60,7 @@ data:
             - batch
             exporters:
             - otlp
----    
+---
 apiVersion: apps/v1
 kind: Deployment
 metadata:
@@ -94,11 +94,11 @@ spec:
               memory: "512Mi"
             requests:
               cpu: 500m
-              memory: "512Mi"   
+              memory: "512Mi"
       volumes:
         - name: otel-collector-conf-apisix
           configMap:
             name: otel-collector-conf-apisix
             items:
               - key: otel-collector-config
-                path: otel-collector-config.yaml              
+                path: otel-collector-config.yaml
diff --git a/services/app/frontend/Dockerfile b/services/app/frontend/Dockerfile
index ccfdf9b..497b3ce 100644
--- a/services/app/frontend/Dockerfile
+++ b/services/app/frontend/Dockerfile
@@ -28,7 +28,7 @@ RUN git clone --recurse-submodules https://github.com/apache/skywalking-client-j
     git submodule sync ; \
     npm install ; \
     npm run build
-    
+
 WORKDIR /app
 
 COPY . .
@@ -39,5 +39,7 @@ RUN npm install /skywalking-client-js && \
 
 FROM apache/apisix:2.15.0-debian
 
-COPY --from=build /app/build /app/build
+ENV SW_AGENT_SERVICE=agent::frontend
+ENV SW_AGENT_SERVICE_INSTANCE=agent::frontend-instance
 
+COPY --from=build /app/build /app/build
diff --git a/services/app/frontend/Dockerfile.agentless b/services/app/frontend/Dockerfile.agentless
index 8b9006d..f224f6e 100644
--- a/services/app/frontend/Dockerfile.agentless
+++ b/services/app/frontend/Dockerfile.agentless
@@ -28,4 +28,7 @@ RUN npm install && \
 
 FROM apache/apisix:2.15.0-debian
 
-COPY --from=build /app/build /app/build
\ No newline at end of file
+ENV SW_AGENT_SERVICE=frontend
+ENV SW_AGENT_SERVICE_INSTANCE=frontend-instance
+
+COPY --from=build /app/build /app/build