Skip to content

Commit

Permalink
Use real dataView in resolved logView
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Oct 25, 2022
1 parent 6256bc8 commit 3595f0f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const createResolvedLogViewMock = (

export const createResolvedLogViewMockFromAttributes = (logViewAttributes: LogViewAttributes) =>
resolveLogView(
'log-view-id',
logViewAttributes,
{
get: async () => createStubDataView({ spec: {} }),
Expand Down
35 changes: 17 additions & 18 deletions x-pack/plugins/infra/common/log_views/resolved_log_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ export interface ResolvedLogView {
}

export const resolveLogView = async (
logViewId: string,
logViewAttributes: LogViewAttributes,
dataViewsService: DataViewsContract,
config: LogViewsStaticConfig
): Promise<ResolvedLogView> => {
if (logViewAttributes.logIndices.type === 'index_name') {
return await resolveLegacyReference(logViewAttributes, dataViewsService, config);
return await resolveLegacyReference(logViewId, logViewAttributes, dataViewsService, config);
} else {
return await resolveDataViewReference(logViewAttributes, dataViewsService);
}
};

const resolveLegacyReference = async (
logViewId: string,
logViewAttributes: LogViewAttributes,
dataViewsService: DataViewsContract,
config: LogViewsStaticConfig
Expand All @@ -49,30 +51,27 @@ const resolveLegacyReference = async (

const indices = logViewAttributes.logIndices.indexName;

const fields = await dataViewsService
.getFieldsForWildcard({
pattern: indices,
allowNoIndex: true,
})
const dataViewReference = await dataViewsService
.create(
{
id: `log-view-${logViewId}`,
title: indices,
timeFieldName: TIMESTAMP_FIELD,
allowNoIndex: true,
},
false,
false
)
.catch((error) => {
throw new ResolveLogViewError(
`Failed to fetch fields for indices "${indices}": ${error}`,
error
);
throw new ResolveLogViewError(`Failed to create Data View reference: ${error}`, error);
});

const dataViewReference = await dataViewsService.create({
id: '___InfraLogsLegacyLogViewReference___',
title: logViewAttributes.logIndices.indexName,
timeFieldName: TIMESTAMP_FIELD,
});

return {
indices: logViewAttributes.logIndices.indexName,
indices,
timestampField: TIMESTAMP_FIELD,
tiebreakerField: TIEBREAKER_FIELD,
messageField: config.messageFields,
fields,
fields: dataViewReference.fields,
runtimeMappings: {},
columns: logViewAttributes.logColumns,
name: logViewAttributes.name,
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/infra/public/hooks/use_log_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const useLogView = ({

const load = useCallback(async () => {
const loadedLogView = await loadLogView(logViewId);
const resolvedLoadedLogView = await resolveLogView(loadedLogView.attributes);
const resolvedLoadedLogView = await resolveLogView(loadedLogView.id, loadedLogView.attributes);
const resolvedLogViewStatus = await loadLogViewStatus(resolvedLoadedLogView);

return [loadedLogView, resolvedLoadedLogView, resolvedLogViewStatus];
Expand All @@ -102,7 +102,10 @@ export const useLogView = ({
const update = useCallback(
async (logViewAttributes: Partial<LogViewAttributes>) => {
const updatedLogView = await updateLogView(logViewId, logViewAttributes);
const resolvedUpdatedLogView = await resolveLogView(updatedLogView.attributes);
const resolvedUpdatedLogView = await resolveLogView(
updatedLogView.id,
updatedLogView.attributes
);
const resolvedLogViewStatus = await loadLogViewStatus(resolvedUpdatedLogView);

return [updatedLogView, resolvedUpdatedLogView, resolvedLogViewStatus];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class LogViewsClient implements ILogViewsClient {

public async getResolvedLogView(logViewId: string): Promise<ResolvedLogView> {
const logView = await this.getLogView(logViewId);
const resolvedLogView = await this.resolveLogView(logView.attributes);
const resolvedLogView = await this.resolveLogView(logView.id, logView.attributes);
return resolvedLogView;
}

Expand Down Expand Up @@ -118,8 +118,11 @@ export class LogViewsClient implements ILogViewsClient {
return data;
}

public async resolveLogView(logViewAttributes: LogViewAttributes): Promise<ResolvedLogView> {
return await resolveLogView(logViewAttributes, this.dataViews, this.config);
public async resolveLogView(
logViewId: string,
logViewAttributes: LogViewAttributes
): Promise<ResolvedLogView> {
return await resolveLogView(logViewId, logViewAttributes, this.dataViews, this.config);
}
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/infra/public/services/log_views/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ export interface ILogViewsClient {
getResolvedLogViewStatus(resolvedLogView: ResolvedLogView): Promise<LogViewStatus>;
getResolvedLogView(logViewId: string): Promise<ResolvedLogView>;
putLogView(logViewId: string, logViewAttributes: Partial<LogViewAttributes>): Promise<LogView>;
resolveLogView(logViewAttributes: LogViewAttributes): Promise<ResolvedLogView>;
resolveLogView(logViewId: string, logViewAttributes: LogViewAttributes): Promise<ResolvedLogView>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('LogViewsClient class', () => {
})
);

const resolvedLogView = await logViewsClient.resolveLogView({
const resolvedLogView = await logViewsClient.resolveLogView('log-view-id', {
name: 'LOG VIEW',
description: 'LOG VIEW DESCRIPTION',
logIndices: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class LogViewsClient implements ILogViewsClient {

public async getResolvedLogView(logViewId: string): Promise<ResolvedLogView> {
const logView = await this.getLogView(logViewId);
const resolvedLogView = await this.resolveLogView(logView.attributes);
const resolvedLogView = await this.resolveLogView(logView.id, logView.attributes);
return resolvedLogView;
}

Expand Down Expand Up @@ -98,8 +98,11 @@ export class LogViewsClient implements ILogViewsClient {
return getLogViewFromSavedObject(savedObject);
}

public async resolveLogView(logViewAttributes: LogViewAttributes): Promise<ResolvedLogView> {
return await resolveLogView(logViewAttributes, await this.dataViews, this.config);
public async resolveLogView(
logViewId: string,
logViewAttributes: LogViewAttributes
): Promise<ResolvedLogView> {
return await resolveLogView(logViewId, logViewAttributes, await this.dataViews, this.config);
}

private async getSavedLogView(logViewId: string): Promise<LogView> {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/infra/server/services/log_views/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ export interface ILogViewsClient {
getLogView(logViewId: string): Promise<LogView>;
getResolvedLogView(logViewId: string): Promise<ResolvedLogView>;
putLogView(logViewId: string, logViewAttributes: Partial<LogViewAttributes>): Promise<LogView>;
resolveLogView(logViewAttributes: LogViewAttributes): Promise<ResolvedLogView>;
resolveLogView(logViewId: string, logViewAttributes: LogViewAttributes): Promise<ResolvedLogView>;
}

0 comments on commit 3595f0f

Please sign in to comment.