MCPcopy Create free account
hub / github.com/ShipSecAI/studio / queryLoki

Method queryLoki

backend/src/trace/log-stream.service.ts:183–224  ·  view source on GitHub ↗
(record: WorkflowLogStreamRecord, limit: number)

Source from the content-addressed store, hash-verified

181 }
182
183 private async queryLoki(record: WorkflowLogStreamRecord, limit: number): Promise<LokiEntry[]> {
184 const selector = this.buildSelector(this.normalizeLabels(record.labels));
185 const start = this.toNanoseconds(record.firstTimestamp);
186 const end = this.toNanoseconds(record.lastTimestamp);
187
188 const params = new URLSearchParams({
189 query: selector,
190 start,
191 end,
192 direction: 'forward',
193 limit: limit.toString(),
194 });
195
196 const response = await fetch(this.resolveUrl(`/loki/api/v1/query_range?${params.toString()}`), {
197 method: 'GET',
198 headers: this.buildHeaders(),
199 });
200
201 if (!response.ok) {
202 const errorText = await response.text();
203 throw new ServiceUnavailableException(
204 `Loki query failed: ${response.status} ${response.statusText} - ${errorText}`,
205 );
206 }
207
208 const payload = (await response.json()) as {
209 data?: { result?: { values?: [string, string][] }[] };
210 };
211
212 const entries: LokiEntry[] = [];
213 const results = payload.data?.result ?? [];
214 for (const result of results) {
215 for (const [timestamp, message] of result.values ?? []) {
216 entries.push({
217 timestamp: this.fromNanoseconds(timestamp),
218 message,
219 });
220 }
221 }
222
223 return entries;
224 }
225
226 private async queryLokiTimeRange(
227 selector: string,

Callers

nothing calls this directly

Calls 8

buildSelectorMethod · 0.95
normalizeLabelsMethod · 0.95
toNanosecondsMethod · 0.95
resolveUrlMethod · 0.95
buildHeadersMethod · 0.95
fromNanosecondsMethod · 0.95
fetchFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected