Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 57 additions & 2 deletions glean-core/rlb/tests/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use flate2::read::GzDecoder;
use jsonschema_valid::{self, schemas::Draft};
use serde_json::Value;

use glean::{ClientInfoMetrics, Configuration};
use glean::private::{DenominatorMetric, NumeratorMetric, RateMetric};
use glean::{ClientInfoMetrics, CommonMetricData, Configuration};

const SCHEMA_JSON: &str = include_str!("../../../glean.1.schema.json");

Expand Down Expand Up @@ -88,8 +89,62 @@ fn validate_against_schema() {
};
let _ = new_glean(Some(cfg));

// Define a new ping and submit it.
const PING_NAME: &str = "test-ping";

// Test each of the metric types, just for basic smoke testing against the
// schema

// TODO: 1695762 Test all of the metric types against the schema from Rust

let rate_metric: RateMetric = RateMetric::new(CommonMetricData {
category: "test".into(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the category first so I can read it in the same order ( test.rate ) that it appears in the payload?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing.

name: "rate".into(),
send_in_pings: vec![PING_NAME.into()],
..Default::default()
});
rate_metric.add_to_numerator(1);
rate_metric.add_to_denominator(1);

let numerator_metric1: NumeratorMetric = NumeratorMetric::new(CommonMetricData {
category: "test".into(),
name: "num1".into(),
send_in_pings: vec![PING_NAME.into()],
..Default::default()
});
let numerator_metric2: NumeratorMetric = NumeratorMetric::new(CommonMetricData {
category: "test".into(),
name: "num2".into(),
send_in_pings: vec![PING_NAME.into()],
..Default::default()
});
let denominator_metric: DenominatorMetric = DenominatorMetric::new(
CommonMetricData {
category: "test".into(),
name: "den".into(),
send_in_pings: vec![PING_NAME.into()],
..Default::default()
},
vec![
CommonMetricData {
category: "test".into(),
name: "num1".into(),
send_in_pings: vec![PING_NAME.into()],
..Default::default()
},
CommonMetricData {
category: "test".into(),
name: "num2".into(),
send_in_pings: vec![PING_NAME.into()],
..Default::default()
},
],
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chutten pointed out in Matrix that maybe we should document how to make these in the developer docs. First, to confirm that this is correct, though...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me.


numerator_metric1.add_to_numerator(1);
numerator_metric2.add_to_numerator(2);
denominator_metric.add(3);

// Define a new ping and submit it.
let custom_ping = glean::private::PingType::new(PING_NAME, true, true, vec![]);
custom_ping.submit(None);

Expand Down
66 changes: 60 additions & 6 deletions glean.1.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,57 @@
"additionalProperties": false,
"properties": {
"android_sdk_version": {
"description": "The optional Android specific SDK version of the software running on this hardware device.",
"type": "string"
},
"app_build": {
"description": "The build identifier generated by the CI system (e.g. \"1234/A\"). For language bindings that provide automatic detection for this value, (e.g. Android/Kotlin), in the unlikely event that the build identifier can not be retrieved from the OS, it is set to \"inaccessible\". For other language bindings, if the value was not provided through configuration, this metric gets set to `Unknown`.",
"type": "string"
},
"app_channel": {
"description": "The channel the application is being distributed on.",
"type": "string"
},
"app_display_version": {
"description": "The user visible version string (e.g. \"1.0.3\"). In the unlikely event that the display version can not be retrieved, it is set to \"inaccessible\".",
"type": "string"
},
"architecture": {
"description": "The architecture of the device, (e.g. \"arm\", \"x86\").",
"type": "string"
},
"client_id": {
"description": "A UUID uniquely identifying the client.",
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
"type": "string"
},
"device_manufacturer": {
"description": "The manufacturer of the device the application is running on. Not set if the device manufacturer can't be determined (e.g. on Desktop).",
"type": "string"
},
"device_model": {
"description": "The model of the device the application is running on. On Android, this is Build.MODEL, the user-visible marketing name, like \"Pixel 2 XL\". Not set if the device model can't be determined (e.g. on Desktop).",
"type": "string"
},
"first_run_date": {
"description": "The date of the first run of the application.",
"format": "datetime",
"type": "string"
},
"locale": {
"description": "The locale of the application during initialization (e.g. \"es-ES\"). If the locale can't be determined on the system, the value is [\"und\"](https://unicode.org/reports/tr35/#Unknown_or_Invalid_Identifiers), to indicate \"undetermined\".",
"type": "string"
},
"os": {
"description": "The name of the operating system. Possible values: Android, iOS, Linux, Darwin, Windows, FreeBSD, NetBSD, OpenBSD, Solaris, unknown",
"type": "string"
},
"os_version": {
"description": "The user-visible version of the operating system (e.g. \"1.2.3\"). If the version detection fails, this metric gets set to `Unknown`.",
"type": "string"
},
"telemetry_sdk_build": {
"description": "The version of the Glean SDK",
"type": "string"
}
},
Expand Down Expand Up @@ -136,7 +149,7 @@
"type": "integer"
},
"propertyNames": {
"pattern": "[0-9]+"
"pattern": "^[0-9]+$"
},
"type": "object"
}
Expand Down Expand Up @@ -177,6 +190,17 @@
},
"type": "object"
},
"jwe": {
"additionalProperties": {
"type": "string"
},
"propertyNames": {
"maxLength": 61,
"pattern": "^[a-z_][a-z0-9_]{0,29}(\\.[a-z_][a-z0-9_]{0,29})+$",
"type": "string"
},
"type": "object"
},
"labeled_boolean": {
"additionalProperties": {
"additionalProperties": {
Expand Down Expand Up @@ -276,7 +300,22 @@
"labeled_rate": {
"additionalProperties": {
"additionalProperties": {
"type": "integer"
"additionalProperties": false,
"properties": {
"denominator": {
"minimum": 0,
"type": "integer"
},
"numerator": {
"minimum": 0,
"type": "integer"
}
},
"required": [
"numerator",
"denominator"
],
"type": "object"
},
"propertyNames": {
"comment": "This must be at least the length of 'category.name' metric names to support error reporting",
Expand Down Expand Up @@ -381,7 +420,7 @@
"type": "integer"
},
"propertyNames": {
"pattern": "[0-9]+"
"pattern": "^[0-9]+$"
},
"type": "object"
}
Expand Down Expand Up @@ -500,7 +539,7 @@
"type": "integer"
},
"propertyNames": {
"pattern": "[0-9]+"
"pattern": "^[0-9]+$"
},
"type": "object"
}
Expand Down Expand Up @@ -541,7 +580,22 @@
},
"rate": {
"additionalProperties": {
"type": "integer"
"additionalProperties": false,
"properties": {
"denominator": {
"minimum": 0,
"type": "integer"
},
"numerator": {
"minimum": 0,
"type": "integer"
}
},
"required": [
"numerator",
"denominator"
],
"type": "object"
},
"propertyNames": {
"maxLength": 61,
Expand Down Expand Up @@ -654,7 +708,7 @@
"type": "integer"
},
"propertyNames": {
"pattern": "[0-9]+"
"pattern": "^[0-9]+$"
},
"type": "object"
}
Expand Down