Skip to content

Commit

Permalink
feat: implement /version endpoint in http indexer service
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis committed Oct 25, 2023
1 parent 1c71d49 commit ed2b558
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 16 deletions.
73 changes: 68 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
[workspace]
members = [
"common",
"service",
]
members = ["common", "service"]
resolver = "2"

[profile.dev.package."*"]
Expand Down
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ thiserror = "1.0.49"
async-trait = "0.1.74"
headers-derive = "0.1.1"
headers = "0.3.9"
build-info = "0.0.34"

[dev-dependencies]
env_logger = "0.9.0"
Expand Down
26 changes: 25 additions & 1 deletion common/src/indexer_service/http/indexer_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use axum::{
body::Body,
response::{IntoResponse, Response},
routing::{get, post},
Router, Server,
Json, Router, Server,
};
use build_info::BuildInfo;
use eventuals::Eventual;
use reqwest::StatusCode;
use serde::{de::DeserializeOwned, Serialize};
Expand Down Expand Up @@ -114,12 +115,34 @@ where
}
}

#[derive(Clone, Serialize)]
pub struct IndexerServiceRelease {
version: String,
dependencies: HashMap<String, String>,
}

impl From<&BuildInfo> for IndexerServiceRelease {
fn from(value: &BuildInfo) -> Self {
Self {
version: value.crate_info.version.to_string(),
dependencies: HashMap::from_iter(
value
.crate_info
.dependencies
.iter()
.map(|d| (d.name.clone(), d.version.to_string())),
),
}
}
}

pub struct IndexerServiceOptions<I>
where
I: IndexerServiceImpl + Sync + Send + 'static,
{
pub service_impl: I,
pub config: IndexerServiceConfig,
pub release: IndexerServiceRelease,
pub extra_routes: Router<Arc<IndexerServiceState<I>>, Body>,
}

Expand Down Expand Up @@ -230,6 +253,7 @@ impl IndexerService {

let router = Router::new()
.route("/", get("Service is up and running"))
.route("/version", get(Json(options.release)))
.route(
PathBuf::from(options.config.server.url_prefix)
.join("manifests/:id")
Expand Down
2 changes: 1 addition & 1 deletion common/src/indexer_service/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub use config::{
NetworkSubgraphConfig, ServerConfig,
};
pub use indexer_service::{
IndexerService, IndexerServiceImpl, IndexerServiceOptions, IsAttestable,
IndexerService, IndexerServiceImpl, IndexerServiceOptions, IndexerServiceRelease, IsAttestable,
};
22 changes: 17 additions & 5 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "service"
version = "0.1.0"
edition = "2021"
description="Could not find crate on crates.io and could not import with git and path at the same time, so copied a version directly at https://github.com/graphprotocol/indexer/blob/972658b3ce8c512ad7b4dc575d29cd9d5377e3fe/packages/indexer-native/native"
description = "Could not find crate on crates.io and could not import with git and path at the same time, so copied a version directly at https://github.com/graphprotocol/indexer/blob/972658b3ce8c512ad7b4dc575d29cd9d5377e3fe/packages/indexer-native/native"
license = "Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -25,7 +25,11 @@ serde_json = "1"
axum = "0.5"
hyper = "0.14.27"
tower = { version = "0.4", features = ["util", "timeout", "limit"] }
tower-http = { version = "0.4.0", features = ["add-extension", "trace", "cors"] }
tower-http = { version = "0.4.0", features = [
"add-extension",
"trace",
"cors",
] }
toml = "0.7.4"
once_cell = "1.17"
async-graphql = "4.0.16"
Expand All @@ -44,11 +48,19 @@ prometheus = "0.13.3"
hex = "0.4.3"
tap_core = "0.6.0"
ethereum-types = "0.14.1"
sqlx = { version = "0.7.1", features = ["postgres", "runtime-tokio", "bigdecimal", "rust_decimal", "time"] }
sqlx = { version = "0.7.1", features = [
"postgres",
"runtime-tokio",
"bigdecimal",
"rust_decimal",
"time",
] }
alloy-primitives = { version = "0.4.2", features = ["serde"] }
alloy-sol-types = "0.4.2"
lazy_static = "1.4.0"
toolshed = { git = "https://github.com/edgeandnode/toolshed", branch = "main", features = ["graphql"] }
toolshed = { git = "https://github.com/edgeandnode/toolshed", branch = "main", features = [
"graphql",
] }

[dev-dependencies]
faux = "0.1.10"
Expand All @@ -65,4 +77,4 @@ wiremock = "0.5.19"
version = "1"
default-features = false
# Disable features which are enabled by default
features = ["precommit-hook", "run-cargo-fmt", "run-cargo-clippy"]
features = ["precommit-hook", "run-cargo-fmt", "run-cargo-clippy"]

0 comments on commit ed2b558

Please sign in to comment.