# Copyright 2022 Google LLC
#
# 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
#
#      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.

public_url: "https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/third-party/couchdb"
app_url: "https://couchdb.apache.org/"
short_name: CouchDB
long_name: Apache CouchDB
logo_path: /stackdriver/images/couchdb.png # supplied by google technical writer
description: |-
  The Apache CouchDB integration collects traffic-related metrics, such as the
  number of requests to a node and responses from the node. It also collects
  database metrics, such as how many are open and the number of operations. The
  integration collects general CouchDB and access logs and parses them into a JSON
  payload. The result includes fields for user, host, level, and message.
configure_integration: |-
  This integration does not require any additional configuration with
  CouchDB versions prior to 3.4.0, or on Debian-based distributions.

  As of version 3.4.0, CouchDB behaves differently on RPM-based
  distributions (like RHEL or Rocky Linux). To make CouchDB work with
  this logging receiver's default configuration on such systems, you must
  configure Apache CouchDB to write to `/var/log/couchdb/couchdb.log`
  instead of journald.

  To write logs to `/var/log/couchdb/couchdb.log`, complete the
  following steps:

  1. Create the file `/opt/couchdb/etc/local.d/ops-agent-filelog.ini`.

  1. Add the following lines to the file:

     ```none
     [log]
     writer = file
     file = /var/log/couchdb/couchdb.log
     level = info
     ```

  1. Restart Apache CouchDB:

     ```
     sudo systemctl restart couchdb
     ```
minimum_supported_agent_version:
  metrics: 2.10.0
  logging: 2.11.0
supported_operating_systems: linux
platforms_to_skip:
  # couchdb is not supported on various distros.
  - suse-cloud:sles-12
  - suse-cloud:sles-15
  - suse-cloud:sles-15-arm64
  - rocky-linux-cloud:rocky-linux-8-optimized-gcp-arm64
  - rocky-linux-cloud:rocky-linux-9
  - rocky-linux-cloud:rocky-linux-9-optimized-gcp
  - rocky-linux-cloud:rocky-linux-9-arm64
  - rocky-linux-cloud:rocky-linux-9-optimized-gcp-arm64
  - ubuntu-os-cloud:ubuntu-2404-lts-amd64
  - ubuntu-os-cloud:ubuntu-2404-lts-arm64
  - ubuntu-os-cloud:ubuntu-2410-amd64 # Possible support in the future
  - ubuntu-os-cloud:ubuntu-minimal-2410-amd64 # Possible support in the future
  - ubuntu-os-cloud:ubuntu-2410-arm64 # Possible support in the future
  - ubuntu-os-cloud:ubuntu-minimal-2410-arm64 # Possible support in the future
  - debian-cloud:debian-12
  - debian-cloud:debian-12-arm64
supported_app_version: ["2.3.x", "3.1 and higher"]
expected_metrics:
  - type: workload.googleapis.com/couchdb.average_request_time
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/couchdb.database.open
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
    representative: true
  - type: workload.googleapis.com/couchdb.database.operations
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: operation
        value_regex: .*
  - type: workload.googleapis.com/couchdb.file_descriptor.open
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/couchdb.httpd.bulk_requests
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/couchdb.httpd.requests
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: http_method
        value_regex: .*
  - type: workload.googleapis.com/couchdb.httpd.responses
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: http_status_code
        value_regex: .*
  - type: workload.googleapis.com/couchdb.httpd.views
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: view
        value_regex: .*
expected_logs:
  - log_name: couchdb
    fields:
      - name: jsonPayload.node
        value_regex: couchdb
        type: string
        description: Node instance name
      - name: jsonPayload.path
        value_regex: /forbidden
        type: string
        description: Request path
      - name: jsonPayload.remote_user
        value_regex: undefined
        type: string
        description: Authenticated username for the request
      - name: jsonPayload.status_message
        value_regex: ok
        type: string
        description: Status code message
      - name: jsonPayload.pid
        type: string
        description: Process ID
      - name: jsonPayload.message
        type: string
        description: Log message
      - name: jsonPayload.host
        type: string
        description: Host instance name
      - name: jsonPayload.level
        type: string
        description: Log entry level
        optional: true
      - name: httpRequest.serverIp
        value_regex: "localhost:5984"
        type: string
        description: "The server's IP and port that was requested"
        optional: true
      - name: httpRequest.remoteIp
        value_regex: "127.0.0.1"
        type: string
        description: "IP of the client that made the request"
        optional: true
      - name: httpRequest.requestMethod
        value_regex: GET
        type: string
        description: "HTTP method"
        optional: true
      - name: httpRequest.requestSize
        type: number
        description: "HTTP request size"
        optional: true
      - name: httpRequest.status
        type: number
        description: "HTTP status code"
        optional: true
      - name: httpRequest.responseSize
        type: string
        description: ''
        optional: true
      - name: httpRequest.userAgent
        type: string
        description: ''
        optional: true
      - name: severity
        type: string
        description: ''
configuration_options:
  logs:
    - type: couchdb
      fields:
        - name: type
          default: null
          description: This value must be `couchdb`.
        - name: include_paths
          default: '[/var/log/couchdb/couchdb.log]'
          description: A list of filesystem paths to read by tailing each file. A wild card (`*`) can be used in the paths; for example, `/var/log/couchdb*/*.log`.
        - name: exclude_paths
          default: null
          description: A list of filesystem path patterns to exclude from the set matched by `include_paths`.
        - name: record_log_file_path
          default: false
          description: If set to `true`, then the path to the specific file from which the log record was obtained appears in the output log entry as the value of the `agent.googleapis.com/log_file_path` label. When using a wildcard, only the path of the file from which the record was obtained is recorded.
        - name: wildcard_refresh_interval
          default: 60s
          description: The interval at which wildcard file paths in `include_paths` are refreshed. Given as a [time duration](https://pkg.go.dev/time#ParseDuration), for example `30s` or `2m`. This property might be useful under high logging throughputs where log files are rotated faster than the default interval.
  metrics:
    - type: couchdb
      fields:
        - name: type
          default: null
          description: This value must be `couchdb`.
        - name: server_status_url
          default: http://localhost:5984
          description: The URL exposed by CouchDB.
        - name: username
          default: null
          description: The username used to connect to the server.
        - name: password
          default: null
          description: The password used to connect to the server.
        - name: collection_interval
          default: 60s
          description: A [time duration](https://pkg.go.dev/time#ParseDuration) value, such as `30s` or `5m`.
