mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
Loki: Remove duplicated methods in languageProvider (#77456)
Loki: Remove fuplicated methods in languageProvider
This commit is contained in:
parent
41572238ac
commit
1e065580ac
@ -96,20 +96,6 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method over fetchSeriesLabels to retrieve series labels and handle errors.
|
||||
* @todo remove this in favor of fetchSeriesLabels as we already in this.request do the same thing
|
||||
*/
|
||||
async getSeriesLabels(selector: string) {
|
||||
try {
|
||||
return await this.fetchSeriesLabels(selector);
|
||||
} catch (error) {
|
||||
// TODO: better error handling
|
||||
console.error(error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all label keys
|
||||
* This asynchronous function returns all available label keys from the data source.
|
||||
@ -186,13 +172,6 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
||||
return nanoseconds ? Math.floor(nanoseconds / NS_IN_MS / 1000 / 60 / 5) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo remove this in favor of fetchLabelValues as it is the same thing
|
||||
*/
|
||||
async getLabelValues(key: string): Promise<string[]> {
|
||||
return await this.fetchLabelValues(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch label values
|
||||
*
|
||||
|
@ -62,7 +62,7 @@ export default class LokiCheatSheet extends PureComponent<QueryEditorHelpProps<L
|
||||
const labels = provider.getLabelKeys() || [];
|
||||
const preferredLabel = PREFERRED_LABELS.find((l) => labels.includes(l));
|
||||
if (preferredLabel) {
|
||||
const values = await provider.getLabelValues(preferredLabel);
|
||||
const values = await provider.fetchLabelValues(preferredLabel);
|
||||
const userExamples = shuffle(values)
|
||||
.slice(0, EXAMPLES_LIMIT)
|
||||
.map((value) => `{${preferredLabel}="${value}"}`);
|
||||
|
@ -85,7 +85,7 @@ describe('LokiLabelBrowser', () => {
|
||||
const setupProps = (): BrowserProps => {
|
||||
const mockLanguageProvider = {
|
||||
start: () => Promise.resolve(),
|
||||
getLabelValues: (name: string) => {
|
||||
fetchLabelValues: (name: string) => {
|
||||
switch (name) {
|
||||
case 'label1':
|
||||
return ['value1-1', 'value1-2'];
|
||||
|
@ -350,7 +350,7 @@ export class UnthemedLokiLabelBrowser extends React.Component<BrowserProps, Brow
|
||||
const { languageProvider } = this.props;
|
||||
this.updateLabelState(name, { loading: true }, `Fetching values for ${name}`);
|
||||
try {
|
||||
let rawValues = await languageProvider.getLabelValues(name);
|
||||
let rawValues = await languageProvider.fetchLabelValues(name);
|
||||
// If selector changed, clear loading state and discard result by returning early
|
||||
if (selector !== buildSelector(this.state.labels)) {
|
||||
this.updateLabelState(name, { loading: false }, '');
|
||||
|
@ -66,8 +66,8 @@ describe('CompletionDataProvider', () => {
|
||||
completionProvider = new CompletionDataProvider(languageProvider, historyRef);
|
||||
|
||||
jest.spyOn(languageProvider, 'getLabelKeys').mockReturnValue(labelKeys);
|
||||
jest.spyOn(languageProvider, 'getLabelValues').mockResolvedValue(labelValues);
|
||||
jest.spyOn(languageProvider, 'getSeriesLabels').mockResolvedValue(seriesLabels);
|
||||
jest.spyOn(languageProvider, 'fetchLabelValues').mockResolvedValue(labelValues);
|
||||
jest.spyOn(languageProvider, 'fetchSeriesLabels').mockResolvedValue(seriesLabels);
|
||||
jest.spyOn(languageProvider, 'getParserAndLabelKeys').mockResolvedValue(parserAndLabelKeys);
|
||||
});
|
||||
|
||||
|
@ -51,7 +51,7 @@ export class CompletionDataProvider {
|
||||
async getLabelValues(labelName: string, otherLabels: Label[]) {
|
||||
if (otherLabels.length === 0) {
|
||||
// if there is no filtering, we have to use a special endpoint
|
||||
return await this.languageProvider.getLabelValues(labelName);
|
||||
return await this.languageProvider.fetchLabelValues(labelName);
|
||||
}
|
||||
|
||||
const data = await this.getSeriesLabels(otherLabels);
|
||||
@ -90,6 +90,6 @@ export class CompletionDataProvider {
|
||||
}
|
||||
|
||||
async getSeriesLabels(labels: Label[]) {
|
||||
return await this.languageProvider.getSeriesLabels(this.buildSelector(labels)).then((data) => data ?? {});
|
||||
return await this.languageProvider.fetchSeriesLabels(this.buildSelector(labels)).then((data) => data ?? {});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user