Class OpenSearchClientWrapper
This facade coordinates OpenSearch writes with file export, retry handling, and runtime authentication settings so callers can use a small API surface.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intPushes documents in bulk.static booleanPushes a single document.safeTestConnection(String baseUrl) Tests OpenSearch connectivity without authentication, converting runtime failures into a failed status result.safeTestConnection(String baseUrl, String username, String password) Tests OpenSearch connectivity and converts runtime failures into a failed status result.testConnection(String baseUrl) Tests OpenSearch connectivity without authentication.testConnection(String baseUrl, String username, String password) Tests connectivity with optional basic auth.
-
Constructor Details
-
OpenSearchClientWrapper
public OpenSearchClientWrapper()
-
-
Method Details
-
testConnection
Tests OpenSearch connectivity without authentication.- Parameters:
baseUrl- OpenSearch base URL- Returns:
- structured connection status
-
testConnection
public static OpenSearchClientWrapper.OpenSearchStatus testConnection(String baseUrl, String username, String password) Tests connectivity with optional basic auth. Performs a raw GET / so logs show the actual HTTP version and status line from the wire; on 200 parses the response body for version/distribution.- Parameters:
baseUrl- OpenSearch base URLusername- optional basic-auth usernamepassword- optional basic-auth password- Returns:
- structured connection status
-
safeTestConnection
Tests OpenSearch connectivity without authentication, converting runtime failures into a failed status result.- Parameters:
baseUrl- OpenSearch base URL- Returns:
- structured connection status
-
safeTestConnection
public static OpenSearchClientWrapper.OpenSearchStatus safeTestConnection(String baseUrl, String username, String password) Tests OpenSearch connectivity and converts runtime failures into a failed status result.- Parameters:
baseUrl- OpenSearch base URLusername- optional basic-auth usernamepassword- optional basic-auth password- Returns:
- structured connection status
-
pushDocument
public static boolean pushDocument(String baseUrl, String indexName, String indexKey, Map<String, Object> document) Pushes a single document. Delegates to the retry coordinator (one attempt, then queue on failure).Documents are filtered to include only fields enabled in the Fields panel before push.
- Parameters:
baseUrl- OpenSearch base URLindexName- target index namedocument- the document to index (filtered byExportFieldFilter)- Returns:
trueif indexed successfully,falseotherwise
-
pushBulk
public static int pushBulk(String baseUrl, String indexName, String indexKey, List<Map<String, Object>> documents) Pushes documents in bulk. Delegates to the retry coordinator (retries with backoff, then queue failed items).Documents are filtered to include only fields enabled in the Fields panel before push.
Bulk-path responsibilities
The exporter deliberately uses two distinct bulk paths with different guarantees:
OpenSearchClientWrapper.pushBulk(this method) is the retry-coordinated path used by one-shot snapshot reporters (Proxy History, Proxy WebSocket, Sitemap, Findings). It emits to every enabled file sink viaFileExportService.emitBatch(List)and delegates the OpenSearch call toIndexingRetryCoordinator, which retries with backoff and queues failed items for the drain thread. Callers are expected to be small, bounded batches that can tolerate the synchronous round-trip.ChunkedBulkSender.push(java.lang.String, java.lang.String, java.lang.String, java.util.concurrent.BlockingQueue<java.util.Map<java.lang.String, java.lang.Object>>, int, long, long)is the streaming path used by the liveTrafficExportQueuedrain loop. It writes NDJSON directly into the POST body as the queue is drained, applies per-chunk size/byte/time caps, and tracks per-route counts viaTrafficRouteBucket. It does not retry; when a bulk fails the caller is responsible for re-queuing (or dropping) items.
Snapshot reporters stay on
pushBulkbecause losing retry + drain-queue fallback would regress reliability for one-shot waves. Live traffic stays onChunkedBulkSenderbecause its backpressure and streaming body are required under sustained throughput. Both paths route file-sink writes throughFileExportServiceand attribute success/failure throughTrafficRouteBucket, so traffic accounting is consistent regardless of which path a document takes.- Parameters:
baseUrl- OpenSearch base URLindexName- target index namedocuments- documents to index (each filtered byExportFieldFilter)- Returns:
- number of documents successfully indexed
-