-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(deps): Bump @grafana from 8 to 9.4.3
Signed-off-by: Matthieu MOREL <[email protected]>
- Loading branch information
Showing
10 changed files
with
6,007 additions
and
8,949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ updates: | |
schedule: | ||
interval: "weekly" | ||
groups: | ||
@grafana: | ||
grafana: | ||
patterns: | ||
- "@grafana/*" | ||
labels: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { DataQueryError } from '@grafana/data'; | ||
import { FetchError, FetchResponse, getBackendSrv } from '@grafana/runtime'; | ||
import { of, throwError } from 'rxjs'; | ||
import { catchError } from 'rxjs/operators'; | ||
import { InstantQueryParam, PromDataErrorResponse, PromDataSuccessResponse, PromScalarData, PromVectorData } from './types'; | ||
|
||
export class PrometheusDatasource { | ||
private instantQueryURL; | ||
|
||
constructor(uid?: string) { | ||
this.instantQueryURL = `/api/datasources/proxy/uid/${uid}/api/v1/query`; | ||
} | ||
|
||
async sendInstantQuery(data: InstantQueryParam) { | ||
return getBackendSrv() | ||
.fetch<PromDataSuccessResponse<PromVectorData | PromScalarData>>({ | ||
url: this.instantQueryURL, | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
data, | ||
}).pipe( | ||
catchError((err: FetchError<PromDataErrorResponse<PromVectorData | PromScalarData>>) => { | ||
if (err.cancelled) { | ||
return of(err); | ||
} | ||
return throwError(this.handleErrors(err)); | ||
}) | ||
) | ||
.toPromise() | ||
.then((res: FetchResponse<PromDataSuccessResponse<PromVectorData | PromScalarData>> | FetchError<PromDataErrorResponse<PromVectorData | PromScalarData>>) => { | ||
if (res.status === 200) { | ||
if (res.data.status === 'success') { | ||
return res.data.data.result; | ||
} | ||
throw new Error(`Prom query failed body: ${res.data}`); | ||
} else { | ||
throw new Error(`Failed with status ${res.status} body: ${res.data}`); | ||
} | ||
}); | ||
} | ||
|
||
private handleErrors = (err: any): DataQueryError => { | ||
const error: DataQueryError = { | ||
message: (err && err.statusText) || 'Unknown error during query transaction. Please check JS console logs.', | ||
}; | ||
|
||
if (err.data) { | ||
if (typeof err.data === 'string') { | ||
error.message = err.data; | ||
} else if (err.data.error) { | ||
error.message = this.safeStringifyValue(err.data.error); | ||
} | ||
} else if (err.message) { | ||
error.message = err.message; | ||
} else if (typeof err === 'string') { | ||
error.message = err; | ||
} | ||
|
||
error.status = err.status; | ||
error.statusText = err.statusText; | ||
|
||
return error; | ||
}; | ||
|
||
private safeStringifyValue = (value: any): string => { | ||
if (!value) { | ||
return ''; | ||
} | ||
|
||
try { | ||
return JSON.stringify(value, null); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
return ''; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export interface InstantQueryParam { | ||
query: string; | ||
time: number; | ||
} | ||
|
||
export interface PromDataSuccessResponse<T = PromData> { | ||
status: 'success'; | ||
data: T; | ||
} | ||
|
||
export interface PromDataErrorResponse<T = PromData> { | ||
status: 'error'; | ||
errorType: string; | ||
error: string; | ||
data: T; | ||
} | ||
|
||
export type PromData = PromVectorData | PromScalarData; | ||
|
||
export interface PromVectorData { | ||
resultType: 'vector'; | ||
result: Array<{ | ||
metric: PromMetric; | ||
value: PromValue; | ||
}>; | ||
} | ||
|
||
export interface PromScalarData { | ||
resultType: 'scalar'; | ||
result: PromValue; | ||
} | ||
|
||
export type PromValue = [number, any]; | ||
|
||
export interface PromMetric { | ||
__name__?: string; | ||
[index: string]: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.