package virtdb.interface.pb;

message MonitoringRequest {
  enum RequestType {
    REPORT_STATS       = 2;
    SET_STATE          = 3;
    COMPONENT_ERROR    = 4;
    REQUEST_ERROR      = 5;
    GET_STATES         = 6;
  }
  message NamedStat {
    required   string   Name   = 1;
    required   double   Stat   = 2;
  }
  message ReportStats {
    required   string      Name    = 1;
    repeated   NamedStat   Stats   = 2;
  }
  message SetState {
    enum Types {
      NOT_INITIALIZED   = 1;
      COMPONENT_ERROR   = 2;
      CLEAR             = 3;
    }
    required   string   Name   = 1;
    required   Types    Type   = 2;
    optional   string   Msg    = 3;
  }
  message ComponentError {
    enum Types {
      DOWN              = 1;  // by EndpointService
      TIMED_OUT         = 2;  // by Components
      UPSTREAM_ERROR    = 3;  //   -||-
      CLEAR             = 4;  //   -||-
    }
    required   string   ReportedBy     = 1;
    required   string   ImpactedPeer   = 2;
    required   Types    Type           = 3;
    optional   string   Message        = 4;
  }
  message RequestError {
    enum Types {
      INVALID_REQUEST    = 1;
      UPSTREAM_ERROR     = 2;
      UPSTREAM_TIMEOUT   = 3;
      RESOURCE_LIMIT     = 4;
    }
    required   string   ReportedBy     = 1;
    required   string   ImpactedPeer   = 2;
    required   Types    Type           = 3;
    optional   string   RequestId      = 4;
    optional   string   Table          = 5;
    optional   string   Schema         = 6;
    optional   string   Message        = 7;
  }
  message GetStates {
    optional   string   Name   = 1;
  }
  required   RequestType      Type      = 1;
  optional   ReportStats      RepStats  = 2;
  optional   SetState         SetSt     = 3;
  optional   ComponentError   CompErr   = 4;
  optional   RequestError     ReqErr    = 5;
  optional   GetStates        GetSts    = 6;
}

message MonitoringReply {
  enum ReplyType {
    REPORT_STATS       = 2;
    SET_STATE          = 3;
    COMPONENT_ERROR    = 4;
    REQUEST_ERROR      = 5;
    GET_STATES         = 6;
    ERROR_MSG          = 14;
  }
  message Event {
    required   uint64              Epoch    = 1;
    required   MonitoringRequest   Request  = 2;
  }
  message Status {
    required   string   Name           = 1;
    required   bool     OK             = 2;
    required   uint64   UpdatedEpoch   = 3;
    repeated   Event    Events         = 4;
  }
  message GetStates {
    repeated   Status   States   = 1;
  }
  message Error {
    required   string   Msg   = 1;
  }
  required   ReplyType   Type     = 1;
  optional   GetStates   States   = 6;
  optional   Error       Err      = 14;
}

