Skip to content

Commit

Permalink
move config to sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
rtso committed Feb 11, 2025
1 parent 051a77e commit 0f5c6d5
Show file tree
Hide file tree
Showing 8 changed files with 420 additions and 3 deletions.
8 changes: 8 additions & 0 deletions aptos-indexer-processors-sdk/Cargo.lock

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

7 changes: 5 additions & 2 deletions aptos-indexer-processors-sdk/sdk-server-framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use anyhow::{Context, Result};
use aptos_indexer_processor_sdk::{
instrumented_channel::channel_metrics::init_channel_metrics_registry,
utils::step_metrics::init_step_metrics_registry,
traits::processor_trait::ProcessorTrait, utils::step_metrics::init_step_metrics_registry,
};
#[cfg(target_os = "linux")]
use aptos_system_utils::profiling::start_cpu_profiling;
Expand All @@ -20,6 +20,8 @@ use tokio::runtime::Handle;
use tracing::error;
use tracing_subscriber::EnvFilter;

// pub mod config;

/// ServerArgs bootstraps a server with all common pieces. And then triggers the run method for
/// the specific service.
#[derive(Parser)]
Expand All @@ -29,9 +31,10 @@ pub struct ServerArgs {
}

impl ServerArgs {
pub async fn run<C>(&self, handle: Handle) -> Result<()>
pub async fn run<C, P>(&self, handle: Handle) -> Result<()>
where
C: RunnableConfig,
P: ProcessorTrait,
{
// Set up the server.
setup_logging();
Expand Down
9 changes: 9 additions & 0 deletions aptos-indexer-processors-sdk/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ tiny-keccak = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }

autometrics = { workspace = true }
axum = { workspace = true }
backtrace = { workspace = true }
clap = { workspace = true }
serde_yaml = { workspace = true }
tempfile = { workspace = true }
toml = { workspace = true }
tracing-subscriber = { workspace = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use crate::{
aptos_indexer_transaction_stream::TransactionStreamConfig, common_steps::ProcessorStatusSaver,
};
use anyhow::Result;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::any::Any;

pub const QUERY_DEFAULT_RETRIES: u32 = 5;
pub const QUERY_DEFAULT_RETRY_DELAY_MS: u64 = 500;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct IndexerProcessorConfig<D> {
pub processor_name: String,
pub transaction_stream_config: TransactionStreamConfig,
pub db_config: D,
pub backfill_config: Option<BackfillConfig>,
}

// #[async_trait::async_trait]
// impl RunnableConfig for IndexerProcessorConfig {
// async fn run(&self) -> Result<()> {
// match self.processor_config {
// ProcessorConfig::EventsProcessor => {
// let events_processor = EventsProcessor::new(self.clone()).await?;
// events_processor.run_processor().await
// },
// }
// }

// fn get_server_name(&self) -> String {
// // Get the part before the first _ and trim to 12 characters.
// let before_underscore = self
// .processor_config
// .name()
// .split('_')
// .next()
// .unwrap_or("unknown");
// before_underscore[..before_underscore.len().min(12)].to_string()
// }
// }

// Note: You'll need to create a concrete implementation of this trait
// for your specific database configuration
pub trait DbConfig: Any + Clone + DeserializeOwned + ProcessorStatusSaver + Serialize {}

// #[derive(Clone, Debug, Deserialize, Serialize)]
// #[serde(deny_unknown_fields)]
// pub struct PostgresConfig {
// pub postgres_connection_string: String,
// // Size of the pool for writes/reads to the DB. Limits maximum number of queries in flight
// #[serde(default = "PostgresConfig::default_db_pool_size")]
// pub db_pool_size: u32,
// }

// impl DbConfig for PostgresConfig {}

// impl PostgresConfig {
// pub const fn default_db_pool_size() -> u32 {
// 150
// }
// }

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct BackfillConfig {
pub backfill_alias: String,
}
1 change: 1 addition & 0 deletions aptos-indexer-processors-sdk/sdk/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod indexer_processor_config;
2 changes: 2 additions & 0 deletions aptos-indexer-processors-sdk/sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod builder;
pub mod common_steps; // TODO: Feature gate this?
pub mod config;
pub mod server_framework;
pub mod test;
pub mod traits;
pub mod types;
Expand Down
Loading

0 comments on commit 0f5c6d5

Please sign in to comment.