// Copyright 2018 Istio 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
//
//     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.

syntax = "proto3";

// $title: Datadog
// $description: Adapter to deliver metrics to a dogstatsd agent for delivery to DataDog.
// $location: https://istio.io/docs/reference/config/policy-and-telemetry/adapters/datadog.html
// $supported_templates: metric
// $aliases:
// $  - /docs/reference/config/adapters/datadog.html

// The `dogstatsd` adapter is designed to deliver Istio metric instances to a
// listening [DataDog](https://www.datadoghq.com/) agent.
//
// This adapter supports the [metric template](https://istio.io/docs/reference/config/policy-and-telemetry/templates/metric/).
package adapter.dogstatsd.config;

import "gogoproto/gogo.proto";

option go_package="config";

// Configuration parameter for the DataDog adapter. These params control how Mixer telemetry is transformed and sent to a dogstatsd agent.
//
// The adapter assumes that a dogstatsd agent is running as a sidecar or at some other endpoint that the Mixer can reach.
// Any dimension that is a part of the metric is converted to a tag automatically. The configuration of the DataDog agent/daemon is outside the scope of the adapter.
message Params {
    // Address of the dogstatsd server.
    // Default: localhost:8125
    string address = 1;

    // Prefix to prepend to all metrics handled by the adapter. Metric "bar" with prefix "foo." becomes "foo.bar" in DataDog. In order to make sure the metrics get populated into Datadog properly and avoid any billing issues, it's important to leave the metric prefix to its default value of 'istio.'
    // Default: "istio."
    string prefix = 2;

    // Number of individual metrics to buffer before flushing metrics to the network. When buffered, metrics are flushed every 100ms or when the buffer is filled.
    // When buffer is 0, metrics are not buffered.
    // Default: 0
    int32 buffer_length = 3;

    // Tags to add to every metric. "global": "tag" becomes "global:tag" in DataDog
    // Default: []
    map<string, string> global_tags = 4;

    // Chance that any particular metric is sampled when emitted; can take the range [0, 1].
    // Default: 1
    double sample_rate = 5;

    // Describes how to represent this metric in DataDog
    message MetricInfo {
        // Name of the metric in DataDog
        string name = 1;
        // Describes the type of metric
        enum Type {
            // Default Unknown Type
            UNKNOWN_TYPE = 0;
            // Increments a DataDog counter
            COUNTER = 1;
            // Sets the new value of a DataDog gauge
            GAUGE = 2;
            // DISTRIBUTION is converted to a Timing Histogram for metrics with a time unit and a Histogram for all other units
            DISTRIBUTION = 3;
        }
        // The type of metric
        Type type = 2;
        // Tags to add to the metric in addition to the dimensions. "tag": "val" becomes "tag:val" in DataDog
        // Default: []
        map<string, string> tags = 3;
    }

    // Map of a specific metric instance name -> info. If a metric's instance name is not in the map then the metric will not be exported to DataDog.
    map<string, MetricInfo> metrics = 6;
}
