forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'grafana/master' into expose-get-backend…
…-srv * grafana/master: Fix: Bring back styles on Switch components when checked Update CHANGELOG.md Chore: breaks build if certain FrontEnd limits are exceeded (grafana#16301) Fix: Graphite query ast to string fix (grafana#16297) Fix: Template query editor this bind exception fix (grafana#16299) Fix: Alerting Notification channel http api fixes (grafana#16288) Refactor: Move LogLevel and Labels utils to @grafana/ui (grafana#16285) Refactor: Rename Tags to Labels in SeriesData (simple) (grafana#16284) Elasticsearch: Fix view percentiles metric in table without date histogram (grafana#15686) Configuration: Improve session_lifetime comments (grafana#16238) Alerting: Makes timeouts and retries configurable (grafana#16259) Fix: Correct SnapshotData typing (grafana#16279) Feat: Angular panels & SeriesData to Table/TimeSeries (grafana#16266) Fix: React Graph & Show message on no data (grafana#16278)
- Loading branch information
Showing
45 changed files
with
662 additions
and
318 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
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
8 changes: 7 additions & 1 deletion
8
packages/grafana-ui/src/components/Input/__snapshots__/Input.test.tsx.snap
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
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,21 @@ | ||
/** | ||
* Mapping of log level abbreviation to canonical log level. | ||
* Supported levels are reduce to limit color variation. | ||
*/ | ||
export enum LogLevel { | ||
emerg = 'critical', | ||
alert = 'critical', | ||
crit = 'critical', | ||
critical = 'critical', | ||
warn = 'warning', | ||
warning = 'warning', | ||
err = 'error', | ||
eror = 'error', | ||
error = 'error', | ||
info = 'info', | ||
notice = 'info', | ||
dbug = 'debug', | ||
debug = 'debug', | ||
trace = 'trace', | ||
unknown = 'unknown', | ||
} |
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,55 @@ | ||
import { parseLabels, formatLabels, findCommonLabels, findUniqueLabels } from './labels'; | ||
|
||
describe('parseLabels()', () => { | ||
it('returns no labels on empty labels string', () => { | ||
expect(parseLabels('')).toEqual({}); | ||
expect(parseLabels('{}')).toEqual({}); | ||
}); | ||
|
||
it('returns labels on labels string', () => { | ||
expect(parseLabels('{foo="bar", baz="42"}')).toEqual({ foo: 'bar', baz: '42' }); | ||
}); | ||
}); | ||
|
||
describe('formatLabels()', () => { | ||
it('returns no labels on empty label set', () => { | ||
expect(formatLabels({})).toEqual(''); | ||
expect(formatLabels({}, 'foo')).toEqual('foo'); | ||
}); | ||
|
||
it('returns label string on label set', () => { | ||
expect(formatLabels({ foo: 'bar', baz: '42' })).toEqual('{baz="42", foo="bar"}'); | ||
}); | ||
}); | ||
|
||
describe('findCommonLabels()', () => { | ||
it('returns no common labels on empty sets', () => { | ||
expect(findCommonLabels([{}])).toEqual({}); | ||
expect(findCommonLabels([{}, {}])).toEqual({}); | ||
}); | ||
|
||
it('returns no common labels on differing sets', () => { | ||
expect(findCommonLabels([{ foo: 'bar' }, {}])).toEqual({}); | ||
expect(findCommonLabels([{}, { foo: 'bar' }])).toEqual({}); | ||
expect(findCommonLabels([{ baz: '42' }, { foo: 'bar' }])).toEqual({}); | ||
expect(findCommonLabels([{ foo: '42', baz: 'bar' }, { foo: 'bar' }])).toEqual({}); | ||
}); | ||
|
||
it('returns the single labels set as common labels', () => { | ||
expect(findCommonLabels([{ foo: 'bar' }])).toEqual({ foo: 'bar' }); | ||
}); | ||
}); | ||
|
||
describe('findUniqueLabels()', () => { | ||
it('returns no uncommon labels on empty sets', () => { | ||
expect(findUniqueLabels({}, {})).toEqual({}); | ||
}); | ||
|
||
it('returns all labels given no common labels', () => { | ||
expect(findUniqueLabels({ foo: '"bar"' }, {})).toEqual({ foo: '"bar"' }); | ||
}); | ||
|
||
it('returns all labels except the common labels', () => { | ||
expect(findUniqueLabels({ foo: '"bar"', baz: '"42"' }, { foo: '"bar"' })).toEqual({ baz: '"42"' }); | ||
}); | ||
}); |
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,75 @@ | ||
import { Labels } from '../types/data'; | ||
|
||
/** | ||
* Regexp to extract Prometheus-style labels | ||
*/ | ||
const labelRegexp = /\b(\w+)(!?=~?)"([^"\n]*?)"/g; | ||
|
||
/** | ||
* Returns a map of label keys to value from an input selector string. | ||
* | ||
* Example: `parseLabels('{job="foo", instance="bar"}) // {job: "foo", instance: "bar"}` | ||
*/ | ||
export function parseLabels(labels: string): Labels { | ||
const labelsByKey: Labels = {}; | ||
labels.replace(labelRegexp, (_, key, operator, value) => { | ||
labelsByKey[key] = value; | ||
return ''; | ||
}); | ||
return labelsByKey; | ||
} | ||
|
||
/** | ||
* Returns a map labels that are common to the given label sets. | ||
*/ | ||
export function findCommonLabels(labelsSets: Labels[]): Labels { | ||
return labelsSets.reduce( | ||
(acc, labels) => { | ||
if (!labels) { | ||
throw new Error('Need parsed labels to find common labels.'); | ||
} | ||
if (!acc) { | ||
// Initial set | ||
acc = { ...labels }; | ||
} else { | ||
// Remove incoming labels that are missing or not matching in value | ||
Object.keys(labels).forEach(key => { | ||
if (acc[key] === undefined || acc[key] !== labels[key]) { | ||
delete acc[key]; | ||
} | ||
}); | ||
// Remove common labels that are missing from incoming label set | ||
Object.keys(acc).forEach(key => { | ||
if (labels[key] === undefined) { | ||
delete acc[key]; | ||
} | ||
}); | ||
} | ||
return acc; | ||
}, | ||
(undefined as unknown) as Labels | ||
); | ||
} | ||
|
||
/** | ||
* Returns a map of labels that are in `labels`, but not in `commonLabels`. | ||
*/ | ||
export function findUniqueLabels(labels: Labels, commonLabels: Labels): Labels { | ||
const uncommonLabels: Labels = { ...labels }; | ||
Object.keys(commonLabels).forEach(key => { | ||
delete uncommonLabels[key]; | ||
}); | ||
return uncommonLabels; | ||
} | ||
|
||
/** | ||
* Serializes the given labels to a string. | ||
*/ | ||
export function formatLabels(labels: Labels, defaultValue = ''): string { | ||
if (!labels || Object.keys(labels).length === 0) { | ||
return defaultValue; | ||
} | ||
const labelKeys = Object.keys(labels).sort(); | ||
const cleanSelector = labelKeys.map(key => `${key}="${labels[key]}"`).join(', '); | ||
return ['{', cleanSelector, '}'].join(''); | ||
} |
Oops, something went wrong.