Skip to content

Commit

Permalink
Add test to confirm known bug (#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed May 2, 2024
1 parent 0b78252 commit ccd5f08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
27 changes: 22 additions & 5 deletions opentelemetry-sdk/src/metrics/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,28 @@ where
mod tests {
use std::sync::Arc;

use opentelemetry::metrics::{InstrumentProvider, MetricsError, Unit};
use opentelemetry::metrics::{InstrumentProvider, MeterProvider, MetricsError, Unit};

use super::{
InstrumentValidationPolicy, SdkMeter, INSTRUMENT_NAME_FIRST_ALPHABETIC,
INSTRUMENT_NAME_INVALID_CHAR, INSTRUMENT_NAME_LENGTH, INSTRUMENT_UNIT_INVALID_CHAR,
INSTRUMENT_UNIT_LENGTH,
};
use crate::{metrics::pipeline::Pipelines, Resource, Scope};
use crate::{
metrics::{pipeline::Pipelines, SdkMeterProvider},
Resource, Scope,
};

#[test]
#[ignore = "See issue https://github.com/open-telemetry/opentelemetry-rust/issues/1699"]
fn test_instrument_creation() {
let provider = SdkMeterProvider::builder().build();
let meter = provider.meter("test");
assert!(meter.u64_counter("test").try_init().is_ok());
let result = meter.u64_counter("test with invalid name").try_init();
// this assert fails, as result is always ok variant.
assert!(result.is_err());
}

#[test]
fn test_instrument_config_validation() {
Expand All @@ -787,9 +801,9 @@ mod tests {
("a".repeat(255).leak(), ""),
("a".repeat(256).leak(), INSTRUMENT_NAME_LENGTH),
("invalid name", INSTRUMENT_NAME_INVALID_CHAR),
// hyphens are now valid characters in the specification.
// https://github.com/open-telemetry/opentelemetry-specification/pull/3684
("allow/hyphen", ""),
("allow/slash", ""),
("allow_under_score", ""),
("allow.dots.ok", ""),
];
for (name, expected_error) in instrument_name_test_cases {
let assert = |result: Result<_, MetricsError>| {
Expand Down Expand Up @@ -865,6 +879,9 @@ mod tests {
),
("utf8char锈", INSTRUMENT_UNIT_INVALID_CHAR),
("kb", ""),
("Kb/sec", ""),
("%", ""),
("", ""),
];

for (unit, expected_error) in instrument_unit_test_cases {
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry/src/metrics/noop.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! # No-op OpenTelemetry Metrics Implementation
//!
//! This implementation is returned as the global Meter if no `Meter`
//! has been set. It is also useful for testing purposes as it is intended
//! to have minimal resource utilization and runtime impact.
//! This implementation is returned as the global Meter if no `MeterProvider`
//! has been set. It is expected to have minimal resource utilization and
//! runtime impact.
use crate::{
metrics::{
AsyncInstrument, CallbackRegistration, InstrumentProvider, Meter, MeterProvider, Observer,
Expand Down

0 comments on commit ccd5f08

Please sign in to comment.