Skip to content

Commit

Permalink
Remove unnecessary "Giganto" prefix
Browse files Browse the repository at this point in the history
Closed #819
  • Loading branch information
henry0715-dev committed Sep 10, 2024
1 parent 5811c47 commit f03a8df
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- Changed command line interface.
- Removed `cert`, `key`, `root` fields from config file.
- Added cli options `-c`, `--cert`, `--key` and `--ca-certs`.
- Changed `setGigantoConfig` to receive toml-string with full configuration.
- Updated `gigantoConfig` to respond full configuration.
- Changed `setConfig` to receive toml-string with full configuration.
- Updated `config` to respond full configuration.

### Removed

Expand Down Expand Up @@ -198,12 +198,12 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Changed

- Modify the `setGigantoConfig` and `gigantoConfig` queries in the GraphQL API
- Modify the `setConfig` and `config` queries in the GraphQL API
to read/write the ack transmission count.
- Modify the `setGigantoConfig` and `gigantoConfig` query in the GraphQL API so
- Modify the `setConfig` and `config` query in the GraphQL API so
that the fields that take integers read/write the config file for their
respective types.
- Modify the `gigantoConfig` query in the GraphQL API so that config files that
- Modify the `config` query in the GraphQL API so that config files that
work in standalone mode can also be read correctly.
- Changed `export` GraphQL API's response value format from `{export_path}` to
`{export_path}@{giganto_node_name}`.
Expand Down
4 changes: 2 additions & 2 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct Query(
export::ExportQuery,
packet::PacketQuery,
timeseries::TimeSeriesQuery,
status::GigantoStatusQuery,
status::StatusQuery,
source::SourceQuery,
statistics::StatisticsQuery,
sysmon::SysmonQuery,
Expand All @@ -66,7 +66,7 @@ pub struct Query(
);

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

#[derive(InputObject, Serialize, Clone)]
pub struct TimeRange {
Expand Down
45 changes: 23 additions & 22 deletions src/graphql/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::info;

use super::{PowerOffNotify, RebootNotify, ReloadNotify, TerminateNotify};
use crate::peer::PeerIdentity;
use crate::settings::GigantoConfig;
use crate::settings::Config;
#[cfg(debug_assertions)]
use crate::storage::Database;
use crate::AckTransmissionCount;
Expand All @@ -28,7 +28,7 @@ pub trait TomlPeers {
}

#[derive(SimpleObject, Debug)]
struct GigantoStatus {
struct Status {
name: String,
cpu_usage: f32,
total_memory: u64,
Expand All @@ -50,7 +50,7 @@ struct Properties {
}

#[Object]
impl GigantoConfig {
impl Config {
async fn ingest_srv_addr(&self) -> String {
self.ingest_srv_addr.to_string()
}
Expand Down Expand Up @@ -120,17 +120,17 @@ impl PeerIdentity {
}

#[derive(Default)]
pub(super) struct GigantoStatusQuery;
pub(super) struct StatusQuery;

#[derive(Default)]
pub(super) struct GigantoConfigMutation;
pub(super) struct ConfigMutation;

#[Object]
impl GigantoStatusQuery {
async fn giganto_status(&self) -> Result<GigantoStatus> {
impl StatusQuery {
async fn status(&self) -> Result<Status> {
let usg = roxy::resource_usage().await;
let hostname = roxy::hostname();
let usg = GigantoStatus {
let usg = Status {
name: hostname,
cpu_usage: usg.cpu_usage,
total_memory: usg.total_memory,
Expand Down Expand Up @@ -161,11 +161,11 @@ impl GigantoStatusQuery {
}

#[allow(clippy::unused_async)]
async fn giganto_config<'ctx>(&self, ctx: &Context<'ctx>) -> Result<GigantoConfig> {
async fn config<'ctx>(&self, ctx: &Context<'ctx>) -> Result<Config> {
let cfg_path = ctx.data::<String>()?;
let toml = fs::read_to_string(cfg_path).context("toml not found")?;

let config: GigantoConfig = toml::from_str(&toml)?;
let config: Config = toml::from_str(&toml)?;

Ok(config)
}
Expand All @@ -177,15 +177,15 @@ impl GigantoStatusQuery {
}

#[Object]
impl GigantoConfigMutation {
impl ConfigMutation {
#[allow(clippy::unused_async)]
async fn set_giganto_config<'ctx>(&self, ctx: &Context<'ctx>, draft: String) -> Result<String> {
let config_draft: GigantoConfig = toml::from_str(&draft)?;
async fn set_config<'ctx>(&self, ctx: &Context<'ctx>, draft: String) -> Result<String> {
let config_draft: Config = toml::from_str(&draft)?;

let cfg_path = ctx.data::<String>()?;

let config_toml = fs::read_to_string(cfg_path).context("toml not found")?;
let config: GigantoConfig = toml::from_str(&config_toml)?;
let config: Config = toml::from_str(&config_toml)?;

if config == config_draft {
info!("No changes. config: {config:?}, draft: {config_draft:?}");
Expand Down Expand Up @@ -341,7 +341,7 @@ mod tests {

let query = r#"
{
gigantoStatus {
status {
name
cpuUsage
totalMemory
Expand All @@ -357,7 +357,7 @@ mod tests {
}

#[tokio::test]
async fn test_giganto_config() {
async fn test_config() {
let dir = tempfile::tempdir().unwrap();
let config_path = dir.path().join("config.toml");

Expand All @@ -370,7 +370,7 @@ mod tests {

let query = r#"
{
gigantoConfig {
config {
ingestSrvAddr
publishSrvAddr
graphqlSrvAddr
Expand All @@ -397,12 +397,13 @@ mod tests {
let data = res.data.to_string();
assert_eq!(
data,
"{gigantoConfig: {ingestSrvAddr: \"0.0.0.0:38370\", publishSrvAddr: \"0.0.0.0:38371\", graphqlSrvAddr: \"127.0.0.1:8442\", dataDir: \"tests/data\", retention: \"3months 8days 16h 19m 12s\", logDir: \"/data/logs/apps\", exportDir: \"tests/export\", ackTransmission: 1024, maxOpenFiles: 8000, maxMbOfLevelBase: \"512\", numOfThread: 8, maxSubCompactions: \"2\", addrToPeers: \"127.0.0.1:48383\", peers: [{addr: \"127.0.0.1:60192\", hostname: \"node2\"}]}}".to_string()
"{config: {ingestSrvAddr: \"0.0.0.0:38370\", publishSrvAddr: \"0.0.0.0:38371\", \
graphqlSrvAddr: \"127.0.0.1:8442\", dataDir: \"tests/data\", retention: \"3months 8days 16h 19m 12s\", logDir: \"/data/logs/apps\", exportDir: \"tests/export\", ackTransmission: 1024, maxOpenFiles: 8000, maxMbOfLevelBase: \"512\", numOfThread: 8, maxSubCompactions: \"2\", addrToPeers: \"127.0.0.1:48383\", peers: [{addr: \"127.0.0.1:60192\", hostname: \"node2\"}]}}".to_string()
);
}

#[tokio::test]
async fn test_set_giganto_config() {
async fn test_set_config() {
let dir = tempfile::tempdir().unwrap();
let config_path = dir.path().join("config.toml");

Expand All @@ -417,7 +418,7 @@ mod tests {
let query = format!(
r#"
mutation {{
setGigantoConfig(draft: {toml_content:?})
setConfig(draft: {toml_content:?})
}}
"#
);
Expand Down Expand Up @@ -450,14 +451,14 @@ mod tests {
let query = format!(
r#"
mutation {{
setGigantoConfig(draft: {new_draft:?})
setConfig(draft: {new_draft:?})
}}
"#
);

let res = schema.execute(&query).await;

assert_eq!(res.data.to_string(), "{setGigantoConfig: \"Done\"}");
assert_eq!(res.data.to_string(), "{setConfig: \"Done\"}");

// check config temp file changes
let config_temp_file =
Expand Down
12 changes: 6 additions & 6 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::{collections::HashSet, net::SocketAddr, path::PathBuf, time::Duration};

use clap::{ArgAction, Parser};
use config::{builder::DefaultState, Config, ConfigBuilder, ConfigError, File};
use config::{builder::DefaultState, Config as ConfConfig, ConfigBuilder, ConfigError, File};
use serde::{de::Error, Deserialize, Deserializer};

use crate::peer::PeerIdentity;
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct Args {

/// The application settings.
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
pub struct GigantoConfig {
pub struct Config {
#[serde(deserialize_with = "deserialize_socket_addr")]
pub ingest_srv_addr: SocketAddr, // IP address & port to ingest data
#[serde(deserialize_with = "deserialize_socket_addr")]
Expand Down Expand Up @@ -74,7 +74,7 @@ pub struct GigantoConfig {

#[derive(Clone, Debug, Deserialize)]
pub struct Settings {
pub config: GigantoConfig,
pub config: Config,

// config file path
pub cfg_path: String,
Expand All @@ -96,7 +96,7 @@ impl Settings {
))
}
} else {
let config: GigantoConfig = default_config_builder().build()?.try_deserialize()?;
let config: Config = default_config_builder().build()?.try_deserialize()?;

Check warning on line 99 in src/settings.rs

View check run for this annotation

Codecov / codecov/patch

src/settings.rs#L99

Added line #L99 was not covered by tests
let cfg_path = config_path.to_str().expect("path to string").to_string();

Ok(Self { config, cfg_path })
Expand All @@ -109,7 +109,7 @@ impl Settings {
let s = default_config_builder()
.add_source(File::with_name(cfg_path))
.build()?;
let config: GigantoConfig = s.try_deserialize()?;
let config: Config = s.try_deserialize()?;

Check warning on line 112 in src/settings.rs

View check run for this annotation

Codecov / codecov/patch

src/settings.rs#L112

Added line #L112 was not covered by tests

Ok(Self {
config,
Expand All @@ -133,7 +133,7 @@ fn default_config_builder() -> ConfigBuilder<DefaultState> {
.to_str()
.expect("unreachable export path");

Config::builder()
ConfConfig::builder()

Check warning on line 136 in src/settings.rs

View check run for this annotation

Codecov / codecov/patch

src/settings.rs#L136

Added line #L136 was not covered by tests
.set_default("ingest_srv_addr", DEFAULT_INGEST_SRV_ADDR)
.expect("valid address")
.set_default("publish_srv_addr", DEFAULT_PUBLISH_SRV_ADDR)
Expand Down

0 comments on commit f03a8df

Please sign in to comment.