/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * license agreements; and to You under the Apache License, version 2.0:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * This file is part of the Apache Pekko project, which was derived from Akka.
 */

/*
 * Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
 */

syntax = "proto2";

option java_package = "org.apache.pekko.cluster.metrics.protobuf.msg";
option optimize_for = SPEED;

/****************************************
 * Metrics Gossip Messages
 ****************************************/

/**
 * Metrics Gossip Envelope
 */
message MetricsGossipEnvelope {
  required Address from = 1;
  required MetricsGossip gossip = 2;
  required bool reply = 3;
}

/**
 * Metrics Gossip
 */
message MetricsGossip {
  repeated Address allAddresses = 1;
  repeated string allMetricNames = 2;
  repeated NodeMetrics nodeMetrics = 3;
}

/**
 * Node Metrics
 */
message NodeMetrics {
  enum NumberType {
    Serialized = 0;
    Double = 1;
    Float = 2;
    Integer = 3;
    Long = 4;
  }
  message Number {
    required NumberType type = 1;
    optional uint32 value32 = 2;
    optional uint64 value64 = 3;
    optional bytes serialized = 4;
  }
  message EWMA {
    required double value = 1;
    required double alpha = 2;
  }
  message Metric {
    required int32 nameIndex = 1;
    required Number number = 2;
    optional EWMA ewma = 3;
  }
  required int32 addressIndex = 1;
  required int64 timestamp = 2;
  repeated Metric metrics = 3;
}

/****************************************
 * Common Datatypes and Messages
 ****************************************/

/**
 * Defines a remote address.
 */
message Address {
  required string system = 1;
  required string hostname = 2;
  required uint32 port = 3;
  optional string protocol = 4;
}

/****************************************
 * Router pool (for remote deployment
 ****************************************/

message AdaptiveLoadBalancingPool {
  // omitted if default
  optional MetricsSelector metricsSelector = 1;
  required uint32 nrOfInstances = 2;
  // omitted if default
  optional string routerDispatcher = 3;
  required bool usePoolDispatcher = 4;
}


// couldn't figure out how to import Payload
message MetricsSelector {
  required uint32 serializerId = 1;
  required string manifest = 2;
  required bytes data = 3;
}

message MixMetricsSelector {
  repeated MetricsSelector selectors = 1;
}