envoy-als.yaml 4.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# 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.

rules:
  - name: envoy-als
18
    layer: MESH
19 20 21
    dsl: |
      filter {
        // only collect abnormal logs (http status code >= 300, or commonProperties?.responseFlags is not empty)
22
        if (parsed?.response?.responseCode?.value as Integer < 400 && !parsed?.commonProperties?.responseFlags?.toString()?.trim()) {
23 24 25
          abort {}
        }
        extractor {
26
          if (parsed?.response?.responseCode) {
27
            tag 'status.code': parsed?.response?.responseCode?.value
28
          }
29
          tag 'response.flag': parsed?.commonProperties?.responseFlags
30 31 32
        }
        sink {
          sampler {
33
            if (parsed?.commonProperties?.responseFlags?.toString()) {
34 35
              // use service:errorCode as sampler id so that each service:errorCode has its own sampler,
              // e.g. checkoutservice:[upstreamConnectionFailure], checkoutservice:[upstreamRetryLimitExceeded]
36
              rateLimit("${log.service}:${parsed?.commonProperties?.responseFlags?.toString()}") {
37
                rpm 6000
38 39 40 41 42
              }
            } else {
              // use service:responseCode as sampler id so that each service:responseCode has its own sampler,
              // e.g. checkoutservice:500, checkoutservice:404.
              rateLimit("${log.service}:${parsed?.response?.responseCode}") {
43
                rpm 6000
44 45 46 47 48
              }
            }
          }
        }
      }
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  - name: network-profiling-slow-trace
    layer: MESH
    dsl: |
      filter {
        json{
        }
        extractor{
          if (tag("LOG_KIND") == "NET_PROFILING_SAMPLED_TRACE") {
            sampledTrace {
              latency parsed.latency as Long
              uri parsed.uri as String
              reason parsed.reason as String

              if (parsed.client_process.process_id as String != "") {
                processId parsed.client_process.process_id as String
              } else if (parsed.client_process.local as Boolean) {
                processId ProcessRegistry.generateVirtualLocalProcess(parsed.service as String, parsed.serviceInstance as String) as String
              } else {
                processId ProcessRegistry.generateVirtualRemoteProcess(parsed.service as String, parsed.serviceInstance as String, parsed.client_process.address as String) as String
              }

              if (parsed.server_process.process_id as String != "") {
                destProcessId parsed.server_process.process_id as String
              } else if (parsed.server_process.local as Boolean) {
                destProcessId ProcessRegistry.generateVirtualLocalProcess(parsed.service as String, parsed.serviceInstance as String) as String
              } else {
                destProcessId ProcessRegistry.generateVirtualRemoteProcess(parsed.service as String, parsed.serviceInstance as String, parsed.server_process.address as String) as String
              }

              detectPoint parsed.detect_point as String

              if (parsed.component as String == "http" && parsed.ssl as Boolean) {
                componentId 129
              } else if (parsed.component as String == "http") {
                componentId 49
              } else if (parsed.ssl as Boolean) {
                componentId 130
              } else {
                componentId 110
              }
            }
          }
        }
      }