# Copyright 2018 The Knative Authors
#
# Licensed 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
#
#     https://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.

apiVersion: "config.istio.io/v1alpha2"
kind: logentry
metadata:
  name: requestlog
  namespace: istio-system
  labels:
    serving.knative.dev/release: devel
spec:
  severity: '"Info"'
  timestamp: request.time
  variables:
    method: request.method | ""
    url: request.path | ""
    protocol: request.scheme | "http"
    requestSize: request.size | 0
    requestHost: request.host | ""
    responseCode: response.code | 0
    responseSize: response.size | 0
    latency: response.duration | "0ms"
    sourceK8sService: source.service | "unknown"
    sourceNamespace: source.namespace | "unknown"
    destinationK8sService: destination.service | ""
    destinationNamespace: destination.namespace | ""
    destinationRevision: destination.labels["serving.knative.dev/revision"] | "unknown"
    destinationConfiguration: destination.labels["serving.knative.dev/configuration"] | "unknown"
    destinationService: destination.labels["serving.knative.dev/service"] | "unknown"
    traceId: request.headers["x-b3-traceid"] | "unknown"
    userAgent: request.useragent | "unknown"
    referer: request.referer | "unknown"
  monitored_resource_type: '"UNSPECIFIED"'
---
apiVersion: "config.istio.io/v1alpha2"
kind: fluentd
metadata:
  name: requestloghandler
  namespace: istio-system
  labels:
    serving.knative.dev/release: devel
spec:
  address: "fluentd-ds.knative-monitoring:24224"
---
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
  name: requestlogtofluentd
  namespace: istio-system
  labels:
    serving.knative.dev/release: devel
spec:
  match: context.protocol == "http" || context.protocol == "grpc"
  actions:
   - handler: requestloghandler.fluentd
     instances:
     - requestlog.logentry
