// Copyright 2017 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: StatsD
// $overview: Adapter to deliver metrics to a StatsD backend
// $location: https://istio.io/docs/reference/config/adapters/statsd.html

// The `statsd` adapter enables Istio to deliver metric data to a
// [StatsD](https://github.com/etsy/statsd) monitoring backend.
package adapter.statsd.config;

import "google/protobuf/duration.proto";
import "gogoproto/gogo.proto";

option go_package = "config";
option (gogoproto.goproto_getters_all) = false;
option (gogoproto.equal_all) = false;
option (gogoproto.gostring_all) = false;

// Configuration format for the `statsd` adapter.
message Params {
    // Address of the statsd server, e.g. localhost:8125
    string address = 1;

    // Metric prefix, do not specify for no prefix
    string prefix = 2;

    // FlushDuration controls the maximum amount of time between sending metrics to the statsd collection server.
    // Metrics are reported when either flush_bytes is full or flush_duration time has elapsed since the last report.
    google.protobuf.Duration flush_duration = 3 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true];

    // Maximum UDP packet size to send; if not specified defaults to 512 bytes. If the statsd server is running on the
    // same (private) network 1432 bytes is recommended for better performance.
    int32 flush_bytes = 4;

    // Chance that any particular metric is sampled when incremented; can take the range [0, 1], defaults to 1 if unspecified.
    float sampling_rate = 5;

    // Describes how to represent this metric in statsd
    message MetricInfo {
        // The type of metric.
        enum Type {
            UNKNOWN = 0;
            COUNTER = 1;
            GAUGE = 2;
            DISTRIBUTION = 3;
        }
        Type type = 1;

        // The template will be filled with values from the metric's labels and the resulting string will be used as
        // the statsd metric name. This allows easier creation of statsd metrics like `action_name-response_code`.
        // The template strings must conform to go's text/template syntax. For the example of `action_name-response_code`,
        // we use the template:
        //    `{{.apiMethod}}-{{.responseCode}}`
        //
        // If name_template is the empty string the Istio metric name will be used for statsd metric's name.
        string name_template = 2;
    }

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