Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add telemetry support #136

Merged
merged 21 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
051763e
feat(telemetry): add telemetry for CLI metrics
peterwht May 2, 2024
2978904
feat(telemetry): opt-in handler, better error handling and telemetry …
peterwht May 2, 2024
4d48e54
feat(telemetry): add reporting for errors
peterwht May 3, 2024
d8e2c9b
refactor(telemetry): reduce duplicated code, add comments, and genera…
peterwht May 3, 2024
a648e59
refactor(telemetry): refactor new parachain, and telemetry handling
peterwht May 4, 2024
f5a0837
fix(telemetry): fix error telemetry reporting
peterwht May 5, 2024
a6d6764
test(telemetry): unit tests for telemetry
peterwht May 6, 2024
c7c87c2
fix(telemetry): borrowing issue with multi-threads
peterwht May 6, 2024
10b72cf
merge main
peterwht May 6, 2024
449b890
refactor(telemetry): handle tel_data better
peterwht May 7, 2024
1412315
feat(telemetry): add no_telemetry feature flag to disable telemetry
peterwht May 7, 2024
7c1af47
chore: use edition.workspace in toml files
peterwht May 7, 2024
58826bd
chore: miscallaneous cleanups, documentation, and refactoring
peterwht May 7, 2024
6cca585
refactor(telemetry): change opt-in to opt-out
peterwht May 7, 2024
aa3e3ea
chore: cleanup whitespace and comments
peterwht May 7, 2024
c802275
refactor: improve feature (#145)
evilrobot-01 May 8, 2024
04d6e26
Merge branch 'main' into peter/feat-metrics
brunopgalvao May 10, 2024
482e76a
chore(telemetry): update endpoint and website-id
peterwht May 10, 2024
b437503
refactor(telemetry): default values in `Telemetry::new` with helper `…
peterwht May 10, 2024
f0979d6
chore(telemetry): resolve regressions
peterwht May 10, 2024
e14253a
chore: merge main and adapt pop install command
AlexD10S May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
**/node_modules/
/src/x.rs

.DS_Store
.DS_Store

# IDEs
.idea
.vscode
85 changes: 85 additions & 0 deletions Cargo.lock

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

13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ codegen-units = 1
resolver = "2"
members = ["crates/*"]

[workspace.package]
edition = "2021"

[workspace.dependencies]
anyhow = "1.0"
thiserror = "1.0.58"
dirs = "5.0"
env_logger = "0.11.1"
duct = "0.13"
git2 = "0.18"
log = "0.4.20"
mockito = "1.4.0"
tempfile = "3.8"
thiserror = "1.0.58"

# networking
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
url = { version = "2.5" }
peterwht marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -37,7 +47,6 @@ walkdir = "2.4"
indexmap = { version = "2.2" }
toml_edit = { version = "0.22", features = ["serde"] }
symlink = { version = "0.1" }
reqwest = { version = "0.11" }
serde_json = { version = "1.0" }
serde = { version = "1.0", features = ["derive"] }
zombienet-sdk = { git = "https://github.com/r0gue-io/zombienet-sdk", branch = "pop", version = "0.1.0-alpha.1" }
Expand Down
13 changes: 10 additions & 3 deletions crates/pop-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "pop-cli"
description = "An all-in-one tool for Polkadot development."
version = "0.1.0"
edition = "2021"
edition.workspace = true

[[bin]]
name = "pop"
Expand All @@ -11,9 +11,12 @@ path = "src/main.rs"
[dependencies]
anyhow.workspace = true
duct.workspace = true
env_logger.workspace = true
serde.workspace = true
peterwht marked this conversation as resolved.
Show resolved Hide resolved
serde_json.workspace = true
tempfile.workspace = true
url.workspace = true
tokio.workspace = true
url.workspace = true

# pop-cli
clap.workspace = true
Expand All @@ -29,9 +32,12 @@ sp-weights = { workspace = true, optional = true }

# parachains
pop-parachains = { path = "../pop-parachains", optional = true }
dirs = { version = "5.0", optional = true }
dirs = { workspace = true, optional = true }
git2.workspace = true

# telemetry
pop-telemetry = { path = "../pop-telemetry" }

[dev-dependencies]
assert_cmd = "2.0.14"
predicates = "3.1.0"
Expand All @@ -52,4 +58,5 @@ parachain = [
]
e2e_parachain = []
unit_parachain = []
no_telemetry = []

1 change: 1 addition & 0 deletions crates/pop-cli/src/commands/new/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl NewContractCommand {
let spinner = cliclack::spinner();
spinner.start("Generating contract...");
create_smart_contract(&self.name, contract_path.as_path())?;

spinner.stop("Smart contract created!");
outro(format!("cd into \"{}\" and enjoy hacking! 🚀", contract_path.display()))?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/pop-cli/src/commands/new/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl NewPalletCommand {
description: self.description.clone().expect("default values"),
},
)?;

spinner.stop("Generation complete");
outro(format!("cd into \"{}\" and enjoy hacking! 🚀", &self.name))?;
Ok(())
Expand Down
84 changes: 47 additions & 37 deletions crates/pop-cli/src/commands/new/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cliclack::{clear_screen, confirm, input, intro, log, outro, outro_cancel, se
use pop_parachains::{instantiate_template_dir, Config, Git, GitHub, Provider, Release, Template};
use strum::VariantArray;

#[derive(Args)]
#[derive(Args, Clone)]
pub struct NewParachainCommand {
#[arg(help = "Name of the project. If empty assistance in the process will be provided.")]
pub(crate) name: Option<String>,
Expand All @@ -32,6 +32,12 @@ pub struct NewParachainCommand {
value_parser = crate::enum_variants!(Template)
)]
pub(crate) template: Option<Template>,
#[arg(
short = 'r',
long,
help = "Release tag to use for template. If empty, latest release will be used."
)]
pub(crate) release_tag: Option<String>,
#[arg(long, short, help = "Token Symbol", default_value = "UNIT")]
pub(crate) symbol: Option<String>,
#[arg(long, short, help = "Token Decimals", default_value = "12")]
Expand All @@ -43,12 +49,6 @@ pub struct NewParachainCommand {
default_value = "1u64 << 60"
)]
pub(crate) initial_endowment: Option<String>,
#[arg(
short = 'p',
long,
help = "Path for the parachain project, [default: current directory]"
)]
pub(crate) path: Option<PathBuf>,
AlexD10S marked this conversation as resolved.
Show resolved Hide resolved
}

#[macro_export]
Expand All @@ -67,35 +67,43 @@ macro_rules! enum_variants {
}

impl NewParachainCommand {
pub(crate) async fn execute(&self) -> Result<()> {
pub(crate) async fn execute(&self) -> Result<Template> {
clear_screen()?;
set_theme(Theme);

return match &self.name {
let parachain_config = if self.name.is_none() {
// If user doesn't select the name guide them to generate a parachain.
peterwht marked this conversation as resolved.
Show resolved Hide resolved
None => guide_user_to_generate_parachain().await,
Some(name) => {
let provider = &self.provider.clone().unwrap_or_default();
let template = match &self.template {
Some(template) => template.clone(),
None => provider.default_template(), // Each provider has a template by default
};

is_template_supported(provider, &template)?;
let config = get_customization_value(
&template,
self.symbol.clone(),
self.decimals,
self.initial_endowment.clone(),
)?;

generate_parachain_from_template(name, provider, &template, None, config)
},
guide_user_to_generate_parachain().await?
} else {
self.clone()
};

let name = &parachain_config
.name
.clone()
.expect("name can not be none as fallback above is interactive input; qed");
let provider = &parachain_config.provider.clone().unwrap_or_default();
let template = match &parachain_config.template {
Some(template) => template.clone(),
None => provider.default_template(), // Each provider has a template by default
};

is_template_supported(provider, &template)?;
let config = get_customization_value(
&template,
parachain_config.symbol.clone(),
parachain_config.decimals,
parachain_config.initial_endowment.clone(),
)?;

let tag_version = parachain_config.release_tag.clone();

generate_parachain_from_template(name, provider, &template, tag_version, config)?;
Ok(template)
}
}

async fn guide_user_to_generate_parachain() -> Result<()> {
async fn guide_user_to_generate_parachain() -> Result<NewParachainCommand> {
intro(format!("{}: Generate a parachain", style(" Pop CLI ").black().on_magenta()))?;

let mut prompt = cliclack::select("Select a template provider: ".to_string());
Expand Down Expand Up @@ -141,15 +149,16 @@ async fn guide_user_to_generate_parachain() -> Result<()> {

clear_screen()?;

generate_parachain_from_template(
&name,
&provider,
&template,
release_name,
customizable_options,
)
Ok(NewParachainCommand {
name: Some(name),
provider: Some(provider.clone()),
template: Some(template.clone()),
release_tag: release_name,
symbol: Some(customizable_options.symbol),
decimals: Some(customizable_options.decimals),
initial_endowment: Some(customizable_options.initial_endowment),
})
}

fn generate_parachain_from_template(
name_template: &String,
provider: &Provider,
Expand All @@ -164,6 +173,7 @@ fn generate_parachain_from_template(
template,
provider
))?;

let destination_path = check_destination_path(name_template)?;

let spinner = cliclack::spinner();
Expand Down Expand Up @@ -330,10 +340,10 @@ mod tests {
name: Some(dir.path().join("test_parachain").to_str().unwrap().to_string()),
provider: Some(Provider::Pop),
template: Some(Template::Base),
release_tag: None,
symbol: Some("UNIT".to_string()),
decimals: Some(12),
initial_endowment: Some("1u64 << 60".to_string()),
path: None,
};
command.execute().await?;

Expand Down
Loading
Loading