mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Enable correlations links for traceView formatted fields * Add other links to the span UI * Show both “legacy” and dataframe links * bandaid test * Remove special path logic, stringify all non strings before applying regex * Fix test * Do not create new instance of factory for every call, change header to correlations * Get links from more than one field * Remove categories * Fix google cloud link tests * Add test for multiple internal links * Remove changes to datasources provisioning * Added sorting, changed log link title
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import logfmt from 'logfmt';
|
|
|
|
import { ScopedVars, DataLinkTransformationConfig, SupportedTransformationType } from '@grafana/data';
|
|
import { safeStringifyValue } from 'app/core/utils/explore';
|
|
|
|
export const getTransformationVars = (
|
|
transformation: DataLinkTransformationConfig,
|
|
fieldValue: string,
|
|
fieldName: string
|
|
): ScopedVars => {
|
|
let transformationScopedVars: ScopedVars = {};
|
|
let transformVal: { [key: string]: string | boolean | null | undefined } = {};
|
|
if (transformation.type === SupportedTransformationType.Regex && transformation.expression) {
|
|
const regexp = new RegExp(transformation.expression, 'gi');
|
|
const stringFieldVal = typeof fieldValue === 'string' ? fieldValue : safeStringifyValue(fieldValue);
|
|
|
|
const matches = stringFieldVal.matchAll(regexp);
|
|
for (const match of matches) {
|
|
if (match.groups) {
|
|
transformVal = match.groups;
|
|
} else {
|
|
transformVal[transformation.mapValue || fieldName] = match[1] || match[0];
|
|
}
|
|
}
|
|
} else if (transformation.type === SupportedTransformationType.Logfmt) {
|
|
transformVal = logfmt.parse(fieldValue);
|
|
}
|
|
|
|
Object.keys(transformVal).forEach((key) => {
|
|
const transformValString =
|
|
typeof transformVal[key] === 'string' ? transformVal[key] : safeStringifyValue(transformVal[key]);
|
|
transformationScopedVars[key] = { value: transformValString };
|
|
});
|
|
|
|
return transformationScopedVars;
|
|
};
|