func_grpc_main.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <iostream>
  7. #include <string>
  8. #include <utility>
  9. #include "opentelemetry/exporters/otlp/otlp_environment.h"
  10. #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_factory.h"
  11. #include "opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h"
  12. #include "opentelemetry/nostd/shared_ptr.h"
  13. #include "opentelemetry/nostd/string_view.h"
  14. #include "opentelemetry/sdk/common/attribute_utils.h"
  15. #include "opentelemetry/sdk/common/global_log_handler.h"
  16. #include "opentelemetry/sdk/trace/processor.h"
  17. #include "opentelemetry/sdk/trace/provider.h"
  18. #include "opentelemetry/sdk/trace/recordable.h"
  19. #include "opentelemetry/sdk/trace/simple_processor_factory.h"
  20. #include "opentelemetry/sdk/trace/tracer_provider.h"
  21. #include "opentelemetry/sdk/trace/tracer_provider_factory.h"
  22. #include "opentelemetry/trace/provider.h"
  23. #include "opentelemetry/trace/span.h"
  24. #include "opentelemetry/trace/span_id.h"
  25. #include "opentelemetry/trace/tracer.h"
  26. #include "opentelemetry/trace/tracer_provider.h"
  27. namespace trace = opentelemetry::trace;
  28. namespace trace_sdk = opentelemetry::sdk::trace;
  29. namespace otlp = opentelemetry::exporter::otlp;
  30. namespace nostd = opentelemetry::nostd;
  31. namespace internal_log = opentelemetry::sdk::common::internal_log;
  32. const int TEST_PASSED = 0;
  33. const int TEST_FAILED = 1;
  34. /*
  35. Command line parameters.
  36. */
  37. enum class TestMode : std::uint8_t
  38. {
  39. kNone,
  40. kHttp,
  41. kHttps
  42. };
  43. bool opt_help = false;
  44. bool opt_list = false;
  45. bool opt_debug = false;
  46. bool opt_secure = false;
  47. // HTTPS by default
  48. std::string opt_endpoint = "https://127.0.0.1:4317";
  49. std::string opt_cert_dir;
  50. std::string opt_test_name;
  51. TestMode opt_mode = TestMode::kNone;
  52. /*
  53. Log parsing
  54. */
  55. struct TestResult
  56. {
  57. bool found_connection_failed = false;
  58. bool found_export_error = false;
  59. bool found_export_success = false;
  60. bool deadline_exceeded = false;
  61. bool empty_address_list = false;
  62. void reset()
  63. {
  64. found_connection_failed = false;
  65. found_export_error = false;
  66. found_export_success = false;
  67. deadline_exceeded = false;
  68. empty_address_list = false;
  69. }
  70. };
  71. struct TestResult g_test_result;
  72. void parse_error_msg(TestResult *result, const std::string &msg)
  73. {
  74. static std::string connection_failed("failed to connect to all addresses");
  75. if (msg.find(connection_failed) != std::string::npos)
  76. {
  77. result->found_connection_failed = true;
  78. }
  79. static std::string export_failed("Export() failed with status_code");
  80. if (msg.find(export_failed) != std::string::npos)
  81. {
  82. result->found_export_error = true;
  83. }
  84. static std::string deadline_exceeded("Deadline Exceeded");
  85. if (msg.find(deadline_exceeded) != std::string::npos)
  86. {
  87. result->deadline_exceeded = true;
  88. }
  89. static std::string empty_address_list("empty address list:");
  90. if (msg.find(empty_address_list) != std::string::npos)
  91. {
  92. result->empty_address_list = true;
  93. }
  94. }
  95. void parse_warning_msg(TestResult * /* result */, const std::string & /* msg */) {}
  96. void parse_info_msg(TestResult * /* result */, const std::string & /* msg */) {}
  97. void parse_debug_msg(TestResult *result, const std::string &msg)
  98. {
  99. static std::string export_success("Export 1 trace span(s) success");
  100. if (msg.find(export_success) != std::string::npos)
  101. {
  102. result->found_export_success = true;
  103. }
  104. }
  105. class TestLogHandler : public opentelemetry::sdk::common::internal_log::LogHandler
  106. {
  107. public:
  108. void Handle(opentelemetry::sdk::common::internal_log::LogLevel level,
  109. const char * /* file */,
  110. int /* line */,
  111. const char *msg,
  112. const opentelemetry::sdk::common::AttributeMap & /* attributes */) noexcept override
  113. {
  114. if (msg == nullptr)
  115. {
  116. msg = "<no msg>";
  117. }
  118. switch (level)
  119. {
  120. case opentelemetry::sdk::common::internal_log::LogLevel::None:
  121. break;
  122. case opentelemetry::sdk::common::internal_log::LogLevel::Error:
  123. std::cout << " - [E] " << msg << '\n';
  124. parse_error_msg(&g_test_result, msg);
  125. break;
  126. case opentelemetry::sdk::common::internal_log::LogLevel::Warning:
  127. std::cout << " - [W] " << msg << '\n';
  128. parse_warning_msg(&g_test_result, msg);
  129. break;
  130. case opentelemetry::sdk::common::internal_log::LogLevel::Info:
  131. std::cout << " - [I] " << msg << '\n';
  132. parse_info_msg(&g_test_result, msg);
  133. break;
  134. case opentelemetry::sdk::common::internal_log::LogLevel::Debug:
  135. std::cout << " - [D] " << msg << '\n';
  136. parse_debug_msg(&g_test_result, msg);
  137. break;
  138. }
  139. }
  140. };
  141. void init(const otlp::OtlpGrpcExporterOptions &opts)
  142. {
  143. // Create OTLP exporter instance
  144. auto exporter = otlp::OtlpGrpcExporterFactory::Create(opts);
  145. auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter));
  146. std::shared_ptr<opentelemetry::trace::TracerProvider> provider =
  147. trace_sdk::TracerProviderFactory::Create(std::move(processor));
  148. // Set the global trace provider
  149. trace_sdk::Provider::SetTracerProvider(provider);
  150. }
  151. void payload()
  152. {
  153. static const nostd::string_view k_tracer_name("func_test");
  154. static const nostd::string_view k_span_name("func_grpc_main");
  155. static const nostd::string_view k_attr_test_name("test_name");
  156. auto provider = trace::Provider::GetTracerProvider();
  157. auto tracer = provider->GetTracer(k_tracer_name, "1.0");
  158. auto span = tracer->StartSpan(k_span_name);
  159. span->SetAttribute(k_attr_test_name, opt_test_name);
  160. span->End();
  161. }
  162. void cleanup()
  163. {
  164. std::shared_ptr<opentelemetry::trace::TracerProvider> none;
  165. trace_sdk::Provider::SetTracerProvider(none);
  166. }
  167. void instrumented_payload(const otlp::OtlpGrpcExporterOptions &opts)
  168. {
  169. g_test_result.reset();
  170. init(opts);
  171. payload();
  172. cleanup();
  173. }
  174. void usage(FILE *out)
  175. {
  176. static const char *msg =
  177. "Usage: func_otlp_grpc [options] test_name\n"
  178. "Valid options are:\n"
  179. " --help Print this help\n"
  180. " --list List test names\n"
  181. " --endpoint url OTLP gRPC endpoint (https://localhost:4317/ by default)\n"
  182. " --cert-dir dir Directory that contains test ssl certificates\n"
  183. " --mode mode Test server mode (used to verify expected results)\n"
  184. " - none: no endpoint\n"
  185. " - http: http endpoint\n"
  186. " - https: https endpoint\n";
  187. fprintf(out, "%s", msg);
  188. }
  189. int parse_args(int argc, char *argv[])
  190. {
  191. int remaining_argc = argc;
  192. char **remaining_argv = argv;
  193. while (remaining_argc > 0)
  194. {
  195. if (strcmp(*remaining_argv, "--help") == 0)
  196. {
  197. opt_help = true;
  198. return 0;
  199. }
  200. if (strcmp(*remaining_argv, "--list") == 0)
  201. {
  202. opt_list = true;
  203. return 0;
  204. }
  205. if (strcmp(*remaining_argv, "--debug") == 0)
  206. {
  207. opt_debug = true;
  208. remaining_argc--;
  209. remaining_argv++;
  210. continue;
  211. }
  212. if (remaining_argc >= 2)
  213. {
  214. if (strcmp(*remaining_argv, "--cert-dir") == 0)
  215. {
  216. remaining_argc--;
  217. remaining_argv++;
  218. opt_cert_dir = *remaining_argv;
  219. remaining_argc--;
  220. remaining_argv++;
  221. continue;
  222. }
  223. if (strcmp(*remaining_argv, "--endpoint") == 0)
  224. {
  225. remaining_argc--;
  226. remaining_argv++;
  227. opt_endpoint = *remaining_argv;
  228. remaining_argc--;
  229. remaining_argv++;
  230. continue;
  231. }
  232. if (strcmp(*remaining_argv, "--mode") == 0)
  233. {
  234. remaining_argc--;
  235. remaining_argv++;
  236. std::string mode = *remaining_argv;
  237. remaining_argc--;
  238. remaining_argv++;
  239. if (mode == "none")
  240. {
  241. opt_mode = TestMode::kNone;
  242. }
  243. else if (mode == "http")
  244. {
  245. opt_mode = TestMode::kHttp;
  246. }
  247. else if (mode == "https")
  248. {
  249. opt_mode = TestMode::kHttps;
  250. }
  251. else
  252. {
  253. // Unknown mode
  254. return 2;
  255. }
  256. continue;
  257. }
  258. }
  259. opt_test_name = *remaining_argv;
  260. remaining_argc--;
  261. remaining_argv++;
  262. if (remaining_argc)
  263. {
  264. // Unknown option
  265. return 1;
  266. }
  267. }
  268. return 0;
  269. }
  270. typedef int (*test_func_t)();
  271. struct test_case
  272. {
  273. std::string m_name;
  274. test_func_t m_func;
  275. };
  276. int test_basic();
  277. int test_cert_not_found();
  278. int test_cert_invalid();
  279. int test_cert_unreadable();
  280. int test_client_cert_not_found();
  281. int test_client_cert_invalid();
  282. int test_client_cert_unreadable();
  283. int test_client_cert_no_key();
  284. int test_client_key_not_found();
  285. int test_client_key_invalid();
  286. int test_client_key_unreadable();
  287. int test_mtls_ok();
  288. static const test_case all_tests[] = {{"basic", test_basic},
  289. {"cert-not-found", test_cert_not_found},
  290. {"cert-invalid", test_cert_invalid},
  291. {"cert-unreadable", test_cert_unreadable},
  292. #ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW
  293. {"client-cert-not-found", test_client_cert_not_found},
  294. {"client-cert-invalid", test_client_cert_invalid},
  295. {"client-cert-unreadable", test_client_cert_unreadable},
  296. {"client-cert-no-key", test_client_cert_no_key},
  297. {"client-key-not-found", test_client_key_not_found},
  298. {"client-key-invalid", test_client_key_invalid},
  299. {"client-key-unreadable", test_client_key_unreadable},
  300. {"mtls-ok", test_mtls_ok},
  301. #endif // ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW
  302. {"", nullptr}};
  303. void list_test_cases()
  304. {
  305. const test_case *current = all_tests;
  306. while (current->m_func != nullptr)
  307. {
  308. std::cout << current->m_name << '\n';
  309. current++;
  310. }
  311. }
  312. int run_test_case(const std::string &name)
  313. {
  314. const test_case *current = all_tests;
  315. while (current->m_func != nullptr)
  316. {
  317. if (current->m_name == name)
  318. {
  319. int rc = current->m_func();
  320. return rc;
  321. }
  322. current++;
  323. }
  324. std::cerr << "Unknown test <" << name << ">" << '\n';
  325. return 1;
  326. }
  327. int main(int argc, char *argv[])
  328. {
  329. // Program name
  330. argc--;
  331. argv++;
  332. int rc = parse_args(argc, argv);
  333. if (rc != 0)
  334. {
  335. usage(stderr);
  336. return 1;
  337. }
  338. if (opt_help)
  339. {
  340. usage(stdout);
  341. return 0;
  342. }
  343. if (opt_list)
  344. {
  345. list_test_cases();
  346. return 0;
  347. }
  348. if (opt_endpoint.find("https:") != std::string::npos)
  349. {
  350. opt_secure = true;
  351. }
  352. else
  353. {
  354. opt_secure = false;
  355. }
  356. opentelemetry::nostd::shared_ptr<internal_log::LogHandler> log_handler(new TestLogHandler);
  357. internal_log::GlobalLogHandler::SetLogHandler(log_handler);
  358. internal_log::GlobalLogHandler::SetLogLevel(internal_log::LogLevel::Debug);
  359. rc = run_test_case(opt_test_name);
  360. return rc;
  361. }
  362. void set_common_opts(otlp::OtlpGrpcExporterOptions &opts)
  363. {
  364. opts.endpoint = opt_endpoint;
  365. opts.timeout = std::chrono::milliseconds{100};
  366. opts.use_ssl_credentials = (opt_mode == TestMode::kHttps);
  367. #ifdef ENABLE_ASYNC_EXPORT
  368. // Work around, ASYNC export not working.
  369. opts.max_concurrent_requests = 0;
  370. #endif
  371. }
  372. int expect_connection_failed()
  373. {
  374. if (g_test_result.found_export_error &&
  375. (g_test_result.found_connection_failed || g_test_result.deadline_exceeded ||
  376. g_test_result.empty_address_list))
  377. {
  378. return TEST_PASSED;
  379. }
  380. return TEST_FAILED;
  381. }
  382. int expect_success()
  383. {
  384. if (g_test_result.found_export_success)
  385. {
  386. return TEST_PASSED;
  387. }
  388. return TEST_FAILED;
  389. }
  390. int expect_export_failed()
  391. {
  392. /*
  393. Can not test exact root cause:
  394. - connect failed ?
  395. - send request failed ?
  396. - exact error message ?
  397. so only verifying export failed.
  398. */
  399. if (g_test_result.found_export_error)
  400. {
  401. return TEST_PASSED;
  402. }
  403. return TEST_FAILED;
  404. }
  405. int test_basic()
  406. {
  407. otlp::OtlpGrpcExporterOptions opts;
  408. set_common_opts(opts);
  409. instrumented_payload(opts);
  410. if (opt_mode == TestMode::kNone)
  411. {
  412. return expect_connection_failed();
  413. }
  414. if (!opt_secure && (opt_mode == TestMode::kHttp))
  415. {
  416. return expect_success();
  417. }
  418. if (!opt_secure && (opt_mode == TestMode::kHttps))
  419. {
  420. return expect_export_failed();
  421. }
  422. if (opt_secure && (opt_mode == TestMode::kHttp))
  423. {
  424. return expect_connection_failed();
  425. }
  426. return expect_connection_failed();
  427. }
  428. int test_cert_not_found()
  429. {
  430. otlp::OtlpGrpcExporterOptions opts;
  431. set_common_opts(opts);
  432. opts.ssl_credentials_cacert_path = opt_cert_dir + "/no-such-file.pem";
  433. instrumented_payload(opts);
  434. if (opt_mode == TestMode::kNone)
  435. {
  436. return expect_connection_failed();
  437. }
  438. if (!opt_secure && (opt_mode == TestMode::kHttp))
  439. {
  440. return expect_success();
  441. }
  442. if (!opt_secure && (opt_mode == TestMode::kHttps))
  443. {
  444. return expect_export_failed();
  445. }
  446. return expect_connection_failed();
  447. }
  448. int test_cert_invalid()
  449. {
  450. otlp::OtlpGrpcExporterOptions opts;
  451. set_common_opts(opts);
  452. opts.ssl_credentials_cacert_path = opt_cert_dir + "/garbage.pem";
  453. instrumented_payload(opts);
  454. if (opt_mode == TestMode::kNone)
  455. {
  456. return expect_connection_failed();
  457. }
  458. if (!opt_secure && (opt_mode == TestMode::kHttp))
  459. {
  460. return expect_success();
  461. }
  462. if (!opt_secure && (opt_mode == TestMode::kHttps))
  463. {
  464. return expect_export_failed();
  465. }
  466. return expect_connection_failed();
  467. }
  468. int test_cert_unreadable()
  469. {
  470. otlp::OtlpGrpcExporterOptions opts;
  471. set_common_opts(opts);
  472. opts.ssl_credentials_cacert_path = opt_cert_dir + "/unreadable.pem";
  473. instrumented_payload(opts);
  474. if (opt_mode == TestMode::kNone)
  475. {
  476. return expect_connection_failed();
  477. }
  478. if (!opt_secure && (opt_mode == TestMode::kHttp))
  479. {
  480. return expect_success();
  481. }
  482. if (!opt_secure && (opt_mode == TestMode::kHttps))
  483. {
  484. return expect_export_failed();
  485. }
  486. return expect_connection_failed();
  487. }
  488. #ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW
  489. int test_client_cert_not_found()
  490. {
  491. otlp::OtlpGrpcExporterOptions opts;
  492. set_common_opts(opts);
  493. opts.ssl_credentials_cacert_path = opt_cert_dir + "/ca.pem";
  494. opts.ssl_client_cert_path = opt_cert_dir + "/no-such-file.pem";
  495. instrumented_payload(opts);
  496. if (opt_mode == TestMode::kNone)
  497. {
  498. return expect_connection_failed();
  499. }
  500. if (!opt_secure && (opt_mode == TestMode::kHttp))
  501. {
  502. return expect_success();
  503. }
  504. if (!opt_secure && (opt_mode == TestMode::kHttps))
  505. {
  506. return expect_export_failed();
  507. }
  508. return expect_connection_failed();
  509. }
  510. int test_client_cert_invalid()
  511. {
  512. otlp::OtlpGrpcExporterOptions opts;
  513. set_common_opts(opts);
  514. opts.ssl_credentials_cacert_path = opt_cert_dir + "/ca.pem";
  515. opts.ssl_client_cert_path = opt_cert_dir + "/garbage.pem";
  516. instrumented_payload(opts);
  517. if (opt_mode == TestMode::kNone)
  518. {
  519. return expect_connection_failed();
  520. }
  521. if (!opt_secure && (opt_mode == TestMode::kHttp))
  522. {
  523. return expect_success();
  524. }
  525. if (!opt_secure && (opt_mode == TestMode::kHttps))
  526. {
  527. return expect_export_failed();
  528. }
  529. return expect_connection_failed();
  530. }
  531. int test_client_cert_unreadable()
  532. {
  533. otlp::OtlpGrpcExporterOptions opts;
  534. set_common_opts(opts);
  535. opts.ssl_credentials_cacert_path = opt_cert_dir + "/ca.pem";
  536. opts.ssl_client_cert_path = opt_cert_dir + "/unreadable.pem";
  537. instrumented_payload(opts);
  538. if (opt_mode == TestMode::kNone)
  539. {
  540. return expect_connection_failed();
  541. }
  542. if (!opt_secure && (opt_mode == TestMode::kHttp))
  543. {
  544. return expect_success();
  545. }
  546. if (!opt_secure && (opt_mode == TestMode::kHttps))
  547. {
  548. return expect_export_failed();
  549. }
  550. return expect_connection_failed();
  551. }
  552. int test_client_cert_no_key()
  553. {
  554. otlp::OtlpGrpcExporterOptions opts;
  555. set_common_opts(opts);
  556. opts.ssl_credentials_cacert_path = opt_cert_dir + "/ca.pem";
  557. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  558. instrumented_payload(opts);
  559. if (opt_mode == TestMode::kNone)
  560. {
  561. return expect_connection_failed();
  562. }
  563. if (!opt_secure && (opt_mode == TestMode::kHttp))
  564. {
  565. return expect_success();
  566. }
  567. if (!opt_secure && (opt_mode == TestMode::kHttps))
  568. {
  569. return expect_export_failed();
  570. }
  571. return expect_connection_failed();
  572. }
  573. int test_client_key_not_found()
  574. {
  575. otlp::OtlpGrpcExporterOptions opts;
  576. set_common_opts(opts);
  577. opts.ssl_credentials_cacert_path = opt_cert_dir + "/ca.pem";
  578. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  579. opts.ssl_client_key_path = opt_cert_dir + "/no-such-file.pem";
  580. instrumented_payload(opts);
  581. if (opt_mode == TestMode::kNone)
  582. {
  583. return expect_connection_failed();
  584. }
  585. if (!opt_secure && (opt_mode == TestMode::kHttp))
  586. {
  587. return expect_success();
  588. }
  589. if (!opt_secure && (opt_mode == TestMode::kHttps))
  590. {
  591. return expect_export_failed();
  592. }
  593. return expect_connection_failed();
  594. }
  595. int test_client_key_invalid()
  596. {
  597. otlp::OtlpGrpcExporterOptions opts;
  598. set_common_opts(opts);
  599. opts.ssl_credentials_cacert_path = opt_cert_dir + "/ca.pem";
  600. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  601. opts.ssl_client_key_path = opt_cert_dir + "/garbage.pem";
  602. instrumented_payload(opts);
  603. if (opt_mode == TestMode::kNone)
  604. {
  605. return expect_connection_failed();
  606. }
  607. if (!opt_secure && (opt_mode == TestMode::kHttp))
  608. {
  609. return expect_success();
  610. }
  611. if (!opt_secure && (opt_mode == TestMode::kHttps))
  612. {
  613. return expect_export_failed();
  614. }
  615. return expect_connection_failed();
  616. }
  617. int test_client_key_unreadable()
  618. {
  619. otlp::OtlpGrpcExporterOptions opts;
  620. set_common_opts(opts);
  621. opts.ssl_credentials_cacert_path = opt_cert_dir + "/ca.pem";
  622. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  623. opts.ssl_client_key_path = opt_cert_dir + "/unreadable.pem";
  624. instrumented_payload(opts);
  625. if (opt_mode == TestMode::kNone)
  626. {
  627. return expect_connection_failed();
  628. }
  629. if (!opt_secure && (opt_mode == TestMode::kHttp))
  630. {
  631. return expect_success();
  632. }
  633. if (!opt_secure && (opt_mode == TestMode::kHttps))
  634. {
  635. return expect_export_failed();
  636. }
  637. return expect_connection_failed();
  638. }
  639. int test_mtls_ok()
  640. {
  641. otlp::OtlpGrpcExporterOptions opts;
  642. set_common_opts(opts);
  643. opts.ssl_credentials_cacert_path = opt_cert_dir + "/ca.pem";
  644. opts.ssl_client_cert_path = opt_cert_dir + "/client_cert.pem";
  645. opts.ssl_client_key_path = opt_cert_dir + "/client_cert-key.pem";
  646. instrumented_payload(opts);
  647. if (opt_mode == TestMode::kNone)
  648. {
  649. return expect_connection_failed();
  650. }
  651. if (!opt_secure && (opt_mode == TestMode::kHttp))
  652. {
  653. return expect_connection_failed();
  654. }
  655. if (!opt_secure && (opt_mode == TestMode::kHttps))
  656. {
  657. return expect_success();
  658. }
  659. if (opt_secure && (opt_mode == TestMode::kHttp))
  660. {
  661. return expect_connection_failed();
  662. }
  663. return expect_success();
  664. }
  665. #endif // ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW