-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from axiomhq/annotations
Add annitation support
- Loading branch information
Showing
23 changed files
with
1,207 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Manage datasets, ingest data and query it. | ||
//! | ||
//! You're probably looking for the [`Client`]. | ||
//! | ||
//! # Examples | ||
//! ```no_run | ||
//! use axiom_rs::{Client, Error, annotations::requests}; | ||
//! use serde_json::json; | ||
//! | ||
//! #[tokio::main] | ||
//! async fn main() -> Result<(), Error> { | ||
//! let client = Client::new()?; | ||
//! | ||
//! let req = requests::Create::builder() | ||
//! .with_type("cake")? | ||
//! .with_datasets(vec!["snot".to_string(), "badger".to_string()])? | ||
//! .with_title("cookie") | ||
//! .build(); | ||
//! client.annotations().create(req).await?; | ||
//! | ||
//! let res = client.annotations().list(requests::List::default()).await?; | ||
//! assert_eq!(1, res.len()); | ||
//! | ||
//! client.annotations().delete(&res[1].id).await?; | ||
//! | ||
//! Ok(()) | ||
//! } | ||
//! ``` | ||
//! | ||
mod client; | ||
mod model; | ||
pub mod requests; | ||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub use client::Client; | ||
pub use model::Annotation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use std::fmt; | ||
|
||
use crate::{annotations::Annotation, error::Result, http}; | ||
use tracing::instrument; | ||
|
||
use super::requests; | ||
|
||
/// Provides methods to work with Axiom annotations. | ||
#[derive(Debug, Clone)] | ||
pub struct Client<'client> { | ||
http_client: &'client http::Client, | ||
} | ||
|
||
impl<'client> Client<'client> { | ||
pub(crate) fn new(http_client: &'client http::Client) -> Self { | ||
Self { http_client } | ||
} | ||
|
||
/// Creates an annotation | ||
/// | ||
/// # Errors | ||
/// If the API call fails | ||
#[instrument(skip(self))] | ||
pub async fn create(&self, req: requests::Create) -> Result<Annotation> { | ||
self.http_client | ||
.post("/v2/annotations", req) | ||
.await? | ||
.json() | ||
.await | ||
} | ||
|
||
/// Gets an annotation | ||
/// | ||
/// # Errors | ||
/// If the API call fails | ||
#[instrument(skip(self))] | ||
pub async fn get(&self, id: impl fmt::Display + fmt::Debug) -> Result<Annotation> { | ||
self.http_client | ||
.get(format!("/v2/annotations/{id}")) | ||
.await? | ||
.json() | ||
.await | ||
} | ||
|
||
/// Lists annotations | ||
/// | ||
/// # Errors | ||
/// If the API call fails | ||
#[instrument(skip(self))] | ||
pub async fn list(&self, req: requests::List) -> Result<Vec<Annotation>> { | ||
let query_params = serde_qs::to_string(&req)?; | ||
self.http_client | ||
.get(format!("/v2/annotations?{query_params}")) | ||
.await? | ||
.json() | ||
.await | ||
} | ||
|
||
/// Updates an annotation | ||
/// | ||
/// # Errors | ||
/// If the API call fails | ||
#[instrument(skip(self))] | ||
pub async fn update( | ||
&self, | ||
id: impl fmt::Display + fmt::Debug, | ||
req: requests::Update, | ||
) -> Result<Annotation> { | ||
self.http_client | ||
.put(format!("/v2/annotations/{id}"), req) | ||
.await? | ||
.json() | ||
.await | ||
} | ||
/// Delets an annotation | ||
/// | ||
/// # Errors | ||
/// If the API call fails | ||
#[instrument(skip(self))] | ||
pub async fn delete(&self, id: impl fmt::Display + fmt::Debug) -> Result<()> { | ||
self.http_client | ||
.delete(format!("/v2/annotations/{id}")) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use chrono::FixedOffset; | ||
use serde::{Deserialize, Serialize}; | ||
use url::Url; | ||
|
||
/// An annotation. | ||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] | ||
#[serde(rename_all = "camelCase")] | ||
|
||
pub struct Annotation { | ||
/// Unique ID of the annotation | ||
pub id: String, | ||
/// Type of the event marked by the annotation. Use only alphanumeric characters or hyphens. For example, "production-deployment". | ||
#[serde(rename = "type")] | ||
pub annotation_type: String, | ||
/// Dataset names for which the annotation appears on charts | ||
pub datasets: Vec<String>, | ||
/// Explanation of the event the annotation marks on the charts | ||
pub description: Option<String>, | ||
/// Summary of the annotation that appears on the charts | ||
pub title: Option<String>, | ||
/// URL relevant for the event marked by the annotation. For example, link to GitHub pull request. | ||
pub url: Option<Url>, | ||
/// Time the annotation marks on the charts. If you don't include this field, Axiom assigns the time of the API request to the annotation. | ||
pub time: chrono::DateTime<FixedOffset>, | ||
///End time of the annotation | ||
pub end_time: Option<chrono::DateTime<FixedOffset>>, | ||
} |
Oops, something went wrong.