iota_proxy/
remote_write.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5#[allow(clippy::derive_partial_eq_without_eq)]
6#[derive(Clone, PartialEq, ::prost::Message)]
7pub struct MetricMetadata {
8    /// Represents the metric type, these match the set from Prometheus.
9    /// Refer to model/textparse/interface.go for details.
10    #[prost(enumeration = "metric_metadata::MetricType", tag = "1")]
11    pub r#type: i32,
12    #[prost(string, tag = "2")]
13    pub metric_family_name: ::prost::alloc::string::String,
14    #[prost(string, tag = "4")]
15    pub help: ::prost::alloc::string::String,
16    #[prost(string, tag = "5")]
17    pub unit: ::prost::alloc::string::String,
18}
19/// Nested message and enum types in `MetricMetadata`.
20pub mod metric_metadata {
21    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
22    #[repr(i32)]
23    pub enum MetricType {
24        Unknown = 0,
25        Counter = 1,
26        Gauge = 2,
27        Histogram = 3,
28        Gaugehistogram = 4,
29        Summary = 5,
30        Info = 6,
31        Stateset = 7,
32    }
33    impl MetricType {
34        /// String value of the enum field names used in the ProtoBuf
35        /// definition.
36        ///
37        /// The values are not transformed in any way and thus are considered
38        /// stable (if the ProtoBuf definition does not change) and safe
39        /// for programmatic use.
40        pub fn as_str_name(&self) -> &'static str {
41            match self {
42                MetricType::Unknown => "UNKNOWN",
43                MetricType::Counter => "COUNTER",
44                MetricType::Gauge => "GAUGE",
45                MetricType::Histogram => "HISTOGRAM",
46                MetricType::Gaugehistogram => "GAUGEHISTOGRAM",
47                MetricType::Summary => "SUMMARY",
48                MetricType::Info => "INFO",
49                MetricType::Stateset => "STATESET",
50            }
51        }
52        /// Creates an enum from field names used in the ProtoBuf definition.
53        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
54            match value {
55                "UNKNOWN" => Some(Self::Unknown),
56                "COUNTER" => Some(Self::Counter),
57                "GAUGE" => Some(Self::Gauge),
58                "HISTOGRAM" => Some(Self::Histogram),
59                "GAUGEHISTOGRAM" => Some(Self::Gaugehistogram),
60                "SUMMARY" => Some(Self::Summary),
61                "INFO" => Some(Self::Info),
62                "STATESET" => Some(Self::Stateset),
63                _ => None,
64            }
65        }
66    }
67}
68#[allow(clippy::derive_partial_eq_without_eq)]
69#[derive(Clone, PartialEq, ::prost::Message)]
70pub struct Sample {
71    #[prost(double, tag = "1")]
72    pub value: f64,
73    /// timestamp is in ms format, see model/timestamp/timestamp.go for
74    /// conversion from time.Time to Prometheus timestamp.
75    #[prost(int64, tag = "2")]
76    pub timestamp: i64,
77}
78#[allow(clippy::derive_partial_eq_without_eq)]
79#[derive(Clone, PartialEq, ::prost::Message)]
80pub struct Exemplar {
81    /// Optional, can be empty.
82    #[prost(message, repeated, tag = "1")]
83    pub labels: ::prost::alloc::vec::Vec<Label>,
84    #[prost(double, tag = "2")]
85    pub value: f64,
86    /// timestamp is in ms format, see model/timestamp/timestamp.go for
87    /// conversion from time.Time to Prometheus timestamp.
88    #[prost(int64, tag = "3")]
89    pub timestamp: i64,
90}
91/// A native histogram, also known as a sparse histogram.
92/// Original design doc:
93/// <https://docs.google.com/document/d/1cLNv3aufPZb3fNfaJgdaRBZsInZKKIHo9E6HinJVbpM/edit>
94/// The appendix of this design doc also explains the concept of float
95/// histograms. This Histogram message can represent both, the usual
96/// integer histogram as well as a float histogram.
97#[allow(clippy::derive_partial_eq_without_eq)]
98#[derive(Clone, PartialEq, ::prost::Message)]
99pub struct Histogram {
100    /// Sum of observations in the histogram.
101    #[prost(double, tag = "3")]
102    pub sum: f64,
103    /// The schema defines the bucket schema. Currently, valid numbers
104    /// are -4 <= n <= 8. They are all for base-2 bucket schemas, where 1
105    /// is a bucket boundary in each case, and then each power of two is
106    /// divided into 2^n logarithmic buckets. Or in other words, each
107    /// bucket boundary is the previous boundary times 2^(2^-n). In the
108    /// future, more bucket schemas may be added using numbers < -4 or >
109    /// 8.
110    #[prost(sint32, tag = "4")]
111    pub schema: i32,
112    /// Breadth of the zero bucket.
113    #[prost(double, tag = "5")]
114    pub zero_threshold: f64,
115    /// Negative Buckets.
116    #[prost(message, repeated, tag = "8")]
117    pub negative_spans: ::prost::alloc::vec::Vec<BucketSpan>,
118    /// Use either "negative_deltas" or "negative_counts", the former for
119    /// regular histograms with integer counts, the latter for float
120    /// histograms.
121    ///
122    /// Count delta of each bucket compared to previous one (or to zero for 1st
123    /// bucket).
124    #[prost(sint64, repeated, tag = "9")]
125    pub negative_deltas: ::prost::alloc::vec::Vec<i64>,
126    /// Absolute count of each bucket.
127    #[prost(double, repeated, tag = "10")]
128    pub negative_counts: ::prost::alloc::vec::Vec<f64>,
129    /// Positive Buckets.
130    #[prost(message, repeated, tag = "11")]
131    pub positive_spans: ::prost::alloc::vec::Vec<BucketSpan>,
132    /// Use either "positive_deltas" or "positive_counts", the former for
133    /// regular histograms with integer counts, the latter for float
134    /// histograms.
135    ///
136    /// Count delta of each bucket compared to previous one (or to zero for 1st
137    /// bucket).
138    #[prost(sint64, repeated, tag = "12")]
139    pub positive_deltas: ::prost::alloc::vec::Vec<i64>,
140    /// Absolute count of each bucket.
141    #[prost(double, repeated, tag = "13")]
142    pub positive_counts: ::prost::alloc::vec::Vec<f64>,
143    #[prost(enumeration = "histogram::ResetHint", tag = "14")]
144    pub reset_hint: i32,
145    /// timestamp is in ms format, see model/timestamp/timestamp.go for
146    /// conversion from time.Time to Prometheus timestamp.
147    #[prost(int64, tag = "15")]
148    pub timestamp: i64,
149    /// Count of observations in the histogram.
150    #[prost(oneof = "histogram::Count", tags = "1, 2")]
151    pub count: ::core::option::Option<histogram::Count>,
152    /// Count in zero bucket.
153    #[prost(oneof = "histogram::ZeroCount", tags = "6, 7")]
154    pub zero_count: ::core::option::Option<histogram::ZeroCount>,
155}
156/// Nested message and enum types in `Histogram`.
157pub mod histogram {
158    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
159    #[repr(i32)]
160    pub enum ResetHint {
161        /// Need to test for a counter reset explicitly.
162        Unknown = 0,
163        /// This is the 1st histogram after a counter reset.
164        Yes = 1,
165        /// There was no counter reset between this and the previous Histogram.
166        No = 2,
167        /// This is a gauge histogram where counter resets don't happen.
168        Gauge = 3,
169    }
170    impl ResetHint {
171        /// String value of the enum field names used in the ProtoBuf
172        /// definition.
173        ///
174        /// The values are not transformed in any way and thus are considered
175        /// stable (if the ProtoBuf definition does not change) and safe
176        /// for programmatic use.
177        pub fn as_str_name(&self) -> &'static str {
178            match self {
179                ResetHint::Unknown => "UNKNOWN",
180                ResetHint::Yes => "YES",
181                ResetHint::No => "NO",
182                ResetHint::Gauge => "GAUGE",
183            }
184        }
185        /// Creates an enum from field names used in the ProtoBuf definition.
186        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
187            match value {
188                "UNKNOWN" => Some(Self::Unknown),
189                "YES" => Some(Self::Yes),
190                "NO" => Some(Self::No),
191                "GAUGE" => Some(Self::Gauge),
192                _ => None,
193            }
194        }
195    }
196    /// Count of observations in the histogram.
197    #[allow(clippy::derive_partial_eq_without_eq)]
198    #[derive(Clone, PartialEq, ::prost::Oneof)]
199    pub enum Count {
200        #[prost(uint64, tag = "1")]
201        CountInt(u64),
202        #[prost(double, tag = "2")]
203        CountFloat(f64),
204    }
205    /// Count in zero bucket.
206    #[allow(clippy::derive_partial_eq_without_eq)]
207    #[derive(Clone, PartialEq, ::prost::Oneof)]
208    pub enum ZeroCount {
209        #[prost(uint64, tag = "6")]
210        ZeroCountInt(u64),
211        #[prost(double, tag = "7")]
212        ZeroCountFloat(f64),
213    }
214}
215/// A BucketSpan defines a number of consecutive buckets with their
216/// offset. Logically, it would be more straightforward to include the
217/// bucket counts in the Span. However, the protobuf representation is
218/// more compact in the way the data is structured here (with all the
219/// buckets in a single array separate from the Spans).
220#[allow(clippy::derive_partial_eq_without_eq)]
221#[derive(Clone, PartialEq, ::prost::Message)]
222pub struct BucketSpan {
223    /// Gap to previous span, or starting point for 1st span (which can be
224    /// negative).
225    #[prost(sint32, tag = "1")]
226    pub offset: i32,
227    /// Length of consecutive buckets.
228    #[prost(uint32, tag = "2")]
229    pub length: u32,
230}
231/// TimeSeries represents samples and labels for a single time series.
232#[allow(clippy::derive_partial_eq_without_eq)]
233#[derive(Clone, PartialEq, ::prost::Message)]
234pub struct TimeSeries {
235    /// For a timeseries to be valid, and for the samples and exemplars
236    /// to be ingested by the remote system properly, the labels field is
237    /// required.
238    #[prost(message, repeated, tag = "1")]
239    pub labels: ::prost::alloc::vec::Vec<Label>,
240    #[prost(message, repeated, tag = "2")]
241    pub samples: ::prost::alloc::vec::Vec<Sample>,
242    #[prost(message, repeated, tag = "3")]
243    pub exemplars: ::prost::alloc::vec::Vec<Exemplar>,
244    #[prost(message, repeated, tag = "4")]
245    pub histograms: ::prost::alloc::vec::Vec<Histogram>,
246}
247#[allow(clippy::derive_partial_eq_without_eq)]
248#[derive(Clone, PartialEq, ::prost::Message)]
249pub struct Label {
250    #[prost(string, tag = "1")]
251    pub name: ::prost::alloc::string::String,
252    #[prost(string, tag = "2")]
253    pub value: ::prost::alloc::string::String,
254}
255#[allow(clippy::derive_partial_eq_without_eq)]
256#[derive(Clone, PartialEq, ::prost::Message)]
257pub struct Labels {
258    #[prost(message, repeated, tag = "1")]
259    pub labels: ::prost::alloc::vec::Vec<Label>,
260}
261/// Matcher specifies a rule, which can match or set of labels or not.
262#[allow(clippy::derive_partial_eq_without_eq)]
263#[derive(Clone, PartialEq, ::prost::Message)]
264pub struct LabelMatcher {
265    #[prost(enumeration = "label_matcher::Type", tag = "1")]
266    pub r#type: i32,
267    #[prost(string, tag = "2")]
268    pub name: ::prost::alloc::string::String,
269    #[prost(string, tag = "3")]
270    pub value: ::prost::alloc::string::String,
271}
272/// Nested message and enum types in `LabelMatcher`.
273pub mod label_matcher {
274    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
275    #[repr(i32)]
276    pub enum Type {
277        Eq = 0,
278        Neq = 1,
279        Re = 2,
280        Nre = 3,
281    }
282    impl Type {
283        /// String value of the enum field names used in the ProtoBuf
284        /// definition.
285        ///
286        /// The values are not transformed in any way and thus are considered
287        /// stable (if the ProtoBuf definition does not change) and safe
288        /// for programmatic use.
289        pub fn as_str_name(&self) -> &'static str {
290            match self {
291                Type::Eq => "EQ",
292                Type::Neq => "NEQ",
293                Type::Re => "RE",
294                Type::Nre => "NRE",
295            }
296        }
297        /// Creates an enum from field names used in the ProtoBuf definition.
298        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
299            match value {
300                "EQ" => Some(Self::Eq),
301                "NEQ" => Some(Self::Neq),
302                "RE" => Some(Self::Re),
303                "NRE" => Some(Self::Nre),
304                _ => None,
305            }
306        }
307    }
308}
309#[allow(clippy::derive_partial_eq_without_eq)]
310#[derive(Clone, PartialEq, ::prost::Message)]
311pub struct ReadHints {
312    /// Query step size in milliseconds.
313    #[prost(int64, tag = "1")]
314    pub step_ms: i64,
315    /// String representation of surrounding function or aggregation.
316    #[prost(string, tag = "2")]
317    pub func: ::prost::alloc::string::String,
318    /// Start time in milliseconds.
319    #[prost(int64, tag = "3")]
320    pub start_ms: i64,
321    /// End time in milliseconds.
322    #[prost(int64, tag = "4")]
323    pub end_ms: i64,
324    /// List of label names used in aggregation.
325    #[prost(string, repeated, tag = "5")]
326    pub grouping: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
327    /// Indicate whether it is without or by.
328    #[prost(bool, tag = "6")]
329    pub by: bool,
330    /// Range vector selector range in milliseconds.
331    #[prost(int64, tag = "7")]
332    pub range_ms: i64,
333}
334/// Chunk represents a TSDB chunk.
335/// Time range [min, max] is inclusive.
336#[allow(clippy::derive_partial_eq_without_eq)]
337#[derive(Clone, PartialEq, ::prost::Message)]
338pub struct Chunk {
339    #[prost(int64, tag = "1")]
340    pub min_time_ms: i64,
341    #[prost(int64, tag = "2")]
342    pub max_time_ms: i64,
343    #[prost(enumeration = "chunk::Encoding", tag = "3")]
344    pub r#type: i32,
345    #[prost(bytes = "vec", tag = "4")]
346    pub data: ::prost::alloc::vec::Vec<u8>,
347}
348/// Nested message and enum types in `Chunk`.
349pub mod chunk {
350    /// We require this to match chunkenc.Encoding.
351    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
352    #[repr(i32)]
353    pub enum Encoding {
354        Unknown = 0,
355        Xor = 1,
356        Histogram = 2,
357    }
358    impl Encoding {
359        /// String value of the enum field names used in the ProtoBuf
360        /// definition.
361        ///
362        /// The values are not transformed in any way and thus are considered
363        /// stable (if the ProtoBuf definition does not change) and safe
364        /// for programmatic use.
365        pub fn as_str_name(&self) -> &'static str {
366            match self {
367                Encoding::Unknown => "UNKNOWN",
368                Encoding::Xor => "XOR",
369                Encoding::Histogram => "HISTOGRAM",
370            }
371        }
372        /// Creates an enum from field names used in the ProtoBuf definition.
373        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
374            match value {
375                "UNKNOWN" => Some(Self::Unknown),
376                "XOR" => Some(Self::Xor),
377                "HISTOGRAM" => Some(Self::Histogram),
378                _ => None,
379            }
380        }
381    }
382}
383/// ChunkedSeries represents single, encoded time series.
384#[allow(clippy::derive_partial_eq_without_eq)]
385#[derive(Clone, PartialEq, ::prost::Message)]
386pub struct ChunkedSeries {
387    /// Labels should be sorted.
388    #[prost(message, repeated, tag = "1")]
389    pub labels: ::prost::alloc::vec::Vec<Label>,
390    /// Chunks will be in start time order and may overlap.
391    #[prost(message, repeated, tag = "2")]
392    pub chunks: ::prost::alloc::vec::Vec<Chunk>,
393}
394#[allow(clippy::derive_partial_eq_without_eq)]
395#[derive(Clone, PartialEq, ::prost::Message)]
396pub struct WriteRequest {
397    #[prost(message, repeated, tag = "1")]
398    pub timeseries: ::prost::alloc::vec::Vec<TimeSeries>,
399    #[prost(message, repeated, tag = "3")]
400    pub metadata: ::prost::alloc::vec::Vec<MetricMetadata>,
401}
402/// ReadRequest represents a remote read request.
403#[allow(clippy::derive_partial_eq_without_eq)]
404#[derive(Clone, PartialEq, ::prost::Message)]
405pub struct ReadRequest {
406    #[prost(message, repeated, tag = "1")]
407    pub queries: ::prost::alloc::vec::Vec<Query>,
408    /// accepted_response_types allows negotiating the content type of the
409    /// response.
410    ///
411    /// Response types are taken from the list in the FIFO order. If no response
412    /// type in `accepted_response_types` is implemented by server, error is
413    /// returned. For request that do not contain `accepted_response_types`
414    /// field the SAMPLES response type will be used.
415    #[prost(enumeration = "read_request::ResponseType", repeated, tag = "2")]
416    pub accepted_response_types: ::prost::alloc::vec::Vec<i32>,
417}
418/// Nested message and enum types in `ReadRequest`.
419pub mod read_request {
420    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
421    #[repr(i32)]
422    pub enum ResponseType {
423        /// Server will return a single ReadResponse message with matched series
424        /// that includes list of raw samples. It's recommended to use
425        /// streamed response types instead.
426        ///
427        /// Response headers:
428        /// Content-Type: "application/x-protobuf"
429        /// Content-Encoding: "snappy"
430        Samples = 0,
431        /// Server will stream a delimited ChunkedReadResponse message that
432        /// contains XOR or HISTOGRAM(!) encoded chunks for a single series.
433        /// Each message is following varint size and fixed size bigendian
434        /// uint32 for CRC32 Castagnoli checksum.
435        ///
436        /// Response headers:
437        /// Content-Type: "application/x-streamed-protobuf;
438        /// proto=prometheus.ChunkedReadResponse" Content-Encoding: ""
439        StreamedXorChunks = 1,
440    }
441    impl ResponseType {
442        /// String value of the enum field names used in the ProtoBuf
443        /// definition.
444        ///
445        /// The values are not transformed in any way and thus are considered
446        /// stable (if the ProtoBuf definition does not change) and safe
447        /// for programmatic use.
448        pub fn as_str_name(&self) -> &'static str {
449            match self {
450                ResponseType::Samples => "SAMPLES",
451                ResponseType::StreamedXorChunks => "STREAMED_XOR_CHUNKS",
452            }
453        }
454        /// Creates an enum from field names used in the ProtoBuf definition.
455        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
456            match value {
457                "SAMPLES" => Some(Self::Samples),
458                "STREAMED_XOR_CHUNKS" => Some(Self::StreamedXorChunks),
459                _ => None,
460            }
461        }
462    }
463}
464/// ReadResponse is a response when response_type equals SAMPLES.
465#[allow(clippy::derive_partial_eq_without_eq)]
466#[derive(Clone, PartialEq, ::prost::Message)]
467pub struct ReadResponse {
468    /// In same order as the request's queries.
469    #[prost(message, repeated, tag = "1")]
470    pub results: ::prost::alloc::vec::Vec<QueryResult>,
471}
472#[allow(clippy::derive_partial_eq_without_eq)]
473#[derive(Clone, PartialEq, ::prost::Message)]
474pub struct Query {
475    #[prost(int64, tag = "1")]
476    pub start_timestamp_ms: i64,
477    #[prost(int64, tag = "2")]
478    pub end_timestamp_ms: i64,
479    #[prost(message, repeated, tag = "3")]
480    pub matchers: ::prost::alloc::vec::Vec<LabelMatcher>,
481    #[prost(message, optional, tag = "4")]
482    pub hints: ::core::option::Option<ReadHints>,
483}
484#[allow(clippy::derive_partial_eq_without_eq)]
485#[derive(Clone, PartialEq, ::prost::Message)]
486pub struct QueryResult {
487    /// Samples within a time series must be ordered by time.
488    #[prost(message, repeated, tag = "1")]
489    pub timeseries: ::prost::alloc::vec::Vec<TimeSeries>,
490}
491/// ChunkedReadResponse is a response when response_type equals
492/// STREAMED_XOR_CHUNKS. We strictly stream full series after series, optionally
493/// split by time. This means that a single frame can contain partition of the
494/// single series, but once a new series is started to be streamed it means that
495/// no more chunks will be sent for previous one. Series are returned sorted in
496/// the same way TSDB block are internally.
497#[allow(clippy::derive_partial_eq_without_eq)]
498#[derive(Clone, PartialEq, ::prost::Message)]
499pub struct ChunkedReadResponse {
500    #[prost(message, repeated, tag = "1")]
501    pub chunked_series: ::prost::alloc::vec::Vec<ChunkedSeries>,
502    /// query_index represents an index of the query from ReadRequest.queries
503    /// these chunks relates to.
504    #[prost(int64, tag = "2")]
505    pub query_index: i64,
506}