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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
//! Metrics queries/subscriptions.

use graphql_client::GraphQLQuery;

use crate::BoxedSubscription;

/// UptimeSubscription returns uptime metrics to determine how long the Vector
/// instance has been running.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/uptime.graphql",
    response_derives = "Debug"
)]
pub struct UptimeSubscription;

/// ComponentAllocatedBytesSubscription contains metrics on the number of allocated bytes
/// that have been processed by a Vector instance, against specific components.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_allocated_bytes.graphql",
    response_derives = "Debug"
)]
pub struct ComponentAllocatedBytesSubscription;

/// ComponentReceivedBytesThroughputsSubscription contains metrics on the number of bytes
/// that have been received between `interval` samples, against specific components.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_received_bytes_throughputs.graphql",
    response_derives = "Debug"
)]
pub struct ComponentReceivedBytesThroughputsSubscription;

/// ComponentReceivedBytesTotalsSubscription contains metrics on the number of bytes
/// that have been received by a Vector instance, against a specific component.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_received_bytes_totals.graphql",
    response_derives = "Debug"
)]
pub struct ComponentReceivedBytesTotalsSubscription;

/// ComponentReceivedEventsThroughputsSubscription contains metrics on the number of events
/// that have been accepted for processing between `interval` samples, against specific components.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_received_events_throughputs.graphql",
    response_derives = "Debug"
)]
pub struct ComponentReceivedEventsThroughputsSubscription;

/// ComponentReceivedEventsTotalsSubscription contains metrics on the number of events
/// that have been accepted for processing by a Vector instance, against specific components.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_received_events_totals.graphql",
    response_derives = "Debug"
)]
pub struct ComponentReceivedEventsTotalsSubscription;

/// ComponentSentBytesThroughputsSubscription contains metrics on the number of bytes
/// that have been received between `interval` samples, against specific components.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_sent_bytes_throughputs.graphql",
    response_derives = "Debug"
)]
pub struct ComponentSentBytesThroughputsSubscription;

/// ComponentSentBytesTotalsSubscription contains metrics on the number of bytes
/// that have been received by a Vector instance, against a specific component.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_sent_bytes_totals.graphql",
    response_derives = "Debug"
)]
pub struct ComponentSentBytesTotalsSubscription;

/// ComponentSentEventsThroughputsSubscription contains metrics on the number of events
/// that have been emitted between `interval` samples, against specific components.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_sent_events_throughputs.graphql",
    response_derives = "Debug"
)]
pub struct ComponentSentEventsThroughputsSubscription;

/// ComponentSentEventsTotalsSubscription contains metrics on the number of events
/// that have been emitted by a Vector instance, against specific components.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_sent_events_totals.graphql",
    response_derives = "Debug"
)]
pub struct ComponentSentEventsTotalsSubscription;

impl component_sent_events_totals_subscription::ComponentSentEventsTotalsSubscriptionComponentSentEventsTotals {
    pub fn outputs(&self) -> Vec<(String, i64)> {
        self.outputs
            .iter()
            .map(|output| {
                (
                    output.output_id.clone(),
                    output
                        .sent_events_total
                        .as_ref()
                        .map(|p| p.sent_events_total as i64)
                        .unwrap_or(0),
                )
            })
            .collect()
    }
}

impl component_sent_events_throughputs_subscription::ComponentSentEventsThroughputsSubscriptionComponentSentEventsThroughputs {
    pub fn outputs(&self) -> Vec<(String, i64)> {
        self.outputs
            .iter()
            .map(|output| {
                (
                    output.output_id.clone(),
                    output.throughput,
                )
            })
            .collect()
    }

}

/// ComponentErrorsTotalsSubscription contains metrics on the number of errors
/// (metrics ending in `_errors_total`), against specific components.
#[derive(GraphQLQuery, Debug, Copy, Clone)]
#[graphql(
    schema_path = "graphql/schema.json",
    query_path = "graphql/subscriptions/component_errors_totals.graphql",
    response_derives = "Debug"
)]
pub struct ComponentErrorsTotalsSubscription;

/// Extension methods for metrics subscriptions
pub trait MetricsSubscriptionExt {
    /// Executes an uptime metrics subscription.
    fn uptime_subscription(&self) -> crate::BoxedSubscription<UptimeSubscription>;

    /// Executes an all component allocated bytes subscription.
    fn component_allocated_bytes_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentAllocatedBytesSubscription>;

    /// Executes a component bytes received totals subscription.
    fn component_received_bytes_totals_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentReceivedBytesTotalsSubscription>;

    /// Executes a component bytes received throughput subscription.
    fn component_received_bytes_throughputs_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentReceivedBytesThroughputsSubscription>;

    /// Executes a component received events totals subscription.
    fn component_received_events_totals_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentReceivedEventsTotalsSubscription>;

