syntax = "proto3";

package plucky;
option go_package = "code.justin.tv/live/plucky/rpc";

import "google/protobuf/timestamp.proto";

service Plucky {
    // GetItems fetches the items that happened by service. Each item includes the trend
    // of occurrences and the most recent occurrence.
    rpc GetItems(GetItemsRequest) returns (GetItemsResponse);

    // GetOccurrences fetches an item by service and fingerprint. The response contains the occurrences of that
    // item within the last 24 hours and trends of the occurrences.
    rpc GetOccurrences(GetOccurrencesRequest) returns (GetOccurrencesResponse);

    // GetConfig returns the services that the server currently supports.
    rpc GetConfig(GetConfigRequest) returns (GetConfigResponse);
}

message GetItemsRequest {
    string service_id = 1;
    string stage_id = 2;
    google.protobuf.Timestamp start = 3;
    google.protobuf.Timestamp end = 4;

    // If true, skip querying CloudWatch logs if the cache contains at least partial data for the entire
    // query time range.
    bool skip_partial_data_refetch = 5;

    int32 max_trend_points = 6;
}

message GetItemsResponse {
    repeated Item items = 1;
    google.protobuf.Timestamp fetched = 2;
    google.protobuf.Timestamp start = 3;
    google.protobuf.Timestamp end = 4;
    int32 query_time_ms = 5;
}

message Item {
    string fingerprint = 1;
    Trend trend = 2;
    Occurrence last_occurrence = 3;
    int32 num_occurrences = 4;
}

message Trend {
    repeated TrendPoint points = 1;
    int32 bucket_size = 2;
}

message TrendPoint {
    google.protobuf.Timestamp start = 1;
    int32 count = 2;
}

message GetOccurrencesRequest {
    string service_id = 1;
    string stage_id = 2;
    string fingerprint = 3;
    google.protobuf.Timestamp start = 4;
    google.protobuf.Timestamp end = 5;
    // If true, skip querying CloudWatch logs if the cache contains at least partial data for the entire
    // query time range.
    bool skip_partial_data_refetch = 6;
}

message GetOccurrencesResponse {
    string fingerprint = 1;
    repeated Occurrence occurrence = 2;
    Trend trend_day = 3;
    int32 query_time_ms = 4;
}

message Occurrence {
    // Required
    string occurrence_id = 1;
    string service = 2;
    string fingerprint = 3;
    google.protobuf.Timestamp timestamp = 4;
    string level = 5;
    string message = 6;
    string raw_json = 7;
    
    // Optional
    repeated StackTrace stack_trace = 8;
    string request_id = 9;
    // Optional - from telemetry
    string operation = 10;
    string dependency = 11;
}

message StackTrace {
    string full_file_path = 1;
    int32 line = 2;
    string method = 3;

    // Starts from the Brazil package name
    string short_file_path = 4;
    string brazil_pkg_name = 5;
    // True if this file is part of the service's package
    bool relevant = 6;
    string line_url = 7;
    string pkg_url = 8;
}

message GetConfigRequest {}

message GetConfigResponse {
    repeated Service services = 1;
    string version = 2;
    string git_commit = 3;
}

message Service {
    string service_id = 1;
    string stage_id = 2;
    string url_slug = 3;
    string display_name = 4;
    string display_stage = 5;
}

