Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
plugins
/
datasource
/
loki
/
File Content:
LiveStreams.ts
import { Observable, throwError, timer } from 'rxjs'; import { finalize, map, retryWhen, mergeMap } from 'rxjs/operators'; import { webSocket } from 'rxjs/webSocket'; import { DataFrame, FieldType, KeyValue, CircularDataFrame } from '@grafana/data'; import { appendResponseToBufferedData } from './liveStreamsResultTransformer'; import { LokiTailResponse } from './types'; /** * Maps directly to a query in the UI (refId is key) */ export interface LokiLiveTarget { query: string; url: string; refId: string; size: number; } /** * Cache of websocket streams that can be returned as observable. In case there already is a stream for particular * target it is returned and on subscription returns the latest dataFrame. */ export class LiveStreams { private streams: KeyValue<Observable<DataFrame[]>> = {}; getStream(target: LokiLiveTarget, retryInterval = 5000): Observable<DataFrame[]> { let stream = this.streams[target.url]; if (stream) { return stream; } const data = new CircularDataFrame({ capacity: target.size }); data.addField({ name: 'Time', type: FieldType.time, config: {} }); data.addField({ name: 'Line', type: FieldType.string }); data.addField({ name: 'id', type: FieldType.string }); data.meta = { ...data.meta, preferredVisualisationType: 'logs' }; data.refId = target.refId; stream = webSocket<LokiTailResponse>(target.url).pipe( map((response: LokiTailResponse) => { appendResponseToBufferedData(response, data); return [data]; }), retryWhen((attempts: Observable<any>) => attempts.pipe( mergeMap((error, i) => { const retryAttempt = i + 1; // Code 1006 is used to indicate that a connection was closed abnormally. // Added hard limit of 30 on number of retries. // If connection was closed abnormally, and we wish to retry, otherwise throw error. if (error.code === 1006 && retryAttempt < 30) { if (retryAttempt > 10) { // If more than 10 times retried, consol.warn, but keep reconnecting console.warn( `Websocket connection is being disrupted. We keep reconnecting but consider starting new live tailing again. Error: ${error.reason}` ); } // Retry every 5s return timer(retryInterval); } return throwError(error); }) ) ), finalize(() => { delete this.streams[target.url]; }) ); this.streams[target.url] = stream; return stream; } }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
__mocks__
---
0755
components
---
0755
configuration
---
0755
docs
---
0755
img
---
0755
migrations
---
0755
querybuilder
---
0755
LanguageProvider.test.ts
23374 bytes
0644
LanguageProvider.ts
13424 bytes
0644
LiveStreams.test.ts
7021 bytes
0644
LiveStreams.ts
2641 bytes
0644
LogContextProvider.test.ts
21477 bytes
0644
LogContextProvider.ts
14192 bytes
0644
LokiVariableSupport.test.ts
3307 bytes
0644
LokiVariableSupport.ts
984 bytes
0644
README.md
127 bytes
0644
backendResultTransformer.test.ts
5537 bytes
0644
backendResultTransformer.ts
5248 bytes
0644
dataquery.cue
1633 bytes
0644
dataquery.gen.ts
1269 bytes
0644
datasource.test.ts
67600 bytes
0644
datasource.ts
42882 bytes
0644
getDerivedFields.test.ts
6291 bytes
0644
getDerivedFields.ts
4351 bytes
0644
languageUtils.test.ts
4461 bytes
0644
languageUtils.ts
5123 bytes
0644
language_utils.test.ts
1463 bytes
0644
lineParser.test.ts
1846 bytes
0644
lineParser.ts
912 bytes
0644
liveStreamsResultTransformer.test.ts
3396 bytes
0644
liveStreamsResultTransformer.ts
2624 bytes
0644
logsTimeSplitting.test.ts
1463 bytes
0644
logsTimeSplitting.ts
1661 bytes
0644
makeTableFrames.test.ts
3834 bytes
0644
makeTableFrames.ts
2415 bytes
0644
metricTimeSplitting.test.ts
2925 bytes
0644
metricTimeSplitting.ts
1586 bytes
0644
modifyQuery.test.ts
27450 bytes
0644
modifyQuery.ts
20058 bytes
0644
module.test.ts
2975 bytes
0644
module.ts
809 bytes
0644
plugin.json
756 bytes
0644
queryHints.test.ts
7526 bytes
0644
queryHints.ts
4453 bytes
0644
querySplitting.test.ts
20808 bytes
0644
querySplitting.ts
9911 bytes
0644
queryUtils.test.ts
20063 bytes
0644
queryUtils.ts
11174 bytes
0644
responseUtils.test.ts
5757 bytes
0644
responseUtils.ts
4637 bytes
0644
sortDataFrame.test.ts
5184 bytes
0644
sortDataFrame.ts
2708 bytes
0644
streaming.test.ts
1264 bytes
0644
streaming.ts
2939 bytes
0644
syntax.test.ts
3545 bytes
0644
syntax.ts
7646 bytes
0644
tracking.test.ts
6407 bytes
0644
tracking.ts
8353 bytes
0644
types.ts
2568 bytes
0644
N4ST4R_ID | Naxtarrr