Skip to content

Commit

Permalink
feat: add subgraph ID to reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Feb 19, 2025
1 parent 2748f13 commit 8368e8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/client_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,18 @@ async fn run_indexer_queries(
total_fees_usd = *total_fees_usd.0,
);

let subgraph_id = if subgraph.subgraphs.len() == 1 {
Some(subgraph.subgraphs[0])
} else {
None
};
let _ = ctx.reporter.send(reports::ClientRequest {
id: request_id,
response_time_ms,
result,
api_key: auth.key,
user: auth.user,
subgraph: subgraph_id,
grt_per_usd,
indexer_requests,
request_bytes: client_request_bytes,
Expand Down Expand Up @@ -760,6 +766,7 @@ pub async fn handle_indexer_query(
result: report_result,
api_key: auth.key,
user: auth.user,
subgraph: None,
grt_per_usd,
request_bytes: indexer_request.request.len() as u32,
response_bytes: result.as_ref().map(|r| r.client_response.len() as u32).ok(),
Expand Down
6 changes: 5 additions & 1 deletion src/reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::HashSet, time::Duration};
use anyhow::{anyhow, Context};
use ordered_float::NotNan;
use prost::Message;
use thegraph_core::{alloy::primitives::Address, DeploymentId, IndexerId};
use thegraph_core::{alloy::primitives::Address, DeploymentId, IndexerId, SubgraphId};
use tokio::{sync::mpsc, time::Instant};

use crate::{concat_bytes, errors, indexer_client::IndexerResponse, receipts::Receipt};
Expand All @@ -14,6 +14,7 @@ pub struct ClientRequest {
pub result: Result<(), errors::Error>,
pub api_key: String,
pub user: String,
pub subgraph: Option<SubgraphId>,
pub grt_per_usd: NotNan<f64>,
pub indexer_requests: Vec<IndexerRequest>,
pub request_bytes: u32,
Expand Down Expand Up @@ -149,6 +150,7 @@ impl Reporter {
query_id: client_request.id,
api_key: client_request.api_key,
user_id: client_request.user,
subgraph: client_request.subgraph.map(|s| s.to_string()),
result: client_request
.result
.map(|()| "success".to_string())
Expand Down Expand Up @@ -230,6 +232,8 @@ pub struct ClientQueryProtobuf {
api_key: String,
#[prost(string, tag = "11")]
user_id: String,
#[prost(string, optional, tag = "12")]
subgraph: Option<String>,
#[prost(string, tag = "5")]
result: String,
#[prost(uint32, tag = "6")]
Expand Down

0 comments on commit 8368e8d

Please sign in to comment.