Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preview feature-flag/macro for metrics #745

Merged
merged 7 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 5 additions & 3 deletions api/include/opentelemetry/metrics/async_instruments.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#ifdef ENABLE_METRICS_PREVIEW
# pragma once
lalitb marked this conversation as resolved.
Show resolved Hide resolved

#include "instrument.h"
#include "observer_result.h"
# include "instrument.h"
# include "observer_result.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
Expand Down Expand Up @@ -81,3 +82,4 @@ class UpDownSumObserver : virtual public AsynchronousInstrument<T>

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
14 changes: 8 additions & 6 deletions api/include/opentelemetry/metrics/instrument.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once
#ifdef ENABLE_METRIC_PREVIEW
# pragma once

#include <iostream>
#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
# include <iostream>
# include "opentelemetry/common/attribute_value.h"
# include "opentelemetry/common/key_value_iterable_view.h"
# include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/nostd/string_view.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
Expand Down Expand Up @@ -202,3 +203,4 @@ class AsynchronousInstrument : virtual public Instrument

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
18 changes: 10 additions & 8 deletions api/include/opentelemetry/metrics/meter.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once
#ifdef ENABLE_METRIC_PREVIEW
# pragma once

#include "opentelemetry/metrics/async_instruments.h"
#include "opentelemetry/metrics/instrument.h"
#include "opentelemetry/metrics/sync_instruments.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"
# include "opentelemetry/metrics/async_instruments.h"
# include "opentelemetry/metrics/instrument.h"
# include "opentelemetry/metrics/sync_instruments.h"
# include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/nostd/span.h"
# include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
Expand Down Expand Up @@ -281,3 +282,4 @@ class Meter
};
} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
10 changes: 6 additions & 4 deletions api/include/opentelemetry/metrics/meter_provider.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once
#ifdef ENABLE_METRIC_PREVIEW
# pragma once

#include "opentelemetry/metrics/meter.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/metrics/meter.h"
# include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/nostd/string_view.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
Expand All @@ -25,3 +26,4 @@ class MeterProvider
};
} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
22 changes: 12 additions & 10 deletions api/include/opentelemetry/metrics/noop.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#pragma once
#ifdef ENABLE_METRIC_PREVIEW
# pragma once
// Please refer to provider.h for documentation on how to obtain a Meter object.
//
// This file is part of the internal implementation of OpenTelemetry. Nothing in this file should be
// used directly. Please refer to meter.h for documentation on these interfaces.

#include "opentelemetry/metrics/async_instruments.h"
#include "opentelemetry/metrics/instrument.h"
#include "opentelemetry/metrics/meter.h"
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/metrics/sync_instruments.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/version.h"
# include "opentelemetry/metrics/async_instruments.h"
# include "opentelemetry/metrics/instrument.h"
# include "opentelemetry/metrics/meter.h"
# include "opentelemetry/metrics/meter_provider.h"
# include "opentelemetry/metrics/sync_instruments.h"
# include "opentelemetry/nostd/string_view.h"
# include "opentelemetry/nostd/unique_ptr.h"
# include "opentelemetry/version.h"

#include <memory>
# include <memory>

// TODO: Create generic short pattern for opentelemetry::common and opentelemetry::trace and others
// as necessary
Expand Down Expand Up @@ -647,3 +648,4 @@ class NoopMeterProvider final : public opentelemetry::metrics::MeterProvider
};
} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
8 changes: 5 additions & 3 deletions api/include/opentelemetry/metrics/observer_result.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once
#ifdef ENABLE_METRIC_PREVIEW
# pragma once

#include "instrument.h"
#include "opentelemetry/nostd/shared_ptr.h"
# include "instrument.h"
# include "opentelemetry/nostd/shared_ptr.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
Expand Down Expand Up @@ -34,3 +35,4 @@ class ObserverResult

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
14 changes: 8 additions & 6 deletions api/include/opentelemetry/metrics/provider.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once
#ifdef ENABLE_METRIC_PREVIEW
# pragma once

#include <mutex>
# include <mutex>

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/metrics/noop.h"
#include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/common/spin_lock_mutex.h"
# include "opentelemetry/metrics/meter_provider.h"
# include "opentelemetry/metrics/noop.h"
# include "opentelemetry/nostd/shared_ptr.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
Expand Down Expand Up @@ -53,3 +54,4 @@ class Provider

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
6 changes: 4 additions & 2 deletions api/include/opentelemetry/metrics/sync_instruments.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#ifdef ENABLE_METRIC_PREVIEW
# pragma once

#include "instrument.h"
# include "instrument.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
Expand Down Expand Up @@ -174,3 +175,4 @@ class ValueRecorder : virtual public SynchronousInstrument<T>

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
13 changes: 10 additions & 3 deletions api/test/metrics/meter_provider_test.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/nostd/shared_ptr.h"

#include <gtest/gtest.h>

#ifdef ENABLE_METRIC_PREVIEW
# include "opentelemetry/metrics/provider.h"
# include "opentelemetry/nostd/shared_ptr.h"

using opentelemetry::metrics::Meter;
using opentelemetry::metrics::MeterProvider;
using opentelemetry::metrics::Provider;
Expand Down Expand Up @@ -39,3 +40,9 @@ TEST(Provider, MultipleMeterProviders)

ASSERT_NE(Provider::GetMeterProvider(), tf);
}
#else
TEST(Provider, DummyTest)
{
// empty
lalitb marked this conversation as resolved.
Show resolved Hide resolved
}
#endif
16 changes: 12 additions & 4 deletions api/test/metrics/noop_instrument_test.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <gtest/gtest.h>
#include <cstring>
#include <map>
#include <string>
#include "opentelemetry/metrics/noop.h"

