Skip to content

Commit

Permalink
Improve behavior when in remote config mode
Browse files Browse the repository at this point in the history
- Add minimal mode.
  - When local configuration is not used, Giganto will run in minimal
    mode.
  - In minimal mode, only the GraphQL server runs. Tasks and DB
    migrations are skipped.
  - The GraphQL server in minimal mode provides limited APIs.
  - If the configuration is received successfully via the `setConfig`
    GraphQL API, it will switch to normal mode.
- Remove OS-specific configuration directory.

Close: #876
Close: #881
  • Loading branch information
kimhanbeom authored Dec 11, 2024
1 parent 87b106a commit df0a81c
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 284 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- Changed `COMPATIBLE_VERSION_REQ` to ">=0.24.0-alpha.1,<0.25.0".
- Added migration function `migrate_0_23_0_to_0_24_0_op_log`. This function
performs a migration to change the key and value of `Oplog`.
- Added minimal mode to improve behavior in remote configuration mode.
- If local configuration is not used when running Giganto, it will run in
minimal mode, with only the GraphQL server running. Retain task, peer server
task, ingest task, publish task, and DB migration are not executed.
- In minimal mode, the APIs provided by the GraphQL server are limited. In
this mode, only the APIs provided by `graphql::status` are available.
- If the configuration is received successfully via the `setConfig` GraphQL
API, it will switch to normal mode, where all task and DB migrations run
as normal, just like when running Giganto with local settings.

### Removed

- Removed OS-specific configuration directory.
- Linux: $HOME/.config/giganto/config.toml
- macOS: $HOME/Library/Application Support/com.cluml.giganto/config.toml

## [0.23.0] - 2024-11-21

Expand Down
51 changes: 1 addition & 50 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ config = { version = "0.14", features = ["toml"], default-features = false }
ctrlc = { version = "3", features = ["termination"] }
data-encoding = "2"
deluxe = "0.5"
directories = "5"
futures-util = "0.3"
giganto-client = { git = "https://github.com/aicers/giganto-client.git", tag = "0.21.0" }
graphql_client = "0.14"
Expand Down
34 changes: 30 additions & 4 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ pub struct Query(
netflow::NetflowQuery,
);

#[derive(Default, MergedObject)]
pub struct MinimalQuery(status::StatusQuery);

#[derive(Default, MergedObject)]
pub struct Mutation(status::ConfigMutation);

Expand Down Expand Up @@ -141,7 +144,8 @@ pub trait ClusterSortKey {
fn secondary(&self) -> Option<&str>;
}

pub type Schema = async_graphql::Schema<Query, Mutation, EmptySubscription>;
type Schema = async_graphql::Schema<Query, Mutation, EmptySubscription>;
type MinimalSchema = async_graphql::Schema<MinimalQuery, Mutation, EmptySubscription>;
type ConnArgs<T> = (Vec<(Box<[u8]>, T)>, bool, bool);

pub struct NodeName(pub String);
Expand All @@ -164,7 +168,7 @@ pub fn schema(
notify_terminate: Arc<Notify>,
ack_transmission_cnt: AckTransmissionCount,
is_local_config: bool,
settings: Settings,
settings: Option<Settings>,
) -> Schema {
Schema::build(Query::default(), Mutation::default(), EmptySubscription)
.data(node_name)
Expand All @@ -184,6 +188,28 @@ pub fn schema(
.finish()
}

pub fn minimal_schema(
reload_tx: Sender<String>,
notify_reboot: Arc<Notify>,
notify_power_off: Arc<Notify>,
notify_terminate: Arc<Notify>,
is_local_config: bool,
settings: Option<Settings>,
) -> MinimalSchema {
MinimalSchema::build(
MinimalQuery::default(),
Mutation::default(),
EmptySubscription,
)
.data(reload_tx)
.data(TerminateNotify(notify_terminate))
.data(RebootNotify(notify_reboot))
.data(PowerOffNotify(notify_power_off))
.data(is_local_config)
.data(settings)
.finish()
}

/// The default page size for connections when neither `first` nor `last` is
/// provided. Maximum size: 100.
const MAXIMUM_PAGE_SIZE: usize = 100;
Expand Down Expand Up @@ -1779,7 +1805,7 @@ mod tests {
let notify_reboot = Arc::new(Notify::new());
let notify_power_off = Arc::new(Notify::new());
let notify_terminate = Arc::new(Notify::new());
let settings = Settings::new().unwrap();
let settings = Settings::from_file("tests/config.toml").unwrap();
let schema = schema(
NodeName("giganto1".to_string()),
db.clone(),
Expand All @@ -1794,7 +1820,7 @@ mod tests {
notify_terminate,
Arc::new(RwLock::new(1024)),
is_local_config,
settings,
Some(settings),
);

Self {
Expand Down
28 changes: 18 additions & 10 deletions src/graphql/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ impl StatusQuery {
if *is_local {
Err(anyhow!("Config is local").into())
} else {
let s = ctx.data::<Settings>()?;

Ok(s.config.clone())
let s = ctx.data::<Option<Settings>>()?;
if let Some(settings) = s {
return Ok(settings.config.clone());
}
Err(anyhow!("The config doesn't exist and needs to be set up remotely.").into())
}
}

Expand All @@ -191,11 +193,13 @@ impl ConfigMutation {

let config_draft: Config = toml::from_str(&draft)?;

let s = ctx.data::<Settings>()?;
let s = ctx.data::<Option<Settings>>()?;

if s.config == config_draft {
info!("No changes.");
return Err("No changes".to_string().into());
if let Some(settings) = s {
if settings.config == config_draft {
info!("No changes.");
return Err("No changes".to_string().into());
}
}

let reload_tx = ctx.data::<Sender<String>>()?;
Expand Down Expand Up @@ -247,7 +251,11 @@ pub fn settings_to_doc(settings: &Settings) -> Result<DocumentMut> {

pub fn write_toml_file(doc: &DocumentMut, path: &str) -> Result<()> {
let output = doc.to_string();
let mut config_file = OpenOptions::new().write(true).truncate(true).open(path)?;
let mut config_file = OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.open(path)?;
writeln!(config_file, "{output}")?;
Ok(())
}
Expand Down Expand Up @@ -438,8 +446,8 @@ mod tests {
max_mb_of_level_base = 512
num_of_thread = 8
max_sub_compactions = 2
addr_to_peers = "127.0.0.1:48383"
peers = [{ addr = "127.0.0.1:60192", hostname = "node2" }]
addr_to_peers = "127.0.0.1:48382"
peers = [{ addr = "127.0.0.1:60193", hostname = "node3" }]
"#
.to_string()
}
Expand Down
8 changes: 8 additions & 0 deletions src/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl Server {
runtime_ingest_sensors,
rx,
notify_sensor,
notify_shutdown.clone(),
));

let shutdown_signal = Arc::new(AtomicBool::new(false));
Expand Down Expand Up @@ -1074,6 +1075,7 @@ async fn check_sensors_conn(
runtime_ingest_sensors: RunTimeIngestSensors,
mut rx: Receiver<SensorInfo>,
notify_sensor: Option<Arc<Notify>>,
notify_shutdown: Arc<Notify>,
) -> Result<()> {
let mut itv = time::interval(time::Duration::from_secs(SENSOR_INTERVAL));
itv.reset();
Expand Down Expand Up @@ -1121,8 +1123,14 @@ async fn check_sensors_conn(
}
}
}

() = notify_shutdown.notified() => {
break;
},
}
}

Ok(())
}

pub struct NetworkKey {
Expand Down
Loading

0 comments on commit df0a81c

Please sign in to comment.