# 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: v1
kind: ConfigMap
metadata:
  name: config-observability
  namespace: knative-serving
data:
  # LOGGING CONFIGURATION

  # Static parameters:

  # enable-var-log-collection defaults to false. A fluentd sidecar
  # will be set up to collect var log if this flag is true.
  logging.enable-var-log-collection: "false"

  # The fluentd sidecar image used to collect logs from /var/log as a sidecar.
  # Must be presented if logging.enable-var-log-collection is true.
  # KEEP THIS CONSISTENT WITH 999-cache.yaml
  # TODO(mattmoor): Devise a way to test that this (and others like it)
  # stay in sync.
  logging.fluentd-sidecar-image: "k8s.gcr.io/fluentd-elasticsearch:v2.0.4"

  # The fluentd sidecar output config to specify logging destination.
  logging.fluentd-sidecar-output-config: |
    # Parse json log before sending to Elastic Search
    <filter **>
      @type parser
      key_name log
      <parse>
        @type multi_format
        <pattern>
          format json
          time_key fluentd-time # fluentd-time is reserved for structured logs
          time_format %Y-%m-%dT%H:%M:%S.%NZ
        </pattern>
        <pattern>
          format none
          message_key log
        </pattern>
      </parse>
    </filter>
    # Send to Elastic Search
    <match **>
      @id elasticsearch
      @type elasticsearch
      @log_level info
      include_tag_key true
      # Elasticsearch service is in monitoring namespace.
      host elasticsearch-logging.monitoring
      port 9200
      logstash_format true
      <buffer>
        @type file
        path /var/log/fluentd-buffers/kubernetes.system.buffer
        flush_mode interval
        retry_type exponential_backoff
        flush_thread_count 2
        flush_interval 5s
        retry_forever
        retry_max_interval 30
        chunk_limit_size 2M
        queue_limit_length 8
        overflow_action block
      </buffer>
    </match>

  # The revision log url template, where ${REVISION_UID} will be replaced by the actual
  # revision uid. For the url to work you'll need to set up monitoring and have access to
  # the kibana dashboard using `kubectl proxy`.
  logging.revision-url-template: |
    http://localhost:8001/api/v1/namespaces/monitoring/services/kibana-logging/proxy/app/kibana#/discover?_a=(query:(match:(kubernetes.labels.knative-dev%2FrevisionUID:(query:'${REVISION_UID}',type:phrase))))
