Commit 263dcb14 by Andrej Ocenas Committed by GitHub

Chore: Fix bunch of strict null error to fix master CI (#23443)

* Fix bunch of null error

* Fix failing test

* Another test fix
parent 363bf750
......@@ -38,7 +38,7 @@ export class PanelPlugin<TOptions = any, TFieldConfigOptions extends object = an
private _optionEditors?: PanelOptionEditorsRegistry;
private registerOptionEditors?: (builder: PanelOptionsEditorBuilder<TOptions>) => void;
panel: ComponentType<PanelProps<TOptions>>;
panel: ComponentType<PanelProps<TOptions>> | null;
editor?: ComponentClass<PanelEditorProps<TOptions>>;
onPanelMigration?: PanelMigrationHandler<TOptions>;
onPanelTypeChanged?: PanelTypeChangedHandler<TOptions>;
......@@ -49,7 +49,7 @@ export class PanelPlugin<TOptions = any, TFieldConfigOptions extends object = an
*/
angularPanelCtrl?: any;
constructor(panel: ComponentType<PanelProps<TOptions>>) {
constructor(panel: ComponentType<PanelProps<TOptions>> | null) {
super();
this.panel = panel;
}
......
......@@ -51,7 +51,7 @@ export function findCommonLabels(labelsSets: Labels[]): Labels {
/**
* Returns a map of labels that are in `labels`, but not in `commonLabels`.
*/
export function findUniqueLabels(labels: Labels, commonLabels: Labels): Labels {
export function findUniqueLabels(labels: Labels | undefined, commonLabels: Labels): Labels {
const uncommonLabels: Labels = { ...labels };
Object.keys(commonLabels).forEach(key => {
delete uncommonLabels[key];
......
......@@ -218,7 +218,7 @@ describe('dataFrameToLogsModel', () => {
},
}),
];
const logsModel = dataFrameToLogsModel(series, 0, 'utc');
const logsModel = dataFrameToLogsModel(series, 1, 'utc');
expect(logsModel.hasUniqueLabels).toBeFalsy();
expect(logsModel.rows).toHaveLength(2);
expect(logsModel.rows).toMatchObject([
......@@ -274,12 +274,12 @@ describe('dataFrameToLogsModel', () => {
],
}),
];
const logsModel = dataFrameToLogsModel(series, 0, 'utc');
const logsModel = dataFrameToLogsModel(series, 1, 'utc');
expect(logsModel.rows).toHaveLength(1);
expect(logsModel.rows).toMatchObject([
{
entry: 'WARN boooo',
labels: undefined,
labels: {},
logLevel: LogLevel.debug,
uniqueLabels: {},
},
......@@ -338,7 +338,7 @@ describe('dataFrameToLogsModel', () => {
],
}),
];
const logsModel = dataFrameToLogsModel(series, 0, 'utc');
const logsModel = dataFrameToLogsModel(series, 1, 'utc');
expect(logsModel.hasUniqueLabels).toBeTruthy();
expect(logsModel.rows).toHaveLength(3);
expect(logsModel.rows).toMatchObject([
......@@ -448,7 +448,7 @@ describe('dataFrameToLogsModel', () => {
],
}),
];
const logsModel = dataFrameToLogsModel(series, 0, 'utc');
const logsModel = dataFrameToLogsModel(series, 1, 'utc');
expect(logsModel.hasUniqueLabels).toBeTruthy();
expect(logsModel.rows).toHaveLength(4);
expect(logsModel.rows).toMatchObject([
......@@ -497,7 +497,7 @@ describe('dataFrameToLogsModel', () => {
],
}),
];
const logsModel = dataFrameToLogsModel(series, 0, 'utc');
const logsModel = dataFrameToLogsModel(series, 1, 'utc');
expect(logsModel.rows[0].uid).toBe('0');
});
......
......@@ -192,14 +192,19 @@ function isLogsData(series: DataFrame) {
* @param dataFrame
* @param intervalMs In case there are no metrics series, we use this for computing it from log rows.
*/
export function dataFrameToLogsModel(dataFrame: DataFrame[], intervalMs: number, timeZone: TimeZone): LogsModel {
export function dataFrameToLogsModel(
dataFrame: DataFrame[],
intervalMs: number | undefined,
timeZone: TimeZone
): LogsModel {
const { logSeries, metricSeries } = separateLogsAndMetrics(dataFrame);
const logsModel = logSeriesToLogsModel(logSeries);
if (logsModel) {
if (metricSeries.length === 0) {
// Create metrics from logs
logsModel.series = makeSeriesForLogs(logsModel.rows, intervalMs, timeZone);
// If interval is not defined or 0 we cannot really compute the series
logsModel.series = intervalMs ? makeSeriesForLogs(logsModel.rows, intervalMs, timeZone) : [];
} else {
// We got metrics in the dataFrame so process those
logsModel.series = getGraphSeriesModel(
......@@ -270,7 +275,7 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
// Assume the first string field in the dataFrame is the message. This was right so far but probably needs some
// more explicit checks.
const stringField = fieldCache.getFirstFieldOfType(FieldType.string);
if (stringField.labels) {
if (stringField?.labels) {
allLabels.push(stringField.labels);
}
return {
......@@ -279,7 +284,7 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
stringField,
logLevelField: fieldCache.getFieldByName('level'),
idField: getIdField(fieldCache),
};
} as LogFields;
});
const commonLabels = allLabels.length > 0 ? findCommonLabels(allLabels) : {};
......@@ -334,7 +339,7 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
searchWords,
entry: hasAnsi ? ansicolor.strip(message) : message,
raw: message,
labels: stringField.labels,
labels: stringField.labels || {},
uid: idField ? idField.values.get(j) : j.toString(),
});
}
......
......@@ -507,7 +507,7 @@ export enum SortOrder {
export const refreshIntervalToSortOrder = (refreshInterval?: string) =>
RefreshPicker.isLive(refreshInterval) ? SortOrder.Ascending : SortOrder.Descending;
export const sortLogsResult = (logsResult: LogsModel, sortOrder: SortOrder): LogsModel => {
export const sortLogsResult = (logsResult: LogsModel | null, sortOrder: SortOrder): LogsModel => {
const rows = logsResult ? logsResult.rows : [];
sortOrder === SortOrder.Ascending ? rows.sort(sortInAscendingOrder) : rows.sort(sortInDescendingOrder);
const result: LogsModel = logsResult ? { ...logsResult, rows } : { hasUniqueLabels: false, rows };
......
......@@ -179,7 +179,7 @@ describe('ResultProcessor', () => {
entry: 'third',
entryFieldIndex: 2,
hasAnsi: false,
labels: undefined,
labels: {},
logLevel: 'unknown',
raw: 'third',
searchWords: [] as string[],
......@@ -196,7 +196,7 @@ describe('ResultProcessor', () => {
entry: 'second message',
entryFieldIndex: 2,
hasAnsi: false,
labels: undefined,
labels: {},
logLevel: 'unknown',
raw: 'second message',
searchWords: [] as string[],
......@@ -213,7 +213,7 @@ describe('ResultProcessor', () => {
entry: 'this is a message',
entryFieldIndex: 2,
hasAnsi: false,
labels: undefined,
labels: {},
logLevel: 'unknown',
raw: 'this is a message',
searchWords: [] as string[],
......
......@@ -21,7 +21,7 @@ export const LogsPanel: React.FunctionComponent<LogsPanelProps> = ({
);
}
const newResults = data ? dataFrameToLogsModel(data.series, data.request.intervalMs, timeZone) : null;
const newResults = data ? dataFrameToLogsModel(data.series, data.request?.intervalMs, timeZone) : null;
const sortedNewResults = sortLogsResult(newResults, sortOrder);
return (
......
......@@ -658,7 +658,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
window.location.href = linkInfo.href;
} else {
$timeout(() => {
$location.url(locationUtil.stripBaseFromUrl(linkInfo.href));
$location.url(locationUtil.stripBaseFromUrl(linkInfo!.href));
});
}
......
......@@ -4,7 +4,7 @@ echo -e "Collecting code stats (typescript errors & more)"
ERROR_COUNT_LIMIT=798
ERROR_COUNT_LIMIT=795
DIRECTIVES_LIMIT=172
CONTROLLERS_LIMIT=139
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment