Skip to content

Commit

Permalink
Add preview feature-flag/macro for metrics (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored May 14, 2021
1 parent 42e9330 commit b696e11
Show file tree
Hide file tree
Showing 60 changed files with 631 additions and 489 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ endif(WIN32)

option(WITH_EXAMPLES "Whether to build examples" ON)

option(WITH_METRICS_PREVIEW "Whether to build metrics preview" OFF)

if(WITH_METRICS_PREVIEW)
add_definitions(-DENABLE_METRICS_PREVIEW)
endif()

find_package(Threads)

function(install_windows_deps)
Expand Down
6 changes: 4 additions & 2 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

#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
12 changes: 7 additions & 5 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_METRICS_PREVIEW

#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
16 changes: 9 additions & 7 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_METRICS_PREVIEW

#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
8 changes: 5 additions & 3 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_METRICS_PREVIEW

#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
20 changes: 11 additions & 9 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_METRICS_PREVIEW
// 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
6 changes: 4 additions & 2 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_METRICS_PREVIEW

#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
13 changes: 7 additions & 6 deletions api/include/opentelemetry/metrics/provider.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once
#ifdef ENABLE_METRICS_PREVIEW
# 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 +53,4 @@ class Provider

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
4 changes: 3 additions & 1 deletion 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_METRICS_PREVIEW

#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
4 changes: 3 additions & 1 deletion api/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ add_subdirectory(context)
add_subdirectory(plugin)
add_subdirectory(nostd)
add_subdirectory(trace)
add_subdirectory(metrics)
if(WITH_METRICS_PREVIEW)
add_subdirectory(metrics)
endif()
add_subdirectory(logs)
add_subdirectory(common)
add_subdirectory(baggage)
9 changes: 5 additions & 4 deletions api/test/metrics/meter_provider_test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/nostd/shared_ptr.h"

#include <gtest/gtest.h>
#ifdef ENABLE_METRICS_PREVIEW
# include <gtest/gtest.h>
# include "opentelemetry/metrics/provider.h"
# include "opentelemetry/nostd/shared_ptr.h"

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

ASSERT_NE(Provider::GetMeterProvider(), tf);
}
#endif
13 changes: 8 additions & 5 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_METRICS_PREVIEW
# include <gtest/gtest.h>
# include <cstring>
# include <map>
# include <string>

# include "opentelemetry/metrics/noop.h"

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

} // namespace metrics
OPENTELEMETRY_END_NAMESPACE
#endif
16 changes: 9 additions & 7 deletions api/test/metrics/noop_metrics_test.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#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"
#ifdef ENABLE_METRICS_PREVIEW
# 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>
# include <array>
# include <memory>

OPENTELEMETRY_BEGIN_NAMESPACE

Expand Down Expand Up @@ -76,3 +77,4 @@ TEST(NoopMeter, RecordBatch)
m->RecordDoubleBatch(labelkv, dsp, dval);
}
OPENTELEMETRY_END_NAMESPACE
#endif
3 changes: 2 additions & 1 deletion ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if [[ "$1" == "cmake.test" ]]; then
-DWITH_PROMETHEUS=ON \
-DWITH_ZIPKIN=ON \
-DWITH_ELASTICSEARCH=ON \
-DWITH_METRICS_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror" \
"${SRC_DIR}"
make
Expand Down Expand Up @@ -107,7 +108,7 @@ EOF
examples/plugin/load/load_plugin_example ${PLUGIN_DIR}/libexample_plugin.so /dev/null
exit 0
elif [[ "$1" == "bazel.test" ]]; then
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS //...
bazel $BAZEL_STARTUP_OPTIONS build --copt=-DENABLE_METRICS_PREVIEW $BAZEL_OPTIONS //...
bazel $BAZEL_STARTUP_OPTIONS test $BAZEL_TEST_OPTIONS //...
exit 0
elif [[ "$1" == "bazel.legacy.test" ]]; then
Expand Down
4 changes: 3 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ endif()
add_subdirectory(plugin)
add_subdirectory(simple)
add_subdirectory(batch)
add_subdirectory(metrics_simple)
if(WITH_METRICS_PREVIEW)
add_subdirectory(metrics_simple)
endif()
add_subdirectory(multithreaded)
add_subdirectory(multi_processor)
add_subdirectory(http)
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_METRICS_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
2 changes: 1 addition & 1 deletion exporters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif()
add_subdirectory(ostream)
add_subdirectory(memory)

if(WITH_PROMETHEUS)
if(WITH_PROMETHEUS AND WITH_METRICS_PREVIEW)
add_subdirectory(prometheus)
endif()

Expand Down
Loading

0 comments on commit b696e11

Please sign in to comment.