@@ -139,11 +139,11 @@ void metrics_counter_example(const std::string &name)
139139 provider->GetMeter (name, " 1.2.0" );
140140 auto double_counter = meter->CreateDoubleCounter (counter_name);
141141
142- for (uint32_t i = 0 ; i < 20 ; ++i)
142+ for (uint32_t i = 0 ; i < 2000 ; ++i)
143143 {
144144 double val = (rand () % 700 ) + 1.1 ;
145145 double_counter->Add (val);
146- std::this_thread::sleep_for (std::chrono::milliseconds (500 ));
146+ std::this_thread::sleep_for (std::chrono::milliseconds (5 ));
147147 }
148148}
149149
@@ -155,9 +155,9 @@ void metrics_observable_counter_example(const std::string &name)
155155 provider->GetMeter (name, " 1.2.0" );
156156 double_observable_counter = meter->CreateDoubleObservableCounter (counter_name);
157157 double_observable_counter->AddCallback (MeasurementFetcher::Fetcher, nullptr );
158- for (uint32_t i = 0 ; i < 20 ; ++i)
158+ for (uint32_t i = 0 ; i < 2000 ; ++i)
159159 {
160- std::this_thread::sleep_for (std::chrono::milliseconds (500 ));
160+ std::this_thread::sleep_for (std::chrono::milliseconds (5 ));
161161 }
162162}
163163
@@ -169,13 +169,13 @@ void metrics_histogram_example(const std::string &name)
169169 provider->GetMeter (name, " 1.2.0" );
170170 auto histogram_counter = meter->CreateDoubleHistogram (histogram_name, " des" , " unit" );
171171 auto context = opentelemetry::context::Context{};
172- for (uint32_t i = 0 ; i < 20 ; ++i)
172+ for (uint32_t i = 0 ; i < 2000 ; ++i)
173173 {
174174 double val = (rand () % 700 ) + 1.1 ;
175175 std::map<std::string, std::string> labels = get_random_attr ();
176176 auto labelkv = opentelemetry::common::KeyValueIterableView<decltype (labels)>{labels};
177177 histogram_counter->Record (val, labelkv, context);
178- std::this_thread::sleep_for (std::chrono::milliseconds (250 ));
178+ std::this_thread::sleep_for (std::chrono::milliseconds (2 ));
179179 }
180180}
181181
@@ -296,8 +296,8 @@ void InitMetrics(const std::string &name)
296296
297297 // Initialize and set the global MeterProvider
298298 opentelemetry::sdk::metrics::PeriodicExportingMetricReaderOptions options;
299- options.export_interval_millis = std::chrono::milliseconds (1000 );
300- options.export_timeout_millis = std::chrono::milliseconds (500 );
299+ options.export_interval_millis = std::chrono::milliseconds (100 );
300+ options.export_timeout_millis = std::chrono::milliseconds (50 );
301301
302302 auto reader = opentelemetry::sdk::metrics::PeriodicExportingMetricReaderFactory::Create (
303303 std::move (exporter), options);
@@ -382,43 +382,47 @@ struct proxy_thread
382382 std::mutex mu;
383383 std::condition_variable cv;
384384 bool ready{ false };
385- static inline std::unique_ptr<opentelemetry::exporter::otlp::OtlpGrpcForwardProxy> proxy;
386- static void entry (proxy_thread* ctx)
385+ std::unique_ptr<opentelemetry::exporter::otlp::OtlpGrpcForwardProxy> proxy;
386+ static void thread_entry (proxy_thread* this_, const std::string& listenAddress, const std::string& sendAddress )
387+ {
388+ this_->entry (listenAddress, sendAddress);
389+ }
390+ void entry (const std::string& listenAddress, const std::string& sendAddress )
387391 {
388392 using namespace opentelemetry ::exporter::otlp;
389393
390- OtlpGrpcClientOptions clientOptions;
391- clientOptions.endpoint = GetOtlpDefaultGrpcEndpoint ();
392- clientOptions.max_concurrent_requests = 10 ; // 16384;
393- clientOptions.max_threads = 10 ;
394+ OtlpGrpcClientOptions clientOptions{} ;
395+ clientOptions.endpoint = sendAddress; // GetOtlpDefaultGrpcEndpoint();
396+ clientOptions.max_concurrent_requests = 16384 ;
397+ clientOptions.max_threads = 32 ;
394398
395- ctx-> proxy = std::make_unique<OtlpGrpcForwardProxy>(clientOptions);
396- ctx-> proxy ->SetActive (true );
399+ proxy = std::make_unique<OtlpGrpcForwardProxy>(clientOptions);
400+ proxy->SetActive (true );
397401
398- ctx-> proxy ->AddListenAddress (" localhost:4317 " );
402+ proxy->AddListenAddress (listenAddress );
399403 proxy->RegisterMetricExporter (OtlpGrpcForwardProxy::ExportMode::AsyncDropOnFull);
400404 proxy->RegisterTraceExporter (OtlpGrpcForwardProxy::ExportMode::AsyncDropOnFull);
401405 proxy->RegisterLogRecordExporter (OtlpGrpcForwardProxy::ExportMode::AsyncDropOnFull);
402406 printf (" Start\n " );
403- ctx-> proxy ->Start ();
407+ proxy->Start ();
404408 {
405- std::unique_lock<std::mutex> lock (ctx-> mu );
406- ctx-> ready = true ;
407- ctx-> cv .notify_one ();
409+ std::unique_lock<std::mutex> lock (mu);
410+ ready = true ;
411+ cv.notify_one ();
408412 }
409413 printf (" Wait\n " );
410- ctx-> proxy ->Wait ();
414+ proxy->Wait ();
411415 printf (" Done Wait\n " );
412416 }
413- static void start ()
417+ proxy_thread () = delete ;
418+ explicit proxy_thread (const std::string& listenAddress, const std::string& sendAddress)
414419 {
415- proxy_thread ctx;
416- std::thread pt (proxy_thread::entry, &ctx);
420+ std::thread pt (proxy_thread::thread_entry, this , listenAddress, sendAddress);
417421 pt.detach ();
418- std::unique_lock<std::mutex> lock (ctx. mu );
419- ctx. cv .wait (lock, [&ctx ]{ return ctx. ready ; });
422+ std::unique_lock<std::mutex> lock ( mu );
423+ cv.wait (lock, [this ]{ return ready; });
420424 }
421- static void shutdown ()
425+ ~proxy_thread ()
422426 {
423427 if ( proxy )
424428 proxy->Shutdown ();
@@ -434,10 +438,24 @@ int main(int argc, const char *argv[])
434438
435439 {
436440 using namespace opentelemetry ::sdk::common::internal_log;
441+ GlobalLogHandler::SetLogLevel (LogLevel::None);
437442 GlobalLogHandler::SetLogLevel (LogLevel::Debug);
438443 }
439444
440- proxy_thread::start ();
445+ proxy_thread p0 (" 127.0.0.1:4317" , " unix://p/1" );
446+ // proxy_thread p1("unix:q:/p/m/opentelemetry-cpp/1.sock", "unix:q:/p/m/opentelemetry-cpp/2.sock");
447+ // proxy_thread p2("unix:q:/p/m/opentelemetry-cpp/2.sock", "unix:q:/p/m/opentelemetry-cpp/3.sock");
448+ // proxy_thread p1("127.0.0.1:43170", "127.0.0.1:43171");
449+ // proxy_thread p2("127.0.0.1:43171", "127.0.0.1:43172");
450+ // proxy_thread p3("127.0.0.1:43172", "127.0.0.1:43173");
451+ // proxy_thread p4("127.0.0.1:43173", "127.0.0.1:43174");
452+ // proxy_thread p5("127.0.0.1:43174", "127.0.0.1:43175");
453+ // proxy_thread p6("127.0.0.1:43175", "127.0.0.1:43176");
454+ // proxy_thread p7("127.0.0.1:43176", "127.0.0.1:43177");
455+ // proxy_thread p8("127.0.0.1:43177", "127.0.0.1:43178");
456+ // proxy_thread p9("127.0.0.1:43178", "127.0.0.1:43179");
457+ // proxy_thread pA("127.0.0.1:43179", opentelemetry::exporter::otlp::GetOtlpDefaultGrpcEndpoint());
458+ // pA.proxy->SetActive( false );
441459
442460 {
443461 using namespace opentelemetry ::sdk::common;
@@ -462,15 +480,14 @@ int main(int argc, const char *argv[])
462480 CleanupLogger ();
463481 CleanupTracer ();
464482
465- printf (" Press Ctrl+C to break\n " );
466- try {
467- std::this_thread::sleep_for (std::chrono::seconds (500 ));
468- }
469- catch ( ... )
470- {
471- printf (" Caught something?\n " );
472- }
483+ // printf("Press Ctrl+C to break\n");
484+ // try {
485+ // std::this_thread::sleep_for(std::chrono::seconds(500));
486+ // }
487+ // catch( ... )
488+ // {
489+ // printf("Caught something?\n");
490+ // }
473491
474- proxy_thread::shutdown ();
475492 return 0 ;
476493}
0 commit comments