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

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 7a6a19db7f Aggregate nginx service metrics by using `multiple labels` 
feature & Remove unused type label in latency metrics. (#12096)
7a6a19db7f is described below

commit 7a6a19db7f8e2f20f987c8b6d510aaaeb930b0bc
Author: weixiang1862 <[email protected]>
AuthorDate: Fri Apr 12 18:08:07 2024 +0800

    Aggregate nginx service metrics by using `multiple labels` feature & Remove 
unused type label in latency metrics. (#12096)
---
 docs/en/changes/changes.md                         |  1 +
 .../src/main/resources/log-mal-rules/nginx.yaml    |  2 +-
 .../resources/otel-rules/nginx/nginx-endpoint.yaml |  2 +-
 .../resources/otel-rules/nginx/nginx-instance.yaml |  2 +-
 .../resources/otel-rules/nginx/nginx-service.yaml  | 16 +++++-----
 .../nginx/nginx-service.json                       | 20 ++++++------
 test/e2e-v2/cases/nginx/e2e.yaml                   | 12 +++----
 ...s-has-value-label-level-service_instance_id.yml | 37 ++++++++++++++++++++++
 ...metrics-has-value-label-service_instance_id.yml | 35 ++++++++++++++++++++
 ...s-has-value-label-state-service_instance_id.yml | 37 ++++++++++++++++++++++
 ...-has-value-label-status-service_instance_id.yml | 37 ++++++++++++++++++++++
 ...cs-has-value-label-type-service_instance_id.yml | 37 ++++++++++++++++++++++
 12 files changed, 211 insertions(+), 27 deletions(-)

diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index e6cb16b541..8de4efebbc 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -98,6 +98,7 @@
 * Remove unnecessary `componentIds` as series ID in the 
`ServiceRelationClientSideMetrics` and `ServiceRelationServerSideMetrics` 
entities.
 * Fix not throw error when part of expression not matched any expression node 
in the `MQE` and `PromQL.
 * Remove `kafka-fetcher/default/createTopicIfNotExist` as the creation is 
automatically since [#7326](https://github.com/apache/skywalking/issues/7326) 
(v8.7.0).
+* Fix inaccuracy nginx service metrics.
 
 #### UI
 
diff --git 
a/oap-server/server-starter/src/main/resources/log-mal-rules/nginx.yaml 
b/oap-server/server-starter/src/main/resources/log-mal-rules/nginx.yaml
index 380b43bd46..92f847fd7a 100644
--- a/oap-server/server-starter/src/main/resources/log-mal-rules/nginx.yaml
+++ b/oap-server/server-starter/src/main/resources/log-mal-rules/nginx.yaml
@@ -31,6 +31,6 @@
 metricPrefix: meter_nginx
 metricsRules:
   - name: service_error_log_count
-    exp: 
nginx_error_log_count.sum(['level','service']).downsampling(SUM).service(['service'],
 Layer.NGINX)
+    exp: 
nginx_error_log_count.sum(['level','service','service_instance_id']).downsampling(SUM).service(['service'],
 Layer.NGINX)
   - name: instance_error_log_count
     exp: 
nginx_error_log_count.sum(['level','service','service_instance_id']).downsampling(SUM).instance(['service'],['service_instance_id'],
 Layer.NGINX)
\ No newline at end of file
diff --git 
a/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-endpoint.yaml
 
b/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-endpoint.yaml
index cb51df9a40..e46cf98e07 100644
--- 
a/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-endpoint.yaml
+++ 
b/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-endpoint.yaml
@@ -36,7 +36,7 @@ metricsRules:
   - name: http_requests
     exp: nginx_http_requests_total.sum(['service','route']).rate('PT1M')
   - name: http_latency
-    exp: 
nginx_http_latency.sum(['type','le','service','route']).histogram().histogram_percentile([50,70,90,99])
+    exp: 
nginx_http_latency.sum(['le','service','route']).histogram().histogram_percentile([50,70,90,99])
   - name: http_bandwidth
     exp: nginx_http_size_bytes.sum(['type','service','route']).rate('PT1M')
   - name: http_status
diff --git 
a/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-instance.yaml
 
b/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-instance.yaml
index b72a469706..765c3fc33d 100644
--- 
a/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-instance.yaml
+++ 
b/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-instance.yaml
@@ -36,7 +36,7 @@ metricsRules:
   - name: http_requests
     exp: 
nginx_http_requests_total.sum(['service','service_instance_id']).rate('PT1M')
   - name: http_latency
-    exp: 
nginx_http_latency.sum(['type','le','service','service_instance_id']).histogram().histogram_percentile([50,70,90,99])
+    exp: 
nginx_http_latency.sum(['le','service','service_instance_id']).histogram().histogram_percentile([50,70,90,99])
   - name: http_bandwidth
     exp: 
nginx_http_size_bytes.sum(['type','service','service_instance_id']).rate('PT1M')
   - name: http_connections
diff --git 
a/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-service.yaml
 
b/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-service.yaml
index 29dac9072a..78d82f9d37 100644
--- 
a/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-service.yaml
+++ 
b/oap-server/server-starter/src/main/resources/otel-rules/nginx/nginx-service.yaml
@@ -34,18 +34,18 @@ expSuffix: service(['service'] , Layer.NGINX)
 metricPrefix: meter_nginx_service
 metricsRules:
   - name: http_requests
-    exp: nginx_http_requests_total.sum(['service']).rate('PT1M')
+    exp: 
nginx_http_requests_total.sum(['service','service_instance_id']).rate('PT1M')
   - name: http_latency
-    exp: 
nginx_http_latency.sum(['type','le','service']).histogram().histogram_percentile([50,70,90,99])
+    exp: 
nginx_http_latency.sum(['le','service']).histogram().histogram_percentile([50,70,90,99])
   - name: http_bandwidth
-    exp: nginx_http_size_bytes.sum(['type','service']).rate('PT1M')
+    exp: 
nginx_http_size_bytes.sum(['type','service','service_instance_id']).rate('PT1M')
   - name: http_connections
-    exp: nginx_http_connections.sum(['state','service'])
+    exp: nginx_http_connections.sum(['state','service','service_instance_id'])
   - name: http_status
-    exp: nginx_http_requests_total.sum(['status','service']).rate('PT1M')
+    exp: 
nginx_http_requests_total.sum(['status','service','service_instance_id']).rate('PT1M')
   - name: http_requests_increment
-    exp: nginx_http_requests_total.sum(['service']).increase('PT1M')
+    exp: 
nginx_http_requests_total.sum(['service','service_instance_id']).increase('PT1M')
   - name: http_4xx_requests_increment
-    exp: nginx_http_requests_total.tagMatch("status", 
"400|401|403|404|405").sum(['service']).increase('PT1M')
+    exp: nginx_http_requests_total.tagMatch("status", 
"400|401|403|404|405").sum(['service','service_instance_id']).increase('PT1M')
   - name: http_5xx_requests_increment
-    exp: nginx_http_requests_total.tagMatch("status", 
"500|502|503|504").sum(['service']).increase('PT1M')
\ No newline at end of file
+    exp: nginx_http_requests_total.tagMatch("status", 
"500|502|503|504").sum(['service','service_instance_id']).increase('PT1M')
\ No newline at end of file
diff --git 
a/oap-server/server-starter/src/main/resources/ui-initialized-templates/nginx/nginx-service.json
 
b/oap-server/server-starter/src/main/resources/ui-initialized-templates/nginx/nginx-service.json
index 317f7fa199..ced705bad1 100644
--- 
a/oap-server/server-starter/src/main/resources/ui-initialized-templates/nginx/nginx-service.json
+++ 
b/oap-server/server-starter/src/main/resources/ui-initialized-templates/nginx/nginx-service.json
@@ -33,7 +33,7 @@
                     "showYAxis": true
                   },
                   "expressions": [
-                    "meter_nginx_service_http_requests"
+                    "aggregate_labels(meter_nginx_service_http_requests, sum)"
                   ],
                   "metricMode": "Expression",
                   "typesOfMQE": [
@@ -85,7 +85,7 @@
                     "showYAxis": true
                   },
                   "expressions": [
-                    "meter_nginx_service_http_bandwidth/1024"
+                    "aggregate_labels(meter_nginx_service_http_bandwidth, 
sum(type))/1024"
                   ],
                   "metricMode": "Expression",
                   "typesOfMQE": [
@@ -100,7 +100,7 @@
                   "i": "4",
                   "type": "Widget",
                   "expressions": [
-                    "meter_nginx_service_http_connections"
+                    "aggregate_labels(meter_nginx_service_http_connections, 
sum(state))"
                   ],
                   "metricMode": "Expression",
                   "typesOfMQE": [
@@ -137,7 +137,7 @@
                     "showYAxis": true
                   },
                   "expressions": [
-                    "meter_nginx_service_http_status"
+                    "aggregate_labels(meter_nginx_service_http_status, 
sum(status))"
                   ],
                   "metricMode": "Expression",
                   "typesOfMQE": [
@@ -153,7 +153,7 @@
                   "type": "Widget",
                   "metricMode": "Expression",
                   "expressions": [
-                    
"(meter_nginx_service_http_4xx_requests_increment/meter_nginx_service_http_requests_increment)*100"
+                    
"aggregate_labels(meter_nginx_service_http_4xx_requests_increment, 
sum)/aggregate_labels(meter_nginx_service_http_requests_increment, sum)*100"
                   ],
                   "typesOfMQE": [
                     "TIME_SERIES_VALUES"
@@ -177,7 +177,7 @@
                   "type": "Widget",
                   "metricMode": "Expression",
                   "expressions": [
-                    
"(meter_nginx_service_http_5xx_requests_increment/meter_nginx_service_http_requests_increment)*100"
+                    
"aggregate_labels(meter_nginx_service_http_5xx_requests_increment, 
sum)/aggregate_labels(meter_nginx_service_http_requests_increment, sum)*100"
                   ],
                   "typesOfMQE": [
                     "TIME_SERIES_VALUES"
@@ -201,7 +201,7 @@
                   "type": "Widget",
                   "metricMode": "Expression",
                   "expressions": [
-                    "meter_nginx_service_error_log_count"
+                    "aggregate_labels(meter_nginx_service_error_log_count, 
sum(level))"
                   ],
                   "graph": {
                     "type": "Bar",
@@ -290,9 +290,9 @@
       "isRoot": false,
       "isDefault": true,
       "expressions": [
-        "avg(meter_nginx_service_http_status{status='200'})",
-        "avg(meter_nginx_service_http_status{status='404'})",
-        "avg(meter_nginx_service_http_status{status='500'})"
+        "avg(aggregate_labels(meter_nginx_service_http_status{status='200'}, 
sum))",
+        "avg(aggregate_labels(meter_nginx_service_http_status{status='404'}, 
sum))",
+        "avg(aggregate_labels(meter_nginx_service_http_status{status='500'}, 
sum))"
       ],
       "expressionsConfig": [
         {
diff --git a/test/e2e-v2/cases/nginx/e2e.yaml b/test/e2e-v2/cases/nginx/e2e.yaml
index 8fcfa49831..882354f229 100644
--- a/test/e2e-v2/cases/nginx/e2e.yaml
+++ b/test/e2e-v2/cases/nginx/e2e.yaml
@@ -47,19 +47,19 @@ verify:
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql service ls
       expected: expected/service.yml
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql metrics exec 
--expression=meter_nginx_service_http_requests --service-name=nginx::e2e-test
-      expected: expected/metrics-has-value.yml
+      expected: expected/metrics-has-value-label-service_instance_id.yml
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql metrics exec 
--expression=meter_nginx_service_http_latency --service-name=nginx::e2e-test
       expected: expected/metrics-has-value-label-percentile.yml
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql metrics exec 
--expression=meter_nginx_service_http_bandwidth --service-name=nginx::e2e-test
-      expected: expected/metrics-has-value-label-type.yml
+      expected: expected/metrics-has-value-label-type-service_instance_id.yml
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql metrics exec 
--expression=meter_nginx_service_http_connections --service-name=nginx::e2e-test
-      expected: expected/metrics-has-value-label-state.yml
+      expected: expected/metrics-has-value-label-state-service_instance_id.yml
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql metrics exec 
--expression=meter_nginx_service_http_status --service-name=nginx::e2e-test
-      expected: expected/metrics-has-value-label-status.yml
+      expected: expected/metrics-has-value-label-status-service_instance_id.yml
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql metrics exec 
--expression=meter_nginx_service_http_requests_increment 
--service-name=nginx::e2e-test
-      expected: expected/metrics-has-value.yml
+      expected: expected/metrics-has-value-label-service_instance_id.yml
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql metrics exec 
--expression=meter_nginx_service_error_log_count --service-name=nginx::e2e-test
-      expected: expected/metrics-has-value-label-level.yml
+      expected: expected/metrics-has-value-label-level-service_instance_id.yml
     - query: swctl --display yaml 
--base-url=http://${oap_host}:${oap_12800}/graphql logs list 
--service-name=nginx::e2e-test
       expected: expected/logs.yml
 
diff --git 
a/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-level-service_instance_id.yml
 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-level-service_instance_id.yml
new file mode 100644
index 0000000000..d88b230a02
--- /dev/null
+++ 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-level-service_instance_id.yml
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+type: TIME_SERIES_VALUES
+results:
+  {{- contains .results }}
+  - metric:
+      labels:
+        {{- contains .metric.labels }}
+        - key: level
+          value: {{ .value }}
+        - key: service_instance_id
+          value: {{ .value }}
+        {{- end}}
+    values:
+      {{- contains .values }}
+      - id: {{ notEmpty .id }}
+        value: {{ .value }}
+        traceid: null
+      - id: {{ notEmpty .id }}
+        value: null
+        traceid: null
+      {{- end}}
+  {{- end}}
+error: null
diff --git 
a/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-service_instance_id.yml
 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-service_instance_id.yml
new file mode 100644
index 0000000000..3d71dad534
--- /dev/null
+++ 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-service_instance_id.yml
@@ -0,0 +1,35 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+type: TIME_SERIES_VALUES
+results:
+  {{- contains .results }}
+  - metric:
+      labels:
+        {{- contains .metric.labels }}
+        - key: service_instance_id
+          value: {{ .value }}
+        {{- end}}
+    values:
+      {{- contains .values }}
+      - id: {{ notEmpty .id }}
+        value: {{ .value }}
+        traceid: null
+      - id: {{ notEmpty .id }}
+        value: null
+        traceid: null
+      {{- end}}
+  {{- end}}
+error: null
diff --git 
a/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-state-service_instance_id.yml
 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-state-service_instance_id.yml
new file mode 100644
index 0000000000..73aed12ac0
--- /dev/null
+++ 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-state-service_instance_id.yml
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+type: TIME_SERIES_VALUES
+results:
+  {{- contains .results }}
+  - metric:
+      labels:
+        {{- contains .metric.labels }}
+        - key: state
+          value: {{ .value }}
+        - key: service_instance_id
+          value: {{ .value }}
+        {{- end}}
+    values:
+      {{- contains .values }}
+      - id: {{ notEmpty .id }}
+        value: {{ .value }}
+        traceid: null
+      - id: {{ notEmpty .id }}
+        value: null
+        traceid: null
+      {{- end}}
+  {{- end}}
+error: null
diff --git 
a/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-status-service_instance_id.yml
 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-status-service_instance_id.yml
new file mode 100644
index 0000000000..c041fc9390
--- /dev/null
+++ 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-status-service_instance_id.yml
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+type: TIME_SERIES_VALUES
+results:
+  {{- contains .results }}
+  - metric:
+      labels:
+        {{- contains .metric.labels }}
+        - key: status
+          value: {{ .value }}
+        - key: service_instance_id
+          value: {{ .value }}
+        {{- end}}
+    values:
+      {{- contains .values }}
+      - id: {{ notEmpty .id }}
+        value: {{ .value }}
+        traceid: null
+      - id: {{ notEmpty .id }}
+        value: null
+        traceid: null
+      {{- end}}
+  {{- end}}
+error: null
diff --git 
a/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-type-service_instance_id.yml
 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-type-service_instance_id.yml
new file mode 100644
index 0000000000..0ae0af9cc7
--- /dev/null
+++ 
b/test/e2e-v2/cases/nginx/expected/metrics-has-value-label-type-service_instance_id.yml
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+type: TIME_SERIES_VALUES
+results:
+  {{- contains .results }}
+  - metric:
+      labels:
+        {{- contains .metric.labels }}
+        - key: type
+          value: {{ .value }}
+        - key: service_instance_id
+          value: {{ .value }}
+        {{- end}}
+    values:
+      {{- contains .values }}
+      - id: {{ notEmpty .id }}
+        value: {{ .value }}
+        traceid: null
+      - id: {{ notEmpty .id }}
+        value: null
+        traceid: null
+      {{- end}}
+  {{- end}}
+error: null

Reply via email to