github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ts/tspb/timeseries.proto (about) 1 // Copyright 2015 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 syntax = "proto2"; 12 package cockroach.ts.tspb; 13 option go_package = "tspb"; 14 15 import "gogoproto/gogo.proto"; 16 import "google/api/annotations.proto"; 17 18 // TimeSeriesDatapoint is a single point of time series data; a value associated 19 // with a timestamp. 20 message TimeSeriesDatapoint { 21 // The timestamp when this datapoint is located, expressed in nanoseconds 22 // since the unix epoch. 23 optional int64 timestamp_nanos = 1 [(gogoproto.nullable) = false]; 24 // A floating point representation of the value of this datapoint. 25 optional double value = 2 [(gogoproto.nullable) = false]; 26 } 27 28 // TimeSeriesData is a set of measurements of a single named variable at 29 // multiple points in time. This message contains a name and a source which, in 30 // combination, uniquely identify the time series being measured. Measurement 31 // data is represented as a repeated set of TimeSeriesDatapoint messages. 32 message TimeSeriesData { 33 // A string which uniquely identifies the variable from which this data was 34 // measured. 35 optional string name = 1 [(gogoproto.nullable) = false]; 36 // A string which identifies the unique source from which the variable was measured. 37 optional string source = 2 [(gogoproto.nullable) = false]; 38 // Datapoints representing one or more measurements taken from the variable. 39 repeated TimeSeriesDatapoint datapoints = 3 [(gogoproto.nullable) = false]; 40 } 41 42 // TimeSeriesQueryAggregator describes a set of aggregation functions which can 43 // be used to combine multiple datapoints into a single datapoint. 44 // 45 // Aggregators are used to "downsample" series by combining datapoints from the 46 // same series at different times. They are also used to "aggregate" values from 47 // different series, combining data points from different series at the same 48 // time. 49 enum TimeSeriesQueryAggregator { 50 // AVG returns the average value of datapoints. 51 AVG = 1; 52 // SUM returns the sum value of datapoints. 53 SUM = 2; 54 // MAX returns the maximum value of datapoints. 55 MAX = 3; 56 // MIN returns the minimum value of datapoints. 57 MIN = 4; 58 // FIRST returns the value of the first datapoint in the set being aggregated. 59 // This aggregator is not valid for a source aggregator, and should only be 60 // used for downsampling. 61 FIRST = 5; 62 // LAST returns the value of the last datapoint in the set being aggregated. 63 // This aggregator is not valid for a source aggregator, and should only be 64 // used for downsampling. 65 LAST = 6; 66 // VARIANCE returns the variance (σ^2) of the datapoints. 67 VARIANCE = 7; 68 } 69 70 // TimeSeriesQueryDerivative describes a derivative function used to convert 71 // returned datapoints into a rate-of-change. 72 enum TimeSeriesQueryDerivative { 73 // NONE is the default value, and does not apply a derivative function. 74 NONE = 0; 75 // DERIVATIVE returns the first-order derivative of values in the time series. 76 DERIVATIVE = 1; 77 // NON_NEGATIVE_DERIVATIVE returns only non-negative values of the first-order 78 // derivative; negative values are returned as zero. This should be used for 79 // counters that monotonically increase, but might wrap or reset. 80 NON_NEGATIVE_DERIVATIVE = 2; 81 } 82 83 // Each Query defines a specific metric to query over the time span of 84 // this request. 85 message Query { 86 option (gogoproto.goproto_getters) = true; 87 88 // The name of the time series to query. 89 optional string name = 1 [(gogoproto.nullable) = false]; 90 // A downsampling aggregation function to apply to datapoints within the 91 // same sample period. 92 optional TimeSeriesQueryAggregator downsampler = 2 [default = AVG]; 93 // An aggregation function used to combine timelike datapoints from the 94 // different sources being queried. 95 optional TimeSeriesQueryAggregator source_aggregator = 3 [default = SUM]; 96 // If set to a value other than 'NONE', query will return a derivative 97 // (rate of change) of the aggregated datapoints. 98 optional TimeSeriesQueryDerivative derivative = 4 [default = NONE]; 99 // An optional list of sources to restrict the time series query. If no 100 // sources are provided, all available sources will be queried. 101 repeated string sources = 5; 102 } 103 104 // TimeSeriesQueryRequest is the standard incoming time series query request 105 // accepted from cockroach clients. 106 message TimeSeriesQueryRequest { 107 // A timestamp in nanoseconds which defines the early bound of the time span 108 // for this query. 109 optional int64 start_nanos = 1 [(gogoproto.nullable) = false]; 110 // A timestamp in nanoseconds which defines the late bound of the time span 111 // for this query. Must be greater than start_nanos. 112 optional int64 end_nanos = 2 [(gogoproto.nullable) = false]; 113 // A set of Queries for this request. A request must have at least one 114 // Query. 115 repeated Query queries = 3 [(gogoproto.nullable) = false]; 116 // Duration of requested sample period in nanoseconds. Returned data for each 117 // query will be downsampled into periods of the supplied length. The 118 // supplied duration must be a multiple of ten seconds. 119 optional int64 sample_nanos = 4 [(gogoproto.nullable) = false]; 120 } 121 122 // TimeSeriesQueryResponse is the standard response for time series queries 123 // returned to cockroach clients. 124 message TimeSeriesQueryResponse { 125 // Result is the data returned from a single metric query over a time span. 126 message Result { 127 optional Query query = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true]; 128 repeated TimeSeriesDatapoint datapoints = 2 [(gogoproto.nullable) = false]; 129 } 130 131 // A set of Results; there will be one result for each Query in the matching 132 // TimeSeriesQueryRequest, in the same order. A Result will be present for 133 // each Query even if there are zero datapoints to return. 134 repeated Result results = 1 [(gogoproto.nullable) = false]; 135 } 136 137 message DumpRequest {} 138 139 // TimeSeries is the gRPC API for the time series server. Through grpc-gateway, 140 // we offer REST-style HTTP endpoints that locally proxy to the gRPC endpoints. 141 service TimeSeries { 142 // URL: /ts/query 143 rpc Query(TimeSeriesQueryRequest) returns (TimeSeriesQueryResponse) { 144 option (google.api.http) = { 145 post: "/ts/query" 146 body: "*" 147 }; 148 } 149 150 // Dump returns a stream of raw timeseries data that has been stored on the 151 // server. Only data from the 10-second resolution is returned - rollup data is 152 // not returned. Data is returned in the order it is read from disk, meaning 153 // that data from different series may be interleaved. 154 rpc Dump(DumpRequest) returns (stream TimeSeriesData) {} 155 }