Skip to content

Commit 28bd623

Browse files
dantengskyBohuTANG
andauthored
chore: improve license validation log message (#17967)
* chore: improve license validation log message Change license validation error log to ERROR level. Several enterprise features don't affect functional correctness but impact performance significantly. Users have experienced unexplained performance degradation due to expired licenses. This change helps users identify such issues faster. * improve the license error message * tweak log msg --------- Co-authored-by: BohuTANG <[email protected]>
1 parent acad5a2 commit 28bd623

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

src/query/ee/src/license/license_mgr.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,29 @@ impl RealLicenseManager {
5151
fn parse_license_impl(&self, raw: &str) -> Result<JWTClaims<LicenseInfo>> {
5252
for public_key in &self.public_keys {
5353
let public_key = ES256PublicKey::from_pem(public_key)
54-
.map_err_to_code(ErrorCode::LicenseKeyParseError, || "public key load failed")?;
54+
.map_err_to_code(ErrorCode::LicenseKeyParseError, || {
55+
"[LicenseManager] Public key load failed"
56+
})?;
5557

5658
return match public_key.verify_token::<LicenseInfo>(raw, None) {
5759
Ok(v) => Ok(v),
5860
Err(cause) => match cause.downcast_ref::<JWTError>() {
59-
Some(JWTError::TokenHasExpired) => {
60-
warn!("License expired");
61-
Err(ErrorCode::LicenseKeyExpired("license key is expired."))
62-
}
61+
Some(JWTError::TokenHasExpired) => Err(ErrorCode::LicenseKeyExpired(
62+
"[LicenseManager] License key is expired",
63+
)),
6364
Some(JWTError::InvalidSignature) => {
6465
continue;
6566
}
66-
_ => Err(ErrorCode::LicenseKeyParseError("jwt claim decode failed")),
67+
_ => Err(ErrorCode::LicenseKeyParseError(
68+
"[LicenseManager] JWT claim decode failed",
69+
)),
6770
},
6871
};
6972
}
7073

71-
Err(ErrorCode::LicenseKeyParseError("wt claim decode failed"))
74+
Err(ErrorCode::LicenseKeyParseError(
75+
"[LicenseManager] JWT claim decode failed",
76+
))
7277
}
7378
}
7479

@@ -107,8 +112,8 @@ impl LicenseManager for RealLicenseManager {
107112
fn check_enterprise_enabled(&self, license_key: String, feature: Feature) -> Result<()> {
108113
if license_key.is_empty() {
109114
return feature.verify_default(format!(
110-
"The use of this feature requires a Databend Enterprise Edition license. No license key found for tenant: {}. To unlock enterprise features, please contact Databend to obtain a license. Learn more at {}",
111-
self.tenant, LICENSE_URL
115+
"[LicenseManager] Feature '{}' requires Databend Enterprise Edition license. No license key found for tenant: {}. Learn more at {}",
116+
feature, self.tenant, LICENSE_URL
112117
));
113118
}
114119

@@ -134,8 +139,10 @@ impl LicenseManager for RealLicenseManager {
134139
// Previously cached valid license might be expired
135140
let claim = v.value();
136141
if Self::verify_license_expired(claim)? {
137-
warn!("Cached License expired");
138-
Err(ErrorCode::LicenseKeyExpired("license key is expired."))
142+
warn!("[LicenseManager] Cached license expired");
143+
Err(ErrorCode::LicenseKeyExpired(
144+
"[LicenseManager] License key is expired.",
145+
))
139146
} else {
140147
Ok((*claim).clone())
141148
}
@@ -154,7 +161,7 @@ impl LicenseManager for RealLicenseManager {
154161
if let Some(v) = self.cache.get(&license_key) {
155162
if Self::verify_license_expired(v.value())? {
156163
return Err(ErrorCode::LicenseKeyExpired(format!(
157-
"license key expired in {:?}",
164+
"[LicenseManager] License key expired at {:?}",
158165
v.value().expires_at,
159166
)));
160167
}
@@ -163,12 +170,12 @@ impl LicenseManager for RealLicenseManager {
163170

164171
let license = self.parse_license(&license_key).map_err_to_code(
165172
ErrorCode::LicenseKeyInvalid,
166-
|| format!("use of storage requires an enterprise license. current license is invalid for {}", self.tenant),
173+
|| format!("[LicenseManager] Storage use requires enterprise license. Current license invalid for tenant: {}", self.tenant),
167174
)?;
168175

169176
if Self::verify_license_expired(&license)? {
170177
return Err(ErrorCode::LicenseKeyExpired(format!(
171-
"license key expired in {:?}",
178+
"[LicenseManager] License key expired at {:?}",
172179
license.expires_at,
173180
)));
174181
}
@@ -194,7 +201,7 @@ impl RealLicenseManager {
194201
match l.expires_at {
195202
Some(expire_at) => Ok(now > expire_at),
196203
None => Err(ErrorCode::LicenseKeyInvalid(
197-
"cannot find valid expire time",
204+
"[LicenseManager] Cannot find valid expiration time",
198205
)),
199206
}
200207
}
@@ -216,7 +223,7 @@ impl RealLicenseManager {
216223
}
217224

218225
Err(ErrorCode::LicenseKeyInvalid(format!(
219-
"license key does not support feature {}, supported features: {}",
226+
"[LicenseManager] License does not support feature: {}. Supported features: {}",
220227
feature,
221228
l.custom.display_features()
222229
)))
@@ -225,8 +232,8 @@ impl RealLicenseManager {
225232
fn verify_if_expired(&self, feature: Feature) -> Result<()> {
226233
feature.verify_default("").map_err(|_|
227234
ErrorCode::LicenseKeyExpired(format!(
228-
"The use of this feature requires a Databend Enterprise Edition license. License key has expired for tenant: {}. To unlock enterprise features, please contact Databend to obtain a license. Learn more at https://docs.databend.com/guides/products/dee/",
229-
self.tenant
235+
"[LicenseManager] Feature '{}' requires Databend Enterprise Edition license. License key expired for tenant: {}. Learn more at {}",
236+
feature, self.tenant, LICENSE_URL
230237
))
231238
)
232239
}
@@ -245,12 +252,12 @@ fn embedded_public_keys() -> Result<String> {
245252

246253
match decode_res {
247254
Err(e) => Err(ErrorCode::Internal(format!(
248-
"Cannot parse embedded public key {:?}",
255+
"[LicenseManager] Cannot parse embedded public key: {:?}",
249256
e
250257
))),
251258
Ok(bytes) => match String::from_utf8(bytes) {
252259
Err(e) => Err(ErrorCode::Internal(format!(
253-
"Cannot parse embedded public key {:?}",
260+
"[LicenseManager] Cannot parse embedded public key: {:?}",
254261
e
255262
))),
256263
Ok(keys) => Ok(keys),

src/query/service/src/interpreters/interpreter.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,20 @@ pub trait Interpreter: Sync + Send {
103103
ctx.set_status_info("building pipeline");
104104
ctx.check_aborting().with_context(make_error)?;
105105

106-
CacheManager::instance().set_allows_disk_cache(
107-
LicenseManagerSwitch::instance().is_license_valid(ctx.get_license_key()),
108-
);
106+
let enable_disk_cache = match LicenseManagerSwitch::instance()
107+
.check_license(ctx.get_license_key())
108+
{
109+
Ok(_) => true,
110+
Err(e) => {
111+
log::error!(
112+
"[Interpreter] CRITICAL ALERT: License validation FAILED - enterprise features DISABLED, System may operate in DEGRADED MODE with LIMITED CAPABILITIES and REDUCED PERFORMANCE. Please contact us at https://www.databend.com/contact-us/ or email [email protected] to restore full functionality: {}",
113+
e
114+
);
115+
false
116+
}
117+
};
118+
119+
CacheManager::instance().set_allows_disk_cache(enable_disk_cache);
109120

110121
let mut build_res = match self.execute2().await {
111122
Ok(build_res) => build_res,
@@ -179,7 +190,7 @@ fn log_query_start(ctx: &QueryContext) {
179190
}
180191

181192
if let Err(error) = InterpreterQueryLog::log_start(ctx, now, None) {
182-
error!("interpreter.start.error: {:?}", error)
193+
error!("[Interpreter] Query start logging failed: {:?}", error)
183194
}
184195
}
185196

@@ -206,7 +217,7 @@ fn log_query_finished(ctx: &QueryContext, error: Option<ErrorCode>, has_profiles
206217
}
207218

208219
if let Err(error) = InterpreterQueryLog::log_finish(ctx, now, error, has_profiles) {
209-
error!("interpreter.finish.error: {:?}", error)
220+
error!("[Interpreter] Query finish logging failed: {:?}", error)
210221
}
211222
}
212223

0 commit comments

Comments
 (0)