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

Make macros.h available for all source files via version.h #1918

Merged
merged 4 commits into from
Jan 17, 2023
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
9 changes: 2 additions & 7 deletions api/include/opentelemetry/common/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#pragma once

#include <cstdint>

#include "opentelemetry/version.h"

#if !defined(OPENTELEMETRY_LIKELY_IF) && defined(__cplusplus)
// GCC 9 has likely attribute but do not support declare it at the beginning of statement
# if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9)
Expand Down Expand Up @@ -92,10 +88,9 @@

// Regex support
#if (__GNUC__ == 4 && (__GNUC_MINOR__ == 8 || __GNUC_MINOR__ == 9))
# define HAVE_WORKING_REGEX 0
# define OPENTELEMETRY_HAVE_WORKING_REGEX 0
#else
# include <regex>
# define HAVE_WORKING_REGEX 1
# define OPENTELEMETRY_HAVE_WORKING_REGEX 1
#endif

/* clang-format off */
Expand Down
16 changes: 6 additions & 10 deletions api/include/opentelemetry/trace/trace_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
#include <cstring>
#include <string>

#include <regex>
#if (__GNUC__ == 4 && (__GNUC_MINOR__ == 8 || __GNUC_MINOR__ == 9))
# define HAVE_WORKING_REGEX 0
#else
# define HAVE_WORKING_REGEX 1
#endif

#include "opentelemetry/common/kv_properties.h"
#include "opentelemetry/common/macros.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"

#if defined(OPENTELEMETRY_HAVE_WORKING_REGEX)
# include <regex>
#endif

OPENTELEMETRY_BEGIN_NAMESPACE
namespace trace
{
Expand Down Expand Up @@ -212,7 +208,7 @@ class TraceState
*/
static bool IsValidKey(nostd::string_view key)
{
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
return IsValidKeyRegEx(key);
#else
return IsValidKeyNonRegEx(key);
Expand All @@ -225,7 +221,7 @@ class TraceState
*/
static bool IsValidValue(nostd::string_view value)
{
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
return IsValidValueRegEx(value);
#else
return IsValidValueNonRegEx(value);
Expand Down
1 change: 1 addition & 0 deletions api/include/opentelemetry/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include "opentelemetry/common/macros.h"
#include "opentelemetry/detail/preprocessor.h"

#define OPENTELEMETRY_ABI_VERSION_NO 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/version.h"

#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
# include <regex>
#endif

Expand All @@ -26,7 +26,7 @@ class InstrumentMetaDataValidator
bool ValidateDescription(nostd::string_view description) const;

private:
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
const std::regex name_reg_key_;
const std::regex unit_reg_key_;
#endif
Expand Down
8 changes: 6 additions & 2 deletions sdk/include/opentelemetry/sdk/metrics/view/predicate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/common/global_log_handler.h"

#if defined(OPENTELEMETRY_HAVE_WORKING_REGEX)
# include <regex>
#endif

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
Expand All @@ -26,7 +30,7 @@ class PatternPredicate : public Predicate
PatternPredicate(opentelemetry::nostd::string_view pattern) : reg_key_{pattern.data()} {}
bool Match(opentelemetry::nostd::string_view str) const noexcept override
{
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
return std::regex_match(str.data(), reg_key_);
#else
// TBD - Support regex match for GCC4.8
Expand All @@ -37,7 +41,7 @@ class PatternPredicate : public Predicate
}

private:
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
std::regex reg_key_;
#else
std::string reg_key_;
Expand Down
10 changes: 7 additions & 3 deletions sdk/src/metrics/instrument_metadata_validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <algorithm>
#include <iostream>

#if defined(OPENTELEMETRY_HAVE_WORKING_REGEX)
# include <regex>
#endif

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
Expand All @@ -20,7 +24,7 @@ const std::string kInstrumentUnitPattern = "[\x01-\x7F]{0,63}";
// instrument-unit = It can have a maximum length of 63 ASCII chars

InstrumentMetaDataValidator::InstrumentMetaDataValidator()
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
// clang-format off
: name_reg_key_{kInstrumentNamePattern},
unit_reg_key_{kInstrumentUnitPattern}
Expand All @@ -31,7 +35,7 @@ InstrumentMetaDataValidator::InstrumentMetaDataValidator()
bool InstrumentMetaDataValidator::ValidateName(nostd::string_view name) const
{

#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
return std::regex_match(name.data(), name_reg_key_);
#else
const size_t kMaxSize = 63;
Expand All @@ -53,7 +57,7 @@ bool InstrumentMetaDataValidator::ValidateName(nostd::string_view name) const

bool InstrumentMetaDataValidator::ValidateUnit(nostd::string_view unit) const
{
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
return std::regex_match(unit.data(), unit_reg_key_);
#else
const size_t kMaxSize = 63;
Expand Down
8 changes: 6 additions & 2 deletions sdk/test/metrics/histogram_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include <gtest/gtest.h>

#if defined(OPENTELEMETRY_HAVE_WORKING_REGEX)
# include <regex>
#endif

using namespace opentelemetry;
using namespace opentelemetry::sdk::instrumentationscope;
using namespace opentelemetry::sdk::metrics;
Expand Down Expand Up @@ -111,7 +115,7 @@ TEST(Histogram, Double)
actual.counts_);
}

#if (HAVE_WORKING_REGEX)
#if (OPENTELEMETRY_HAVE_WORKING_REGEX)
// FIXME - View Preficate search is only supported through regex
TEST(Histogram, DoubleCustomBuckets)
{
Expand Down Expand Up @@ -223,7 +227,7 @@ TEST(Histogram, UInt64)
actual.counts_);
}

#if (HAVE_WORKING_REGEX)
#if (OPENTELEMETRY_HAVE_WORKING_REGEX)
// FIXME - View Preficate search is only supported through regex
TEST(Histogram, UInt64CustomBuckets)
{
Expand Down
12 changes: 8 additions & 4 deletions sdk/test/metrics/view_registry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#include <gtest/gtest.h>

#if defined(OPENTELEMETRY_HAVE_WORKING_REGEX)
# include <regex>
#endif

using namespace opentelemetry::sdk::metrics;
using namespace opentelemetry::sdk::instrumentationscope;

Expand All @@ -28,14 +32,14 @@ TEST(ViewRegistry, FindViewsEmptyRegistry)
registry.FindViews(default_instrument_descriptor, *default_instrumentation_scope.get(),
[&count](const View &view) {
count++;
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
EXPECT_EQ(view.GetName(), "");
EXPECT_EQ(view.GetDescription(), "");
#endif
EXPECT_EQ(view.GetAggregationType(), AggregationType::kDefault);
return true;
});
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
EXPECT_EQ(count, 1);
EXPECT_EQ(status, true);
#endif
Expand Down Expand Up @@ -73,13 +77,13 @@ TEST(ViewRegistry, FindNonExistingView)
registry.FindViews(default_instrument_descriptor, *default_instrumentation_scope.get(),
[&count, &view_name, &view_description](const View &view) {
count++;
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
EXPECT_EQ(view.GetName(), view_name);
EXPECT_EQ(view.GetDescription(), view_description);
#endif
return true;
});
#if HAVE_WORKING_REGEX
#if OPENTELEMETRY_HAVE_WORKING_REGEX
EXPECT_EQ(count, 1);
EXPECT_EQ(status, true);
#endif
Expand Down