Skip to content
4 changes: 3 additions & 1 deletion .github/workflows/_graph_proxy_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
images: ${{ env.IMAGE_REPOSITORY }}
tags: |
type=raw,value=${{ steps.tags.outputs.version }}
type=raw,value=${{ github.ref_name }}
type=raw,value=latest

- name: Set up Docker Buildx
Expand All @@ -47,7 +48,8 @@ jobs:
context: backend
file: backend/Dockerfile.graph-proxy
target: deploy
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/graph-proxy@') }}
#push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/graph-proxy@') }}
push: ${{ github.event_name == 'push' && (github.ref_type == 'branch' || startsWith(github.ref, 'refs/tags/graph-proxy@')) }}
load: ${{ !(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/graph-proxy@')) }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
27 changes: 22 additions & 5 deletions backend/graph-proxy/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
auth_token_header: Option<TypedHeader<Authorization<Bearer>>>,
request: GraphQLRequest,
) -> GraphQLResponse {
let start = std::time::Instant::now();
let query = request.into_inner();

if let Ok(query) = parse_query(&query.query) {
Expand All @@ -133,13 +134,15 @@
for operation in operations {
match operation {
async_graphql::parser::types::OperationType::Query => state
.metrics_state

Check warning on line 137 in backend/graph-proxy/src/graphql/mod.rs

View workflow job for this annotation

GitHub Actions / graph_proxy_code / lint

Diff in /home/runner/work/workflows/workflows/backend/graph-proxy/src/graphql/mod.rs
.total_requests
.add(1, &[KeyValue::new("request_type", "query")]),
async_graphql::parser::types::OperationType::Mutation => state
.metrics_state
.total_requests
.add(1, &[KeyValue::new("request_type", "mutation")]),
async_graphql::parser::types::OperationType::Mutation => {
state
.metrics_state
.total_requests
.add(1, &[KeyValue::new("request_type", "mutation")])
}
async_graphql::parser::types::OperationType::Subscription => {}
};
}
Expand All @@ -151,7 +154,21 @@
};

let auth_token = auth_token_header.map(|header| header.0);
state.schema.execute(query.data(auth_token)).await.into()
// state.schema.execute(query.data(auth_token)).await.into()
let response = state.schema.execute(query.data(auth_token)).await;
let elapsed_ms = start.elapsed().as_secs_f64() * 1000.0;
let status = if response.errors.is_empty() {
"ok"
} else {

Check warning on line 162 in backend/graph-proxy/src/graphql/mod.rs

View workflow job for this annotation

GitHub Actions / graph_proxy_code / lint

Diff in /home/runner/work/workflows/workflows/backend/graph-proxy/src/graphql/mod.rs
"error"
};
state.metrics_state.request_duration_ms.record(
elapsed_ms,
&[
KeyValue::new("status", status),
],
);
response.into()
}

lazy_static! {
Expand Down
3 changes: 3 additions & 0 deletions backend/graph-proxy/src/graphql/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct WatchEvent {
/// Error returned by API
error: Option<StreamError>,
}

/// Get authentication token
fn get_auth_token(ctx: &Context<'_>) -> anyhow::Result<String> {
ctx.data_unchecked::<Option<Authorization<Bearer>>>()
.as_ref()
Expand Down Expand Up @@ -203,6 +205,7 @@ impl WorkflowsSubscription {
}
}

/// message for StreamError
#[derive(Debug, Deserialize)]
struct StreamError {
/// The message associated with the error
Expand Down
3 changes: 3 additions & 0 deletions backend/graph-proxy/src/graphql/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ impl Workflow {
}
}

/// Metadata for a workflow
#[derive(Debug)]
pub(super) struct Metadata {
/// The name given to the workflow, unique within a given visit
Expand Down Expand Up @@ -379,6 +380,7 @@ impl Artifact<'_> {
}
}

/// Get filename of the artifact in s3 bucket
fn artifact_filename(
manifest: &IoArgoprojWorkflowV1alpha1Artifact,
) -> Result<&str, WorkflowParsingError> {
Expand Down Expand Up @@ -471,6 +473,7 @@ impl Task {
}
}

/// Fetch missing task information
async fn fetch_missing_task_info(
mut url: Url,
token: Option<Authorization<Bearer>>,
Expand Down
15 changes: 13 additions & 2 deletions backend/graph-proxy/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use opentelemetry::metrics::{Counter, MeterProvider};
use opentelemetry::metrics::{Counter, Histogram, MeterProvider};
use opentelemetry_sdk::metrics::SdkMeterProvider;

/// Thread-safe wrapper for OTEL metrics
Expand All @@ -11,6 +11,8 @@ pub type MetricsState = Arc<Metrics>;
pub struct Metrics {
/// Total requests on all routes
pub total_requests: Counter<u64>,
/// Request duration on every request
pub request_duration_ms: Histogram<f64>,
}

impl Metrics {
Expand All @@ -23,6 +25,15 @@ impl Metrics {
.with_description("The total requests on all routes made since the last restart.")
.build();

Metrics { total_requests }
let request_duration_ms = meter
.f64_histogram("graph_proxy_request_duration_ms")
.with_description("GraphQL request duration")
.with_unit("ms")
.build();

Metrics {
total_requests,
request_duration_ms,
}
}
}
Loading