Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] Remove kibana version from report flyout in serverless #196670

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('GetCsvReportPanelAction', () => {
enablePanelActionDownload: false,
};

apiClient = new ReportingAPIClient(core.http, core.uiSettings, '7.15.0');
apiClient = new ReportingAPIClient(core.http, core.uiSettings, '7.15.0', false);
jest.spyOn(apiClient, 'createReportingJob');

mockLicenseState = 'valid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ReportingAPIClient', () => {
beforeEach(() => {
uiSettingsClient = uiSettingsServiceMock.createStartContract();
httpClient = httpServiceMock.createStartContract({ basePath: '/base/path' });
apiClient = new ReportingAPIClient(httpClient, uiSettingsClient, 'version');
apiClient = new ReportingAPIClient(httpClient, uiSettingsClient, 'version', false);
});

describe('getReportURL', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-reporting/public/reporting_api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export class ReportingAPIClient implements IReportingAPI {
constructor(
http: HttpSetup,
private uiSettings: IUiSettingsClient,
private kibanaVersion: string
private kibanaVersion: string,
private isServerless: boolean
) {
this.http = http;
}
Expand Down Expand Up @@ -264,4 +265,6 @@ export class ReportingAPIClient implements IReportingAPI {
public migrateReportingIndicesIlmPolicy() {
return this.http.put(INTERNAL_ROUTES.MIGRATE.MIGRATE_ILM_POLICY);
}

public getIsServerless = () => this.isServerless;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ReportingPanelContent', () => {
return 'Mars';
}
});
apiClient = new ReportingAPIClient(http, uiSettings, '7.15.0-test');
apiClient = new ReportingAPIClient(http, uiSettings, '7.15.0-test', false);
});

const { getStartServices } = coreMock.createSetup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ uiSettings.get.mockImplementation((key: string) => {
return 'Mars';
}
});
const apiClient = new ReportingAPIClient(http, uiSettings, '7.15.0');
const apiClient = new ReportingAPIClient(http, uiSettings, '7.15.0', false);

