Skip to content

Commit

Permalink
use directly the ANSII version of the function (FormatMessageA, LoadL…
Browse files Browse the repository at this point in the history
…ibraryA). Some more testing in X
  • Loading branch information
dstanev-atvi committed Jan 10, 2024
1 parent 35bb335 commit e7a9b53
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ inline void GetLastErrorMessage(std::string &error_message) noexcept
{
auto error_code = ::GetLastError();
// See https://stackoverflow.com/a/455533/4447365
LPTSTR error_text = nullptr;
auto size = ::FormatMessage(
LPSTR error_text = nullptr;
auto size = ::FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPTSTR>(&error_text), 0, nullptr);
reinterpret_cast<LPSTR>(&error_text), 0, nullptr);
if (size == 0)
{
return;
Expand All @@ -53,7 +53,7 @@ class DynamicLibraryHandleWindows final : public DynamicLibraryHandle

inline std::unique_ptr<Factory> LoadFactory(const char *plugin, std::string &error_message) noexcept
{
auto handle = ::LoadLibrary(plugin);
auto handle = ::LoadLibraryA(plugin);
if (handle == nullptr)
{
detail::GetLastErrorMessage(error_message);
Expand Down
15 changes: 8 additions & 7 deletions x/otel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ receivers:
protocols:
grpc:
http:
prometheus/collector:
config:
scrape_configs:
- job_name: 'opentelemetry-collector'
static_configs:
- targets: ['localhost:8888']
# prometheus/collector:
# config:
# scrape_configs:
# - job_name: 'opentelemetry-collector'
# static_configs:
# - targets: ['localhost:8888']

# service:
# # https://opentelemetry.io/docs/collector/configuration/#telemetry
Expand Down Expand Up @@ -62,7 +62,8 @@ service:
processors: [batch]
exporters: [otlphttp,logging/traces]
metrics:
receivers: [otlp,prometheus/collector]
receivers: [otlp]
#,prometheus/collector]
processors: [batch]
exporters: [prometheusremotewrite,logging/metrics]
logs:
Expand Down
35 changes: 21 additions & 14 deletions x/x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static std::map<std::string, std::string> get_random_attr()
return { labels[rand() % ( labels.size() - 1 )], labels[rand() % ( labels.size() - 1 )] };
}

static void counter_example( const std::string &name, const opentelemetry::trace::SpanContext &spanContext )
static void counter_example( const std::string &name, double startValue, const opentelemetry::trace::SpanContext &spanContext )
{
get_logger()->Info( "counter_example" );
opentelemetry::trace::StartSpanOptions options;
Expand All @@ -285,16 +285,17 @@ static void counter_example( const std::string &name, const opentelemetry::trace

const auto provider{ opentelemetry::metrics::Provider::GetMeterProvider() };
const auto meter{ provider->GetMeter( name ) };

const auto double_counter{ meter->CreateDoubleCounter( name + "_counter" ) };
const auto double_updown_counter{ meter->CreateDoubleUpDownCounter( name + "_updown_counter" ) };

double_counter->Add( startValue );
double_updown_counter->Add( startValue + 500.0 );

for ( auto i = 0; i < 1000; ++i )
{
const double val{ rand() % 7 + 1.1 };

double_counter->Add( val );

std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
double_counter->Add( 1.0 );
double_updown_counter->Add( 1.0 );
std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
}
}

Expand Down Expand Up @@ -530,17 +531,23 @@ void demo()
get_logger()->Info( "Spawning threads" );

auto context = span->GetContext();
std::thread counter_example_thread( counter_example, metric_prefix_name, context );
std::thread observable_counter_example_thread( observable_counter_example, metric_prefix_name, context );
std::thread histogram_example_thread( histogram_example, metric_prefix_name, context );
std::thread counter_example_thread1( counter_example, metric_prefix_name + "_0", 100.0, context );
std::thread counter_example_thread2( counter_example, metric_prefix_name + "_1", 200.0, context );
std::thread counter_example_thread3( counter_example, metric_prefix_name + "_1", 200.0, context );
std::thread counter_example_thread4( counter_example, metric_prefix_name + "_1", 300.0, context );
//std::thread observable_counter_example_thread( observable_counter_example, metric_prefix_name, context );
//std::thread histogram_example_thread( histogram_example, metric_prefix_name, context );

get_logger()->Info( "Joining threads" );

ui_main();
//ui_main();

counter_example_thread.join();
observable_counter_example_thread.join();
histogram_example_thread.join();
counter_example_thread1.join();
counter_example_thread2.join();
counter_example_thread3.join();
counter_example_thread4.join();
//observable_counter_example_thread.join();
//histogram_example_thread.join();

get_logger()->Info( "Joined all threads" );
}
Expand Down

0 comments on commit e7a9b53

Please sign in to comment.