relay_server/endpoints/
batch_metrics.rs

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
use axum::http::StatusCode;
use axum::response::IntoResponse;
use serde::{Deserialize, Serialize};

use crate::extractors::{ReceivedAt, SignedBytes};
use crate::service::ServiceState;
use crate::services::processor::{BucketSource, ProcessBatchedMetrics};

#[derive(Debug, Serialize, Deserialize)]
struct SendMetricsResponse {}

pub async fn handle(
    state: ServiceState,
    ReceivedAt(received_at): ReceivedAt,
    body: SignedBytes,
) -> impl IntoResponse {
    if !body.relay.internal {
        return StatusCode::FORBIDDEN.into_response();
    }

    state.processor().send(ProcessBatchedMetrics {
        payload: body.body,
        source: BucketSource::Internal,
        received_at,
        sent_at: None,
    });

    (StatusCode::ACCEPTED, axum::Json(SendMetricsResponse {})).into_response()
}