/**
 * Copyright (c) KMG. All Rights Reserved.
 *
 * 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
 */

/*
 * SBP : Storage Benchmark Protocol
 * This protocol used between SBM an SBK to consolidate the Performance benchmarking results from multiple SBKs to
 * single SBM.
 */

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.sbp.grpc";
option java_outer_classname = "SbpGrpc";

import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";

service Service {
  rpc getVersion (google.protobuf.Empty) returns (Version) {}
  rpc isVersionSupported (Version) returns (google.protobuf.BoolValue) {}
  rpc getConfig (google.protobuf.Empty) returns (Config) {}
  rpc registerClient (Config) returns (ClientID) {}
  rpc streamLatencies (stream MessageLatenciesRecord) returns (google.protobuf.Empty) {}
  rpc closeClient (ClientID) returns (google.protobuf.Empty) {}
}

enum EnumTimeUnit {
  ms = 0;
  mcs = 1;
  ns = 2;
}

enum EnumAction {
  Writing = 0;
  Reading = 1;
  Write_Reading = 2;
  Write_OnlyReading = 3;
  Read_Writing = 4;
  Read_OnlyWriting = 5;
}

message Version {
  int32 major = 1;
  int32 minor = 2;
}

message Config {
  string storageName = 1;
  EnumAction action = 2;
  EnumTimeUnit timeUnit = 3;
  int64 minLatency = 4;
  int64 maxLatency = 5;
  bool isWriteRequests = 6;
  bool isReadRequests = 7;
  int64 maxRecordSizeBytes = 8;
}

message ClientID {
  int64 id = 1;
}


message MessageLatenciesRecord {
  int64 clientID = 1;
  int64 sequenceNumber = 2;
  int32 writers = 3;
  int32 readers = 4;
  int32 maxWriters = 5;
  int32 maxReaders = 6;
  int64 writeRequestBytes = 7;
  int64 writeRequestRecords = 8;
  int64 readRequestBytes = 9;
  int64 readRequestRecords = 10;
  int64 writeTimeoutEvents = 11;
  int64 readTimeoutEvents = 12;
  int64 totalRecords = 13;
  int64 validLatencyRecords = 14;
  int64 lowerLatencyDiscardRecords = 15;
  int64 higherLatencyDiscardRecords = 16;
  int64 invalidLatencyRecords = 17;
  int64 totalBytes = 18;
  int64 totalLatency = 19;
  int64 minLatency = 20;
  int64 maxLatency = 21;
  reserved 22;
  repeated uint64 latencyValues = 23 [packed = true];
  repeated uint64 latencyCounts = 24 [packed = true];
}
