(record: WorkflowLogStreamRecord, limit: number)
| 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, |
nothing calls this directly
no test coverage detected