summaryrefslogtreecommitdiffstats
path: root/src/api.rs
blob: 2e41aaee96347f7b4fb86d2bbd90c13a950bdb0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// This file was copied from:
// https://raw.githubusercontent.com/nickbabcock/rrinlog/master/rrinlog-server/src/api.rs
// on the 10th December 2017


use chrono::prelude::*;
use serde_json;

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)]
pub struct Range {
    pub from: DateTime<Utc>,
    pub to: DateTime<Utc>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Target {
    pub target: String,
    #[serde(rename = "refId")] pub ref_id: String,
    #[serde(rename = "type")] pub _type: String,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Query {
    pub range: Range,
    #[serde(rename = "intervalMs")] pub interval_ms: i32,
    #[serde(rename = "maxDataPoints")] pub max_data_points: i32,
    pub format: Option<String>,
    pub targets: Vec<Target>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(untagged)]
pub enum TargetData {
    Series(Series),
    Table(Table),
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Series {
    pub target: String,
    pub datapoints: Vec<[f64; 2]>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Column {
    pub text: String,
    #[serde(rename = "type")] pub _type: String,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Table {
    pub columns: Vec<Column>,
    #[serde(rename = "type")] pub _type: String,
    pub rows: Vec<Vec<serde_json::Value>>,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct Search {
    pub target: String,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct SearchResponse(pub Vec<String>);

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct QueryResponse(pub Vec<TargetData>);