Skip to content

Commit

Permalink
Made sessionmanager a private member
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSeufert committed Dec 14, 2020
1 parent 1cbf903 commit e1c34b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class ElasticsearchLogExporter final : public sdklogs::LogExporter
// Configuration options for the exporter
ElasticsearchExporterOptions options_;

// Object that stores the HTTP sessions that have been created
std::unique_ptr<ext::http::client::SessionManager> session_manager_;

/**
* Converts a log record into a nlohmann::json object.
*/
Expand Down
18 changes: 11 additions & 7 deletions exporters/elasticsearch/src/es_log_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ResponseHandler : public http_client::EventHandler
{}

private:
// Define a mutex and condition variable
// Define a condition variable used for blocking
std::condition_variable cv_;

// Whether the response from Elasticsearch has been received
Expand All @@ -84,10 +84,13 @@ class ResponseHandler : public http_client::EventHandler
std::string body_ = "";
};

ElasticsearchLogExporter::ElasticsearchLogExporter() : options_(ElasticsearchExporterOptions()) {}
ElasticsearchLogExporter::ElasticsearchLogExporter()
: options_{ElasticsearchExporterOptions()},
session_manager_{new ext::http::client::curl::SessionManager()}
{}

ElasticsearchLogExporter::ElasticsearchLogExporter(const ElasticsearchExporterOptions &options)
: options_{options}
: options_{options}, session_manager_{new ext::http::client::curl::SessionManager()}
{}

sdklogs::ExportResult ElasticsearchLogExporter::Export(
Expand All @@ -112,8 +115,7 @@ sdklogs::ExportResult ElasticsearchLogExporter::Export(
}

// Create a connection to the ElasticSearch instance
opentelemetry::ext::http::client::curl::SessionManager session_manager;
auto session = session_manager.CreateSession(options_.host_, options_.port_);
auto session = session_manager_->CreateSession(options_.host_, options_.port_);
auto request = session->CreateRequest();

// Populate the request with headers and methods
Expand Down Expand Up @@ -148,8 +150,6 @@ sdklogs::ExportResult ElasticsearchLogExporter::Export(

// End the session
session->FinishSession();
session_manager.CancelAllSessions();
session_manager.FinishAllSessions();

// If the response was never received
if (!receivedResponse)
Expand Down Expand Up @@ -184,6 +184,10 @@ bool ElasticsearchLogExporter::Shutdown(std::chrono::microseconds timeout) noexc
{
isShutdown_ = true;

// Shutdown the session manager
session_manager_->CancelAllSessions();
session_manager_->FinishAllSessions();

return true;
}

Expand Down

0 comments on commit e1c34b1

Please sign in to comment.