Skip to content

Commit

Permalink
chore: update axum and async-graphql dep
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed May 6, 2024
1 parent 511f3c7 commit ad0a0c5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
11 changes: 8 additions & 3 deletions file-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 19 additions & 8 deletions file-service/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -82,16 +84,17 @@ 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(),
bundles: context.state.bundles.clone(),
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(),
Expand All @@ -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::<SocketAddr>(),
)
.await.expect("Failed to initialize admin server");
// Server::bind(&addr)
// .serve(router.into_make_service())
// .await
// .expect("Failed to initialize admin server")
});
}

Expand Down
22 changes: 18 additions & 4 deletions file-service/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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::<SocketAddr>(),
)
.await
.expect("Failed to initialize metrics server")
});
}

0 comments on commit ad0a0c5

Please sign in to comment.