Skip to content

Commit

Permalink
refactor: use IndexerServiceRelease for /version endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis committed Oct 26, 2023
1 parent 0bea997 commit 7539a64
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 64 deletions.
85 changes: 84 additions & 1 deletion Cargo.lock

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

4 changes: 4 additions & 0 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ lazy_static = "1.4.0"
toolshed = { git = "https://github.com/edgeandnode/toolshed", branch = "main", features = [
"graphql",
] }
build-info = "0.0.34"

[dev-dependencies]
faux = "0.1.10"
Expand All @@ -69,6 +70,9 @@ indexer-common = { path = "../common", features = ["mock"] }
test-log = "0.2.12"
wiremock = "0.5.19"

[build-dependencies]
build-info-build = "0.0.34"

# [[bin]]
# name = "indexer-native"
# path = "native"
Expand Down
5 changes: 5 additions & 0 deletions service/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use build_info_build::DependencyDepth;

fn main() {
build_info_build::build_script().collect_dependencies(DependencyDepth::Depth(1));
}
11 changes: 6 additions & 5 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use std::{net::SocketAddr, str::FromStr, time::Duration};
use tracing::info;

use indexer_common::{
indexer_service::http::IndexerServiceRelease,
prelude::{
attestation_signers, dispute_manager, escrow_accounts, indexer_allocations, SubgraphClient,
attestation_signers, dispute_manager, escrow_accounts, indexer_allocations,
DeploymentDetails, SubgraphClient, TapManager,
},
subgraph_client::DeploymentDetails,
tap_manager::TapManager,
};

use util::{package_version, shutdown_signal};
use util::shutdown_signal;

use crate::{
common::database, config::Cli, metrics::handle_serve_metrics, query_processor::QueryProcessor,
Expand Down Expand Up @@ -54,7 +54,8 @@ async fn main() -> Result<(), std::io::Error> {

// Parse basic configurations
let config = Cli::args();
let release = package_version().expect("Failed to resolve for release version");
build_info::build_info!(fn build_info);
let release = IndexerServiceRelease::from(build_info());

// Initialize graph-node client
let graph_node = graph_node::GraphNodeInstance::new(
Expand Down
7 changes: 3 additions & 4 deletions service/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@ use tower_http::{
};
use tracing::Level;

use indexer_common::prelude::SubgraphClient;
use indexer_common::{indexer_service::http::IndexerServiceRelease, prelude::SubgraphClient};

use crate::{
query_processor::QueryProcessor,
server::routes::{network_ratelimiter, slow_ratelimiter},
util::PackageVersion,
};

pub mod routes;

#[derive(Clone)]
pub struct ServerOptions {
pub port: Option<u32>,
pub release: PackageVersion,
pub release: IndexerServiceRelease,
pub query_processor: QueryProcessor,
pub free_query_auth_token: Option<String>,
pub graph_node_status_endpoint: String,
Expand All @@ -47,7 +46,7 @@ impl ServerOptions {
#[allow(clippy::too_many_arguments)]
pub fn new(
port: Option<u32>,
release: PackageVersion,
release: IndexerServiceRelease,
query_processor: QueryProcessor,
free_query_auth_token: Option<String>,
graph_node_status_endpoint: String,
Expand Down
54 changes: 0 additions & 54 deletions service/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

use ethers::signers::WalletError;
use serde::Serialize;
use std::collections::HashMap;
use std::fs;
use tokio::signal;
use toml::Value;
use tracing::{
info,
subscriber::{set_global_default, SetGlobalDefaultError},
};
use tracing_subscriber::{EnvFilter, FmtSubscriber};

use crate::common::address::{build_wallet, wallet_address};
use crate::common::indexer_error::{indexer_error, IndexerError};

/// Struct for version control
#[derive(Serialize, Debug, Clone)]
pub struct PackageVersion {
version: String,
dependencies: HashMap<String, String>,
}

/// Read the manfiest
fn read_manifest() -> Result<Value, IndexerError> {
let toml_string = fs::read_to_string("service/Cargo.toml")
.map_err(|_e| indexer_error(crate::common::indexer_error::IndexerErrorCode::IE074))?;
let toml_value: Value = toml::from_str(&toml_string)
.map_err(|_e| indexer_error(crate::common::indexer_error::IndexerErrorCode::IE074))?;
Ok(toml_value)
}

/// Parse package versioning from the manifest
pub fn package_version() -> Result<PackageVersion, IndexerError> {
read_manifest().map(|toml_file| {
let pkg = toml_file.as_table().unwrap();
let version = pkg
.get("package")
.and_then(|p| p.get("version"))
.unwrap()
.as_str()
.unwrap()
.to_string();
let dependencies = pkg.get("dependencies").and_then(|d| d.as_table()).unwrap();
let indexer_native = dependencies
.get("indexer-native")
.map(|d| d.as_str().unwrap().to_string());

let release = PackageVersion {
version,
dependencies: match indexer_native {
Some(indexer_native_version) => {
let mut map = HashMap::new();
map.insert("indexer-native".to_string(), indexer_native_version);
map
}
None => HashMap::new(),
},
};
info!("Running package version {:#?}", release);

release
})
}

/// Validate that private key as an Eth wallet
pub fn public_key(value: &str) -> Result<String, WalletError> {
Expand Down

0 comments on commit 7539a64

Please sign in to comment.