-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from nightly-labs/finish-grafana-setup
Finish grafana setup
- Loading branch information
Showing
13 changed files
with
342 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ ENV=DEV # PROD or DEV | |
ONLY_RELAY_SERVICE=FALSE # TRUE - This will start only nightly relay service without cloud service | ||
NONCE=VERY_SECRET_NONCE | ||
MAILER_ADDRESS=[email protected] | ||
# Different than db address specified in infra/.env due to docker shenanigans, used in setting up datasource in grafana | ||
# This is a address of the whole docker interface not just container with database | ||
# Can be found by looking for docker0 entry by sing command ifconfig/ip -a | ||
DATABASE_ADDRESS=172.17.0.1 | ||
GRAFANA_BASE_PATH=http://localhost:3005/api | ||
# TEST LOGIN DO NO USE IN PRODUCTION | ||
GF_SECURITY_ADMIN_USER=admin | ||
|
@@ -10,6 +14,7 @@ GF_SECURITY_ADMIN_PASSWORD=admin | |
# TEST PASSWORD DO NO USE IN PRODUCTION | ||
MAILER_PASSWORD=ZtA5gFKMsXzHmEm | ||
MAILER_ACTIVE=FALSE | ||
|
||
# Generated so it can work with grafana | ||
# ssh-keygen -t rsa -b 4096 -m PEM -f grafana.key -N "" | ||
# openssl rsa -in grafana.key -pubout -outform PEM -out grafana.key.pub | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
server/src/http/cloud/grafana_utils/setup_database_datasource.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::{ | ||
env::DATABASE_ADDRESS, | ||
infra_env::{GRAFANA_DB_USERNAME, POSTGRES_DB}, | ||
statics::POSTGRES_DATASOURCE_UID, | ||
structs::cloud::grafana_error::handle_grafana_error, | ||
}; | ||
use axum::http::StatusCode; | ||
use openapi::{ | ||
apis::{ | ||
configuration::Configuration, | ||
datasources_api::{add_data_source, get_data_source_by_uid}, | ||
}, | ||
models::AddDataSourceCommand, | ||
}; | ||
use std::sync::Arc; | ||
|
||
pub async fn setup_database_datasource( | ||
grafana_conf: &Arc<Configuration>, | ||
) -> Result<(), (StatusCode, String)> { | ||
// Check if datasource already exists, otherwise create it | ||
if let Err(_) = get_data_source_by_uid(grafana_conf, POSTGRES_DATASOURCE_UID).await { | ||
let request_payload = AddDataSourceCommand { | ||
name: Some("Postgres".to_string()), | ||
r#type: Some("postgres".to_string()), | ||
access: Some("proxy".to_string()), | ||
// DATABASE ADDRESS from main env file | ||
url: Some(DATABASE_ADDRESS().to_string()), | ||
database: Some(POSTGRES_DB().to_string()), | ||
user: Some(GRAFANA_DB_USERNAME().to_string()), | ||
basic_auth: None, | ||
with_credentials: Some(false), | ||
is_default: Some(true), | ||
json_data: None, | ||
uid: Some(POSTGRES_DATASOURCE_UID.to_string()), | ||
basic_auth_user: None, | ||
secure_json_data: None, | ||
}; | ||
|
||
match add_data_source(&grafana_conf, request_payload).await { | ||
Ok(_) => return Ok(()), | ||
Err(err) => { | ||
println!("Failed to import database datasource: {:?}", err); | ||
return Err(handle_grafana_error(err)); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.