@ -12,6 +12,7 @@ import {
} from '@grafana/data' ;
import { BackendSrvRequest } from '@grafana/runtime' ;
import { DEFAULT_SERIES_LIMIT , REMOVE_SERIES_LIMIT } from './components/PrometheusMetricsBrowser' ;
import { Label } from './components/monaco-query-field/monaco-completion-provider/situation' ;
import { PrometheusDatasource } from './datasource' ;
import {
@ -30,6 +31,13 @@ const EMPTY_SELECTOR = '{}';
// Max number of items (metrics, labels, values) that we display as suggestions. Prevents from running out of memory.
export const SUGGESTIONS_LIMIT = 10000 ;
type UrlParamsType = {
start? : string ;
end? : string ;
'match[]' ? : string ;
limit? : string ;
} ;
const buildCacheHeaders = ( durationInSeconds : number ) = > {
return {
headers : {
@ -181,7 +189,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
if ( selector === EMPTY_SELECTOR ) {
return await this . fetchDefaultSeries ( ) ;
} else {
return await this . fetchSeriesLabels ( selector , withName ) ;
return await this . fetchSeriesLabels ( selector , withName , REMOVE_SERIES_LIMIT ) ;
}
} catch ( error ) {
// TODO: better error handling
@ -325,7 +333,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
if ( this . datasource . hasLabelsMatchAPISupport ( ) ) {
return this . fetchSeriesLabelsMatch ( name , withName ) ;
} else {
return this . fetchSeriesLabels ( name , withName ) ;
return this . fetchSeriesLabels ( name , withName , REMOVE_SERIES_LIMIT ) ;
}
} ;
@ -334,14 +342,24 @@ export default class PromQlLanguageProvider extends LanguageProvider {
* they can change over requested time .
* @param name
* @param withName
* @param withLimit
* /
fetchSeriesLabels = async ( name : string , withName? : boolean ) : Promise < Record < string , string [ ] > > = > {
fetchSeriesLabels = async (
name : string ,
withName? : boolean ,
withLimit? : string
) : Promise < Record < string , string [ ] > > = > {
const interpolatedName = this . datasource . interpolateString ( name ) ;
const range = this . datasource . getAdjustedInterval ( this . timeRange ) ;
const urlParams = {
let urlParams : UrlParamsType = {
. . . range ,
'match[]' : interpolatedName ,
} ;
if ( withLimit !== 'none' ) {
urlParams = { . . . urlParams , limit : withLimit ? ? DEFAULT_SERIES_LIMIT } ;
}
const url = ` /api/v1/series ` ;
const data = await this . request ( url , [ ] , urlParams , this . getDefaultCacheHeaders ( ) ) ;