Skip to content

Commit

Permalink
Add database file export graphql function
Browse files Browse the repository at this point in the history
Closes: #224
  • Loading branch information
Hanbeom kim authored and msk committed Jan 4, 2023
1 parent 3ae2fca commit a81cd47
Show file tree
Hide file tree
Showing 14 changed files with 1,914 additions and 73 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Add export file to GraphQL API. (`csv`, `json` format support)
- Add `Statistics` column family. Receive and save traffic statistics from Piglet.
- Save Giganto's `syslog` to a path written to `log_dir` in configuration file.
- Add `Operationlog`
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ rustls = "0.20"
rustls-pemfile = "1.0"
semver = "1.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tracing = "0.1"
tracing-appender ="0.2"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ In the config file, you can specify the following options:
key = "key.pem" # path to private key file
cert = "cert.pem" # path to certificate file
roots = ["ca1.pem", "ca2.pem", "ca3.pem"] # paths to CA certificate files
ingestion_address = "0.0.0.0:38370" # address to listen for QUIC connections
ingestion_address = "0.0.0.0:38370" # address to listen for ingestion QUIC
publish_address = "0.0.0.0:38371" # address to listen for publish QUIC
data_dir = "tests/data" # path to directory to store data
retention = "100d" # retention period for data
log_dir = "tests/logs/apps" # path to giganto's syslog file
export_dir = "tests/export" # path to giganto's export file
```

By default, giganto reads the config file from the following directories:
Expand Down
10 changes: 7 additions & 3 deletions src/graphql.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod export;
mod log;
pub mod network;
mod packet;
Expand All @@ -17,7 +18,7 @@ use async_graphql::{
};
use chrono::{DateTime, TimeZone, Utc};
use serde::{de::DeserializeOwned, Serialize};
use std::net::IpAddr;
use std::{net::IpAddr, path::PathBuf};

use self::network::NetworkFilter;

Expand All @@ -27,6 +28,7 @@ pub const TIMESTAMP_SIZE: usize = 8;
pub struct Query(
log::LogQuery,
network::NetworkQuery,
export::ExportQuery,
packet::PacketQuery,
timeseries::TimeSeriesQuery,
);
Expand Down Expand Up @@ -58,10 +60,11 @@ pub trait FromKeyValue<T>: Sized {
pub type Schema = async_graphql::Schema<Query, EmptyMutation, EmptySubscription>;
type ConnArgs<T> = (Vec<(Box<[u8]>, T)>, bool, bool);

pub fn schema(database: Database, packet_sources: PacketSources) -> Schema {
pub fn schema(database: Database, packet_sources: PacketSources, export_path: PathBuf) -> Schema {
Schema::build(Query::default(), EmptyMutation, EmptySubscription)
.data(database)
.data(packet_sources)
.data(export_path)
.finish()
}

Expand Down Expand Up @@ -339,7 +342,8 @@ impl TestSchema {
let db_dir = tempfile::tempdir().unwrap();
let db = Database::open(db_dir.path()).unwrap();
let packet_sources = Arc::new(RwLock::new(HashMap::new()));
let schema = schema(db.clone(), packet_sources);
let export_dir = tempfile::tempdir().unwrap();
let schema = schema(db.clone(), packet_sources, export_dir.path().to_path_buf());
Self {
_dir: db_dir,
db,
Expand Down
Loading

0 comments on commit a81cd47

Please sign in to comment.