logscale_client/models/
ingest.rs

1use std::collections::HashMap;
2
3use serde::Serialize;
4use serde_json::value::Value as JsonValue;
5
6#[derive(Serialize)]
7pub struct StructuredLogsIngestRequest<'a> {
8    pub tags: HashMap<String, String>,
9    pub events: &'a [StructuredLogEvent],
10}
11
12#[derive(Serialize, Clone)]
13pub struct StructuredLogEvent {
14    pub timestamp: u128,
15    pub attributes: JsonValue,
16}
17
18impl StructuredLogEvent {
19    pub fn new(timestamp: u128, attributes: JsonValue) -> Self {
20        Self {
21            timestamp,
22            attributes,
23        }
24    }
25}
26
27#[derive(Clone)]
28pub struct UnstructuredLogEvent {
29    message: String,
30}
31
32impl Serialize for UnstructuredLogEvent {
33    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
34    where
35        S: serde::Serializer,
36    {
37        serializer.serialize_str(&self.message)
38    }
39}
40
41impl From<String> for UnstructuredLogEvent {
42    fn from(value: String) -> Self {
43        UnstructuredLogEvent { message: value }
44    }
45}
46
47#[derive(Serialize)]
48pub struct UnstructuredLogsIngestRequest<'a> {
49    pub messages: &'a [UnstructuredLogEvent],
50    pub fields: HashMap<&'a str, &'a str>,
51}
52
53impl<'a> UnstructuredLogsIngestRequest<'a> {
54    pub fn from_log_events(log_events: &'a [UnstructuredLogEvent]) -> Self {
55        Self {
56            messages: log_events,
57            fields: HashMap::new(),
58        }
59    }
60}
61
62pub trait LogScaleLogEvent: Clone + Serialize {}
63
64impl LogScaleLogEvent for StructuredLogEvent {}
65impl LogScaleLogEvent for UnstructuredLogEvent {}