Skip to content

Commit

Permalink
feat(telemetry): add telemetry data point when checking license (#18371)
Browse files Browse the repository at this point in the history
Signed-off-by: tabVersion <[email protected]>
  • Loading branch information
tabVersion authored Sep 3, 2024
1 parent 51d3c63 commit c519f0d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions src/license/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ ignored = ["workspace-hack"]
normal = ["workspace-hack"]

[dependencies]
jsonbb = { workspace = true }
jsonwebtoken = "9"
risingwave_pb = { workspace = true }
risingwave_telemetry_event = { workspace = true }
serde = { version = "1", features = ["derive"] }
thiserror = "1"
thiserror-ext = { workspace = true }
Expand Down
18 changes: 15 additions & 3 deletions src/license/src/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use thiserror::Error;

use super::{License, LicenseKeyError, LicenseManager, Tier};
use super::{report_telemetry, License, LicenseKeyError, LicenseManager, Tier};

/// Define all features that are available based on the tier of the license.
///
Expand Down Expand Up @@ -84,6 +84,14 @@ macro_rules! def_feature {
)*
}
}

fn get_feature_name(&self) -> &'static str {
match &self {
$(
Self::$name => stringify!($name),
)*
}
}
}
};
}
Expand Down Expand Up @@ -113,7 +121,7 @@ pub enum FeatureNotAvailable {
impl Feature {
/// Check whether the feature is available based on the current license.
pub fn check_available(self) -> Result<(), FeatureNotAvailable> {
match LicenseManager::get().license() {
let check_res = match LicenseManager::get().license() {
Ok(license) => {
if license.tier >= self.min_tier() {
Ok(())
Expand All @@ -136,6 +144,10 @@ impl Feature {
})
}
}
}
};

report_telemetry(&self, self.get_feature_name(), check_res.is_ok());

check_res
}
}
23 changes: 23 additions & 0 deletions src/license/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,26 @@ mod manager;
pub use feature::*;
pub use key::*;
pub use manager::*;
use risingwave_pb::telemetry::PbTelemetryEventStage;
use risingwave_telemetry_event::report_event_common;

pub(crate) fn report_telemetry(feature: &Feature, feature_name: &str, success_flag: bool) {
if matches!(feature, Feature::TestPaid) {
let mut attr_builder = jsonbb::Builder::<Vec<u8>>::new();
attr_builder.begin_object();
attr_builder.add_string("success");
attr_builder.add_value(jsonbb::ValueRef::Bool(success_flag));
attr_builder.end_object();
let attr = attr_builder.finish();

report_event_common(
PbTelemetryEventStage::Unspecified,
feature_name,
0,
None,
None,
Some(attr),
"paywall".to_string(),
);
}
}

0 comments on commit c519f0d

Please sign in to comment.