    /// Executes an component events in throughputs subscription.
    fn component_received_events_throughputs_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentReceivedEventsThroughputsSubscription>;

    /// Executes a component bytes sent totals subscription.
    fn component_sent_bytes_totals_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentSentBytesTotalsSubscription>;

    /// Executes a component bytes sent throughput subscription.
    fn component_sent_bytes_throughputs_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentSentBytesThroughputsSubscription>;

    /// Executes a component events totals subscription.
    fn component_sent_events_totals_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentSentEventsTotalsSubscription>;

    /// Executes a component sent events throughputs subscription.
    fn component_sent_events_throughputs_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentSentEventsThroughputsSubscription>;

    fn component_errors_totals_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentErrorsTotalsSubscription>;
}

impl MetricsSubscriptionExt for crate::SubscriptionClient {
    /// Executes an uptime metrics subscription.
    fn uptime_subscription(&self) -> BoxedSubscription<UptimeSubscription> {
        let request_body = UptimeSubscription::build_query(uptime_subscription::Variables);

        self.start::<UptimeSubscription>(&request_body)
    }

    /// Executes an all component allocated bytes subscription.
    fn component_allocated_bytes_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentAllocatedBytesSubscription> {
        let request_body = ComponentAllocatedBytesSubscription::build_query(
            component_allocated_bytes_subscription::Variables { interval },
        );

        self.start::<ComponentAllocatedBytesSubscription>(&request_body)
    }

    /// Executes an all component bytes received totals subscription.
    fn component_received_bytes_totals_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentReceivedBytesTotalsSubscription> {
        let request_body = ComponentReceivedBytesTotalsSubscription::build_query(
            component_received_bytes_totals_subscription::Variables { interval },
        );

        self.start::<ComponentReceivedBytesTotalsSubscription>(&request_body)
    }

    /// Executes a component bytes received throughput subscription.
    fn component_received_bytes_throughputs_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentReceivedBytesThroughputsSubscription> {
        let request_body = ComponentReceivedBytesThroughputsSubscription::build_query(
            component_received_bytes_throughputs_subscription::Variables { interval },
        );

        self.start::<ComponentReceivedBytesThroughputsSubscription>(&request_body)
    }

    /// Executes an all component received events totals subscription.
    fn component_received_events_totals_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentReceivedEventsTotalsSubscription> {
        let request_body = ComponentReceivedEventsTotalsSubscription::build_query(
            component_received_events_totals_subscription::Variables { interval },
        );

        self.start::<ComponentReceivedEventsTotalsSubscription>(&request_body)
    }

    /// Executes an all component received events throughputs subscription.
    fn component_received_events_throughputs_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentReceivedEventsThroughputsSubscription> {
        let request_body = ComponentReceivedEventsThroughputsSubscription::build_query(
            component_received_events_throughputs_subscription::Variables { interval },
        );

        self.start::<ComponentReceivedEventsThroughputsSubscription>(&request_body)
    }

    /// Executes an all component bytes sent totals subscription.
    fn component_sent_bytes_totals_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentSentBytesTotalsSubscription> {
        let request_body = ComponentSentBytesTotalsSubscription::build_query(
            component_sent_bytes_totals_subscription::Variables { interval },
        );

        self.start::<ComponentSentBytesTotalsSubscription>(&request_body)
    }

    /// Executes a component bytes sent throughput subscription.
    fn component_sent_bytes_throughputs_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentSentBytesThroughputsSubscription> {
        let request_body = ComponentSentBytesThroughputsSubscription::build_query(
            component_sent_bytes_throughputs_subscription::Variables { interval },
        );

        self.start::<ComponentSentBytesThroughputsSubscription>(&request_body)
    }

    /// Executes a component sent events totals subscription.
    fn component_sent_events_totals_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentSentEventsTotalsSubscription> {
        let request_body = ComponentSentEventsTotalsSubscription::build_query(
            component_sent_events_totals_subscription::Variables { interval },
        );

        self.start::<ComponentSentEventsTotalsSubscription>(&request_body)
    }

    /// Executes a component sent events throughputs subscription.
    fn component_sent_events_throughputs_subscription(
        &self,
        interval: i64,
    ) -> crate::BoxedSubscription<ComponentSentEventsThroughputsSubscription> {
        let request_body = ComponentSentEventsThroughputsSubscription::build_query(
            component_sent_events_throughputs_subscription::Variables { interval },
        );

        self.start::<ComponentSentEventsThroughputsSubscription>(&request_body)
    }

    fn component_errors_totals_subscription(
        &self,
        interval: i64,
    ) -> BoxedSubscription<ComponentErrorsTotalsSubscription> {
        let request_body = ComponentErrorsTotalsSubscription::build_query(
            component_errors_totals_subscription::Variables { interval },
        );

        self.start::<ComponentErrorsTotalsSubscription>(&request_body)
    }
}