// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/.
mod common; usecrate::common::*;
use std::collections::HashMap; use std::io::Read;
use flate2::read::GzDecoder; use jsonschema_valid::schemas::Draft; use serde_json::Value;
use glean::net::{CapablePingUploadRequest, UploadResult}; use glean::private::*; use glean::{
traits, ClientInfoMetrics, CommonMetricData, ConfigurationBuilder, HistogramType, MemoryUnit,
TimeUnit,
};
let common = |name: &str| CommonMetricData {
category: "test".into(),
name: name.into(),
send_in_pings: vec![PING_NAME.into()],
..Default::default()
};
// 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 counter_metric = CounterMetric::new(common("counter"));
counter_metric.add(42);
let bool_metric = BooleanMetric::new(common("bool"));
bool_metric.set(true);
let string_metric = StringMetric::new(common("string"));
string_metric.set("test".into());
let stringlist_metric = StringListMetric::new(common("stringlist"));
stringlist_metric.add("one".into());
stringlist_metric.add("two".into());
// Let's make sure an empty array is accepted. let stringlist_metric2 = StringListMetric::new(common("stringlist2"));
stringlist_metric2.set(vec![]);
let timespan_metric = TimespanMetric::new(common("timespan"), TimeUnit::Nanosecond);
timespan_metric.start();
timespan_metric.stop();
let timing_dist = TimingDistributionMetric::new(common("timing_dist"), TimeUnit::Nanosecond); let id = timing_dist.start();
timing_dist.stop_and_accumulate(id);
let memory_dist = MemoryDistributionMetric::new(common("memory_dist"), MemoryUnit::Byte);
memory_dist.accumulate(100);
let uuid_metric = UuidMetric::new(common("uuid")); // chosen by fair dic roll (`uuidgen`)
uuid_metric.set("3ee4db5f-ee26-4557-9a66-bc7425d7893f".into());
// We can't test the URL metric, // because the regex used in the schema uses a negative lookahead, // which the regex crate doesn't handle. // //let url_metric = UrlMetric::new(common("url")); //url_metric.set("https://mozilla.github.io/glean/");
let datetime_metric = DatetimeMetric::new(common("datetime"), TimeUnit::Day);
datetime_metric.set(None);
let custom_dist =
CustomDistributionMetric::new(common("custom_dist"), 1, 100, 100, HistogramType::Linear);
custom_dist.accumulate_samples(vec![50, 51]);
let quantity_metric = QuantityMetric::new(common("quantity"));
quantity_metric.set(0);
let rate_metric = RateMetric::new(common("rate"));
rate_metric.add_to_numerator(1);
rate_metric.add_to_denominator(1);
let numerator_metric1 = NumeratorMetric::new(common("num1")); let numerator_metric2 = NumeratorMetric::new(common("num2")); let denominator_metric =
DenominatorMetric::new(common("den"), vec![common("num1"), common("num2")]);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.