Skip to content

Commit c9248d0

Browse files
committed
Initial metrics support
1 parent 59db2c6 commit c9248d0

8 files changed

Lines changed: 339 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 173 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ actix-web = { version = "4.11.0", features = ["http2"] }
1010
anyhow = "1.0.98"
1111
base16ct = { version = "0.2.0", features = ["std"] }
1212
clap = { version = "4.5.41", features = ["derive", "env"] }
13+
documented = "0.9.2"
1314
env_logger = "0.11.8"
1415
moka = { version = "0.12.10", features = ["future"] }
15-
# prometheus-client = "0.23.1"
16+
prometheus-client = "0.23.1"
1617
quick-xml = { version = "0.38.0", features = ["serde", "serialize"] }
1718
reqwest = { version = "0.12.22", default-features = false, features = ["charset", "http2", "system-proxy", "json", "rustls-tls"] }
1819
semver = "1.0.26"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use sha2::{Digest as _, Sha256};
1010

1111
use super::{ApiData, CacheKey, CacheValue};
1212

13-
pub async fn etag_middleware(
13+
pub async fn middleware(
1414
service_request: ServiceRequest,
1515
next: Next<impl MessageBody>
1616
) -> Result<ServiceResponse<EitherBody<impl MessageBody>>, actix_web::Error> {
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use std::fmt::Display;
1+
use std::fmt::{Display, Write};
22

33
use actix_web::{
44
HttpResponse,
55
Responder,
66
get,
77
web::{self, ServiceConfig}
88
};
9+
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
910
use serde::{Deserialize, Serialize};
1011
use tokio::task::JoinSet;
1112

@@ -43,6 +44,15 @@ pub enum ModLoader {
4344
Fabric
4445
}
4546

47+
impl EncodeLabelValue for ModLoader {
48+
fn encode(
49+
&self,
50+
encoder: &mut prometheus_client::encoding::LabelValueEncoder
51+
) -> Result<(), std::fmt::Error> {
52+
encoder.write_str(&self.to_string())
53+
}
54+
}
55+
4656
impl Display for ModLoader {
4757
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4858
f.write_str(match self {
@@ -52,22 +62,22 @@ impl Display for ModLoader {
5262
}
5363
}
5464

55-
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone)]
65+
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone, EncodeLabelSet)]
5666
pub struct OneConfigVersionInfo {
5767
/// The minecraft version to fetch artifacts for
58-
version: String,
68+
pub version: String,
5969
/// The mod loader to fetch artifacts for
60-
loader: ModLoader
70+
pub loader: ModLoader
6171
}
6272

6373
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq, Clone)]
6474
pub struct ArtifactQuery<V = ()> {
6575
/// Whether or not to use snapshots instead of official releases
6676
#[serde(default)]
67-
snapshots: bool,
77+
pub snapshots: bool,
6878
/// Extra version information
6979
#[serde(flatten)]
70-
version_info: V
80+
pub version_info: V
7181
}
7282

7383
#[get("/oneconfig")]

src/api/v1/endpoints/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod artifacts;

0 commit comments

Comments
 (0)