From ad0a0c5d31e386e4b960c161e72477b8da6810d7 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Sun, 5 May 2024 11:05:14 -0700 Subject: [PATCH] chore: update axum and async-graphql dep --- file-service/Cargo.toml | 11 ++++++++--- file-service/src/admin.rs | 27 +++++++++++++++++++-------- file-service/src/metrics.rs | 22 ++++++++++++++++++---- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/file-service/Cargo.toml b/file-service/Cargo.toml index 053c0f3..cfc0e97 100644 --- a/file-service/Cargo.toml +++ b/file-service/Cargo.toml @@ -14,13 +14,18 @@ path = "src/main.rs" [dependencies] file-exchange = { path = "../file-exchange" } +# indexer-common = { package = "indexer-common", git = "https://github.com/graphprotocol/indexer-rs", rev = "3069008" } indexer-common = { package = "indexer-common", git = "https://github.com/graphprotocol/indexer-rs", rev = "8c97d04" } thegraph = { git = "https://github.com/edgeandnode/toolshed", tag = "thegraph-v0.5.0" } anyhow = "1.0" -async-graphql = "6.0.11" -async-graphql-axum = "6.0.11" +# async-graphql = "6.0.11" +async-graphql = "7.0.3" +async-graphql-axum = "7.0.3" +# async-graphql-axum = "6.0.11" autometrics = { version = "0.3.3", features = ["prometheus-exporter"] } -axum = "0.6.20" +axum = { version = "0.7.5", default_features = true } +axum-extra = { version = "0.9.3", features = ["typed-header"] } +#axum = "0.6.20" sha3 = "0.10.6" base64 = "0.21" build-info = "0.0.34" diff --git a/file-service/src/admin.rs b/file-service/src/admin.rs index f886b65..c70e74b 100644 --- a/file-service/src/admin.rs +++ b/file-service/src/admin.rs @@ -2,13 +2,15 @@ use std::collections::HashMap; use std::sync::Arc; use async_graphql::{Context, EmptySubscription, MergedObject, Object, Schema}; -use async_graphql_axum::{GraphQLRequest, GraphQLResponse}; -use axum::{extract::State, routing::get, Router, Server}; +use async_graphql_axum::{GraphQLRequest, GraphQLResponse, GraphQL}; +use axum::{extract::State, routing::get, Router, serve}; use file_exchange::{ config::{BundleArgs, PublisherArgs}, publisher::ManifestPublisher, }; +use core::net::SocketAddr; use http::HeaderMap; +use tokio::net::TcpListener; use tokio::sync::Mutex; use crate::file_server::{util::graphql_playground, FileServiceError, ServerContext}; @@ -82,8 +84,9 @@ async fn graphql_handler( context.state.admin_schema.execute(req).await.into() } -pub fn serve_admin(context: ServerContext) { +pub fn serve_admin(context: ServerContext) { tokio::spawn(async move { + let admin_schema= build_schema().await; let admin_context = AdminContext::new( AdminState { client: context.state.client.clone(), @@ -91,7 +94,7 @@ pub fn serve_admin(context: ServerContext) { files: context.state.files.clone(), prices: context.state.prices.clone(), admin_auth_token: context.state.admin_auth_token.clone(), - admin_schema: build_schema().await, + admin_schema: admin_schema.clone(), store: context.state.store.clone(), } .into(), @@ -101,13 +104,21 @@ pub fn serve_admin(context: ServerContext) { , "Serve admin metrics"); let router = Router::new() - .route("/admin", get(graphql_playground).post(graphql_handler)) + .route("/admin", get(graphql_playground).post_service(GraphQL::new(admin_schema))) .with_state(admin_context); - Server::bind(&addr) - .serve(router.into_make_service()) + let listener = TcpListener::bind(&addr) .await - .expect("Failed to initialize admin server") + .expect("Failed to bind to file-service admin port"); + serve( + listener, + router.into_make_service_with_connect_info::(), + ) + .await.expect("Failed to initialize admin server"); + // Server::bind(&addr) + // .serve(router.into_make_service()) + // .await + // .expect("Failed to initialize admin server") }); } diff --git a/file-service/src/metrics.rs b/file-service/src/metrics.rs index 0454bb7..f09cef0 100644 --- a/file-service/src/metrics.rs +++ b/file-service/src/metrics.rs @@ -1,8 +1,11 @@ use autometrics::encode_global_metrics; use axum::http::StatusCode; use axum::routing::get; +// use axum::{Router, Server}; use axum::Router; -use axum::Server; +use axum::serve; +use tokio::net::TcpListener; +use core::net::SocketAddr; use once_cell::sync::Lazy; use prometheus::{core::Collector, Registry}; use prometheus::{HistogramOpts, HistogramVec, IntGaugeVec, Opts}; @@ -83,9 +86,20 @@ pub fn serve_metrics(config: &ServerArgs) { let app = Router::new().route("/metrics", get(get_metrics)); let metrics_addr = config.metrics_host_and_port.unwrap(); tokio::spawn(async move { - Server::bind(&metrics_addr) - .serve(app.into_make_service()) + // Server::bind(&metrics_addr) + // .serve(app.into_make_service()) + // .await + // .expect("Failed to initialize metrics server") + + + let listener = TcpListener::bind(&metrics_addr) .await - .expect("Failed to initialize admin server") + .expect("Failed to bind to file-service metrics"); + serve( + listener, + app.into_make_service_with_connect_info::(), + ) + .await + .expect("Failed to initialize metrics server") }); }