mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
Logs: Do not insert log-line into log-fields in json download (#70901)
* logs: do not insert log-line into log-fields in json download * fixed test after merge
This commit is contained in:
parent
b39c62efbf
commit
2084cc9955
@ -12,6 +12,7 @@ describe('logParser', () => {
|
||||
dataFrame: new MutableDataFrame({
|
||||
refId: 'A',
|
||||
fields: [
|
||||
testLineField,
|
||||
testStringField,
|
||||
{
|
||||
name: 'labels',
|
||||
@ -34,6 +35,7 @@ describe('logParser', () => {
|
||||
dataFrame: new MutableDataFrame({
|
||||
refId: 'A',
|
||||
fields: [
|
||||
testLineField,
|
||||
testStringField,
|
||||
{
|
||||
name: 'labels',
|
||||
@ -55,6 +57,7 @@ describe('logParser', () => {
|
||||
dataFrame: new MutableDataFrame({
|
||||
refId: 'A',
|
||||
fields: [
|
||||
testLineField,
|
||||
testStringField,
|
||||
{
|
||||
name: 'labels',
|
||||
@ -83,6 +86,7 @@ describe('logParser', () => {
|
||||
dataFrame: new MutableDataFrame({
|
||||
refId: 'A',
|
||||
fields: [
|
||||
testLineField,
|
||||
testStringField,
|
||||
{
|
||||
name: 'id',
|
||||
@ -138,7 +142,7 @@ describe('logParser', () => {
|
||||
entryFieldIndex: 10,
|
||||
dataFrame: new MutableDataFrame({
|
||||
refId: 'A',
|
||||
fields: [{ ...testStringField }],
|
||||
fields: [testLineField, { ...testStringField }],
|
||||
}),
|
||||
});
|
||||
|
||||
@ -210,6 +214,13 @@ describe('logParser', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const testLineField = {
|
||||
name: 'body',
|
||||
type: FieldType.string,
|
||||
config: {},
|
||||
values: ['line1'],
|
||||
};
|
||||
|
||||
const testStringField = {
|
||||
name: 'test_field_string',
|
||||
type: FieldType.string,
|
||||
|
@ -86,9 +86,26 @@ export const getDataframeFields = memoizeOne(
|
||||
);
|
||||
|
||||
function shouldRemoveField(field: Field, index: number, row: LogRowModel) {
|
||||
// hidden field, remove
|
||||
if (field.config.custom?.hidden) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// field with data-links, keep
|
||||
if ((field.config.links ?? []).length > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// field that has empty value (we want to keep 0 or empty string)
|
||||
if (field.values[row.rowIndex] == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// the remaining checks use knowledge of how we parse logs-dataframes
|
||||
|
||||
// Remove field if it is:
|
||||
// "labels" field that is in Loki used to store all labels
|
||||
if (field.name === 'labels' && field.type === FieldType.other && (field.config.links?.length || 0) === 0) {
|
||||
if (field.name === 'labels' && field.type === FieldType.other) {
|
||||
return true;
|
||||
}
|
||||
// id and tsNs are arbitrary added fields in the backend and should be hidden in the UI
|
||||
@ -103,13 +120,12 @@ function shouldRemoveField(field: Field, index: number, row: LogRowModel) {
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
// hidden field
|
||||
if (field.config.custom?.hidden) {
|
||||
return true;
|
||||
}
|
||||
// field that has empty value (we want to keep 0 or empty string)
|
||||
if (field.values[row.rowIndex] == null) {
|
||||
|
||||
// first string-field is the log-line
|
||||
const firstStringFieldIndex = row.dataFrame.fields.findIndex((f) => f.type === FieldType.string);
|
||||
if (firstStringFieldIndex === index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -221,9 +221,19 @@ describe('checkLogsError()', () => {
|
||||
|
||||
describe('logRowsToReadableJson', () => {
|
||||
const testRow: LogRowModel = {
|
||||
rowIndex: 1,
|
||||
rowIndex: 0,
|
||||
entryFieldIndex: 0,
|
||||
dataFrame: new MutableDataFrame(),
|
||||
dataFrame: {
|
||||
length: 1,
|
||||
fields: [
|
||||
{
|
||||
name: 'body',
|
||||
type: FieldType.string,
|
||||
config: {},
|
||||
values: ['test entry'],
|
||||
},
|
||||
],
|
||||
},
|
||||
entry: 'test entry',
|
||||
hasAnsi: false,
|
||||
hasUnescapedContent: false,
|
||||
@ -239,8 +249,23 @@ describe('logRowsToReadableJson', () => {
|
||||
timeUtc: '',
|
||||
uid: '2',
|
||||
};
|
||||
const testDf = new MutableDataFrame();
|
||||
testDf.addField({ name: 'foo2', values: ['bar2'] });
|
||||
const testDf: DataFrame = {
|
||||
length: 1,
|
||||
fields: [
|
||||
{
|
||||
name: 'body',
|
||||
type: FieldType.string,
|
||||
config: {},
|
||||
values: ['test entry'],
|
||||
},
|
||||
{
|
||||
name: 'foo2',
|
||||
type: FieldType.string,
|
||||
config: {},
|
||||
values: ['bar2'],
|
||||
},
|
||||
],
|
||||
};
|
||||
const testRow2: LogRowModel = {
|
||||
rowIndex: 0,
|
||||
entryFieldIndex: -1,
|
||||
|
Loading…
Reference in New Issue
Block a user