#ifdef ENABLE_METRIC_PREVIEW
# include <cstring>
# include <map>
# include <string>
# include "opentelemetry/metrics/noop.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace metrics
Expand Down Expand Up @@ -183,3 +185,9 @@ TEST(ValueRecorder, Record)

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#else
TEST(ValueRecorder, DummyTest)
{
// empty
}
#endif
20 changes: 14 additions & 6 deletions api/test/metrics/noop_metrics_test.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <gtest/gtest.h>
#include "opentelemetry/metrics/instrument.h"
#include "opentelemetry/metrics/noop.h"
#include "opentelemetry/metrics/observer_result.h"
#include "opentelemetry/metrics/sync_instruments.h"

#include <array>
#include <memory>
#ifdef ENABLE_METRIC_PREVIEW
# include "opentelemetry/metrics/instrument.h"
# include "opentelemetry/metrics/noop.h"
# include "opentelemetry/metrics/observer_result.h"
# include "opentelemetry/metrics/sync_instruments.h"

# include <array>
# include <memory>

OPENTELEMETRY_BEGIN_NAMESPACE

Expand Down Expand Up @@ -76,3 +78,9 @@ TEST(NoopMeter, RecordBatch)
m->RecordDoubleBatch(labelkv, dsp, dval);
}
OPENTELEMETRY_END_NAMESPACE
#else
TEST(NoopMeter, DummyTest)
{
// empty
}
#endif
19 changes: 13 additions & 6 deletions examples/metrics_simple/main.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "opentelemetry/exporters/ostream/metrics_exporter.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/metrics/controller.h"
#include "opentelemetry/sdk/metrics/meter.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"
#include "opentelemetry/sdk/metrics/ungrouped_processor.h"
#ifdef ENABLE_METRIC_PREVIEW
# include "opentelemetry/exporters/ostream/metrics_exporter.h"
# include "opentelemetry/metrics/provider.h"
# include "opentelemetry/sdk/metrics/controller.h"
# include "opentelemetry/sdk/metrics/meter.h"
# include "opentelemetry/sdk/metrics/meter_provider.h"
# include "opentelemetry/sdk/metrics/ungrouped_processor.h"

namespace sdkmetrics = opentelemetry::sdk::metrics;
namespace nostd = opentelemetry::nostd;
Expand Down Expand Up @@ -105,3 +106,9 @@ int main()
}
ControllerStateful.stop();
}
#else
int main()
{
// empty
}
#endif
4 changes: 3 additions & 1 deletion exporters/ostream/src/metrics_exporter.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "opentelemetry/exporters/ostream/metrics_exporter.h"
#ifdef ENABLE_METRICS_PREVIEW
# include "opentelemetry/exporters/ostream/metrics_exporter.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
Expand Down Expand Up @@ -48,3 +49,4 @@ sdk::common::ExportResult OStreamMetricsExporter::Export(
} // namespace metrics
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif
28 changes: 18 additions & 10 deletions exporters/ostream/test/ostream_metrics_test.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#include "opentelemetry/exporters/ostream/metrics_exporter.h"
#include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h"
#include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h"
#include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h"
#include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h"
#include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h"
#include "opentelemetry/sdk/metrics/exporter.h"
#include "opentelemetry/sdk/metrics/record.h"

#include <gtest/gtest.h>
#include <iostream>
#ifdef ENABLE_METRICS_PREVIEW

# include "opentelemetry/exporters/ostream/metrics_exporter.h"
# include "opentelemetry/sdk/metrics/aggregator/counter_aggregator.h"
# include "opentelemetry/sdk/metrics/aggregator/exact_aggregator.h"
# include "opentelemetry/sdk/metrics/aggregator/gauge_aggregator.h"
# include "opentelemetry/sdk/metrics/aggregator/min_max_sum_count_aggregator.h"
# include "opentelemetry/sdk/metrics/aggregator/sketch_aggregator.h"
# include "opentelemetry/sdk/metrics/exporter.h"
# include "opentelemetry/sdk/metrics/record.h"

# include <iostream>

namespace sdkmetrics = opentelemetry::sdk::metrics;
namespace metrics_api = opentelemetry::metrics;
Expand Down Expand Up @@ -288,3 +290,9 @@ TEST(OStreamMetricsExporter, PrintSketch)

ASSERT_EQ(stdoutOutput.str(), expectedOutput);
}
#else
TEST(OStreamMetricsExporter, DummyTest)
{
// empty
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef ENABLE_METRIC_PREVIEW
# pragma once

#pragma once
# include <memory>
# include <mutex>
# include <vector>

#include <memory>
#include <mutex>
#include <vector>

#include "opentelemetry/sdk/metrics/record.h"
#include "prometheus/collectable.h"
#include "prometheus/metric_family.h"
#include "prometheus_exporter_utils.h"
# include "opentelemetry/sdk/metrics/record.h"
# include "prometheus/collectable.h"
# include "prometheus/metric_family.h"
# include "prometheus_exporter_utils.h"

namespace prometheus_client = ::prometheus;
namespace metric_sdk = opentelemetry::sdk::metrics;
Expand Down Expand Up @@ -98,3 +98,4 @@ class PrometheusCollector : public prometheus_client::Collectable
} // namespace prometheus
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

#pragma once
#ifdef ENABLE_METRIC_PREVIEW
# pragma once

#include <string>
#include <vector>
# include <string>
# include <vector>

#include "opentelemetry/sdk/metrics/record.h"
#include "prometheus/metric_family.h"
# include "opentelemetry/sdk/metrics/record.h"
# include "prometheus/metric_family.h"

namespace metric_sdk = opentelemetry::sdk::metrics;

Expand Down Expand Up @@ -180,3 +181,4 @@ class PrometheusExporterUtils
} // namespace prometheus
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
#endif
Loading