Package codes.grow.packages.loki
Class LokiLogQueryClient
java.lang.Object
codes.grow.packages.loki.LokiLogQueryClient
- All Implemented Interfaces:
LogQueryClient
LogQueryClient of the logging category on top of the Loki query API: search
(query_range, merge-sorted across streams, cursor pagination), tail (WebSocket),
listStreams (series), listLabels (labels) and waitForLog.
Records are normalized: the line becomes body; structured metadata and parsed labels
become attributes (the SDK's own keys map back to severity, traceId,
spanId, traceFlags and observedTimestamp); stream labels become
resource (service_name → service.name, deployment_environment →
deployment.environment, …).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSelector used for free-text searches andlistStreams().static final intLargestlimitLoki accepts per query by default (max_entries_limit_per_query). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionLabel names of the default window.AsynchronousLogQueryClient.listLabels().Every stream of the default window as a label-set string ({a="b", c="d"}), sorted.AsynchronousLogQueryClient.listStreams().search(String query, SearchOptions options) Searches withquery_range.searchAsync(String query, SearchOptions options) AsynchronousLogQueryClient.search(String, SearchOptions).tail(String query, Consumer<LogRecord> onRecord, TailOptions options) Live tail over the WebSocket API.static StringTurns a search text into LogQL: text starting with{is LogQL as is; anything else is a case-sensitive substring search over every stream ({service_name=~".+"} |= "<text>").static LogRecordtoLogRecord(Map<String, String> labels, StreamEntry entry) Converts one Loki entry to a normalizedLogRecord.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface codes.grow.packages.loki.logging.LogQueryClient
search, waitForLog, waitForLog, waitForLogAsync
-
Field Details
-
MAX_QUERY_LIMIT
public static final int MAX_QUERY_LIMITLargestlimitLoki accepts per query by default (max_entries_limit_per_query).- See Also:
-
ALL_STREAMS_SELECTOR
Selector used for free-text searches andlistStreams().- See Also:
-
-
Constructor Details
-
LokiLogQueryClient
Creates a query client.- Parameters:
client- client (and tenant) to query
-
-
Method Details
-
toLogQL
Turns a search text into LogQL: text starting with{is LogQL as is; anything else is a case-sensitive substring search over every stream ({service_name=~".+"} |= "<text>").- Parameters:
query- search text or LogQL- Returns:
- LogQL
-
toLogRecord
Converts one Loki entry to a normalizedLogRecord.- Parameters:
labels- stream labelsentry- entry- Returns:
- the record
-
search
Searches withquery_range.queryis LogQL (starting with{) or free text. OrderDESC(default) is newest first. PassnextCursorback ascursorfor the next page; the cursor is<timestamp>:<entries at that timestamp already returned>, so pages never skip or repeat entries sharing a nanosecond.totalis not available from Loki.- Specified by:
searchin interfaceLogQueryClient- Parameters:
query- LogQL or free textoptions- window, limit (1–5000), order, cursor- Returns:
- one page of records
-
searchAsync
Description copied from interface:LogQueryClientAsynchronousLogQueryClient.search(String, SearchOptions).- Specified by:
searchAsyncin interfaceLogQueryClient- Parameters:
query- query textoptions- options- Returns:
- future page
-
tail
Live tail over the WebSocket API.options.start()defaults to now, so only new records arrive. Connection errors and abnormal closes go tooptions.onError().- Specified by:
tailin interfaceLogQueryClient- Parameters:
query- LogQL selector or free textonRecord- receives every record (oldest first within a frame)options- start and error callback (intervalis not used: Loki streams)- Returns:
- a handle;
stop()closes the socket
-
listStreams
Every stream of the default window as a label-set string ({a="b", c="d"}), sorted.- Specified by:
listStreamsin interfaceLogQueryClient- Returns:
- stream label sets
-
listStreamsAsync
Description copied from interface:LogQueryClientAsynchronousLogQueryClient.listStreams().- Specified by:
listStreamsAsyncin interfaceLogQueryClient- Returns:
- future names
-
listLabels
Label names of the default window.- Specified by:
listLabelsin interfaceLogQueryClient- Returns:
- label names
-
listLabelsAsync
Description copied from interface:LogQueryClientAsynchronousLogQueryClient.listLabels().- Specified by:
listLabelsAsyncin interfaceLogQueryClient- Returns:
- future names
-