const getJobParamsDefault = () => ({
objectType: 'test-object-type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ const mockJobsFound: Job[] = [
].map((j) => new Job(j as ReportApiJSON)); // prettier-ignore

const coreSetup = coreMock.createSetup();
const jobQueueClientMock = new ReportingAPIClient(coreSetup.http, coreSetup.uiSettings, '7.15.0');
const jobQueueClientMock = new ReportingAPIClient(
coreSetup.http,
coreSetup.uiSettings,
'7.15.0',
false
);
jobQueueClientMock.findForJobIds = async () => mockJobsFound;
jobQueueClientMock.getInfo = () =>
Promise.resolve({ content: 'this is the completed report data' } as unknown as Job);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export type TestBed = Awaited<ReturnType<typeof setup>>;
export const setup = async (props?: Partial<Props>) => {
const uiSettingsClient = coreMock.createSetup().uiSettings;
const httpService = httpServiceMock.createSetupContract();
const reportingAPIClient = new ReportingAPIClient(httpService, uiSettingsClient, 'x.x.x');
const reportingAPIClient = new ReportingAPIClient(httpService, uiSettingsClient, 'x.x.x', false);

jest
.spyOn(reportingAPIClient, 'list')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ interface Props {

export const ReportInfoFlyout: FunctionComponent<Props> = ({ config, onClose, job }) => {
const isMounted = useMountedState();

const { apiClient } = useInternalApiClient();
const isServerless = apiClient.getIsServerless();
Copy link
Member

@tsullivan tsullivan Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall changes in this PR can be simplified, since there already is an indication of whether the deployment is serverless in the config.statefulSettings.enabled value, and the config object is in scope here


const [isLoading, setIsLoading] = useState<boolean>(true);
const [loadingError, setLoadingError] = useState<undefined | Error>();
Expand Down Expand Up @@ -139,7 +141,7 @@ export const ReportInfoFlyout: FunctionComponent<Props> = ({ config, onClose, jo
{isLoading ? (
<EuiLoadingSpinner />
) : loadingError ? undefined : !!info ? (
<ReportInfoFlyoutContent info={info} />
<ReportInfoFlyoutContent info={info} isServerless={isServerless} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Let's change this to passing the ClientConfigType object
Suggested change
<ReportInfoFlyoutContent info={info} isServerless={isServerless} />
<ReportInfoFlyoutContent info={info} config={config} />

) : undefined}
</EuiFlyoutBody>
{!isLoading && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ const UNKNOWN = i18n.translate('xpack.reporting.listing.infoPanel.unknownLabel',

interface Props {
info: Job;
isServerless: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Let's have this expect the ClientConfigType object
Suggested change
isServerless: boolean;
config: ClientConfigType;

}

const createDateFormatter = (format: string, tz: string) => (date: string) => {
const m = moment.tz(date, tz);
return m.isValid() ? m.format(format) : NA;
};

export const ReportInfoFlyoutContent: FunctionComponent<Props> = ({ info }) => {
export const ReportInfoFlyoutContent: FunctionComponent<Props> = ({ info, isServerless }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const ReportInfoFlyoutContent: FunctionComponent<Props> = ({ info, isServerless }) => {
export const ReportInfoFlyoutContent: FunctionComponent<Props> = ({ info, config }) => {

const {
services: { uiSettings, docLinks },
} = useKibana();
Expand All @@ -50,6 +51,8 @@ export const ReportInfoFlyoutContent: FunctionComponent<Props> = ({ info }) => {
? moment.tz.guess()
: uiSettings.get('dateFormat:tz');

const showKibanaVersion = Boolean(info.version) && !isServerless;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Let's use the config object to determine this flag
Suggested change
const showKibanaVersion = Boolean(info.version) && !isServerless;
const showKibanaVersion = Boolean(info.version) && config.statefulSettings.enabled;


const formatDate = createDateFormatter(uiSettings.get('dateFormat'), timezone);
const formatMilliseconds = (millis: number) =>
i18n.translate('xpack.reporting.listing.infoPanel.msToSeconds', {
Expand All @@ -74,7 +77,7 @@ export const ReportInfoFlyoutContent: FunctionComponent<Props> = ({ info }) => {
}),
description: info.prettyStatus,
},
Boolean(info.version) && {
showKibanaVersion && {
title: i18n.translate('xpack.reporting.listing.infoPanel.kibanaVersion', {
defaultMessage: 'Kibana version',
}),
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Setup = jest.Mocked<ReportingSetup>;

const createSetupContract = (): Setup => {
const coreSetup = coreMock.createSetup();
const apiClient = new ReportingAPIClient(coreSetup.http, coreSetup.uiSettings, '7.15.0');
const apiClient = new ReportingAPIClient(coreSetup.http, coreSetup.uiSettings, '7.15.0', false);
return {
usesUiCapabilities: jest.fn().mockImplementation(() => true),
components: getSharedComponents(apiClient, Rx.from(coreSetup.getStartServices())),
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/reporting/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class ReportingPublicPlugin
>
{
private kibanaVersion: string;
private isServerless: boolean;
private apiClient?: ReportingAPIClient;
private readonly stop$ = new ReplaySubject<void>(1);
private readonly title = i18n.translate('xpack.reporting.management.reportingTitle', {
Expand All @@ -82,6 +83,7 @@ export class ReportingPublicPlugin
constructor(initializerContext: PluginInitializerContext) {
this.config = initializerContext.config.get<ClientConfigType>();
this.kibanaVersion = initializerContext.env.packageInfo.version;
this.isServerless = initializerContext.env.packageInfo.buildFlavor === 'serverless';
}

private getContract(apiClient: ReportingAPIClient, startServices$: StartServices$) {
Expand Down Expand Up @@ -127,7 +129,12 @@ export class ReportingPublicPlugin
);
const usesUiCapabilities = !this.config.roles.enabled;

const apiClient = new ReportingAPIClient(core.http, core.uiSettings, this.kibanaVersion);
const apiClient = new ReportingAPIClient(
core.http,
core.uiSettings,
this.kibanaVersion,
this.isServerless
);
this.apiClient = apiClient;

homeSetup.featureCatalogue.register({
Expand Down