Skip to content

Commit

Permalink
Enable CSV reporting in serverless (elastic#162358)
Browse files Browse the repository at this point in the history
## Summary

This PR sets up the reporting plugin for the serverless implementation
by adding properties to the existing reporting config.

Image reporting is enabled for dev mode but disabled for serverless.
Canvas is disabled for serverless.

## To Test

Run `yarn es snapshot --license trial` in one terminal and then `yarn
start`. Load sample data and you should be able to see the option to
have PDF and PNG reports in Dashboard's Share Menu.

![Screenshot 2023-07-25 at 9 40 30
AM](https://github.com/elastic/kibana/assets/20343860/c258a14d-6cc7-4fdf-9bb1-4dc3b15d371b)

Now run `yarn es snapshot --license trial` and `yarn serverless-es`. You
should see that Dashboard's share menu does not include PDF or PNG
Reports. However there is still the option to see run CSV reports and
see the Reporting in Management.

![Screenshot 2023-07-25 at 9 42 16
AM](https://github.com/elastic/kibana/assets/20343860/638691dc-6c2f-41ed-a8d3-d5d38c15fa91)


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Timothy Sullivan <tsullivan@elastic.co>
  • Loading branch information
3 people committed Jul 28, 2023
1 parent af15cc1 commit 5864674
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 13 deletions.
1 change: 0 additions & 1 deletion config/serverless.yml
Expand Up @@ -42,7 +42,6 @@ management.deeplinks.navLinkStatus: visible

# Other disabled plugins
#xpack.canvas.enabled: false #only disabable in dev-mode
xpack.reporting.enabled: false
xpack.cloud_integrations.data_migration.enabled: false
data.search.sessions.enabled: false
advanced_settings.enabled: false
Expand Down
25 changes: 14 additions & 11 deletions x-pack/plugins/reporting/public/plugin.ts
Expand Up @@ -46,6 +46,7 @@ import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '../common/constants';
export interface ClientConfigType {
poll: { jobsRefresh: { interval: number; intervalErrorMultiplier: number } };
roles: { enabled: boolean };
export_types: { pdf: { enabled: boolean }; png: { enabled: boolean }; csv: { enabled: boolean } };
}

function getStored(): JobId[] {
Expand Down Expand Up @@ -236,17 +237,19 @@ export class ReportingPublicPlugin
})
);

share.register(
reportingScreenshotShareProvider({
apiClient,
toasts,
uiSettings,
license,
application,
usesUiCapabilities,
theme: core.theme,
})
);
if (this.config.export_types.pdf.enabled || this.config.export_types.png.enabled) {
share.register(
reportingScreenshotShareProvider({
apiClient,
toasts,
uiSettings,
license,
application,
usesUiCapabilities,
theme: core.theme,
})
);
}
});
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x-pack/plugins/reporting/server/config/index.ts
Expand Up @@ -11,7 +11,7 @@ import { get } from 'lodash';
import { ConfigSchema, ReportingConfigType } from './schema';

export const config: PluginConfigDescriptor<ReportingConfigType> = {
exposeToBrowser: { poll: true, roles: true },
exposeToBrowser: { poll: true, roles: true, export_types: true },
schema: ConfigSchema,
deprecations: ({ unused }) => [
unused('capture.browser.chromium.maxScreenshotDimension', { level: 'warning' }), // unused since 7.8
Expand Down
50 changes: 50 additions & 0 deletions x-pack/plugins/reporting/server/config/schema.test.ts
Expand Up @@ -62,4 +62,54 @@ describe('Reporting Config Schema', () => {
);
}
);

it('permits csv with serverless', () => {
expect(() =>
ConfigSchema.validate({ export_types: { pdf: { enabled: true } } }, { dev: true })
).not.toThrow();
});

it('enables all export types by default', () => {
expect(ConfigSchema.validate({}, { serverless: false }).export_types).toMatchInlineSnapshot(`
Object {
"csv": Object {
"enabled": true,
},
"pdf": Object {
"enabled": true,
},
"png": Object {
"enabled": true,
},
}
`);
});

it('disables screenshot type exports in serverless', () => {
expect(ConfigSchema.validate({}, { serverless: true }).export_types).toMatchInlineSnapshot(`
Object {
"csv": Object {
"enabled": true,
},
"pdf": Object {
"enabled": false,
},
"png": Object {
"enabled": false,
},
}
`);
});

it('it should allow image reporting for any non-serverless config', () => {
expect(() =>
ConfigSchema.validate({ export_types: { pdf: { enabled: true } } }, { dev: true })
).not.toThrow();
expect(() =>
ConfigSchema.validate({ export_types: { png: { enabled: true } } }, { dev: true })
).not.toThrow();
expect(() =>
ConfigSchema.validate({ export_types: { csv: { enabled: true } } }, { dev: true })
).not.toThrow();
});
});
26 changes: 26 additions & 0 deletions x-pack/plugins/reporting/server/config/schema.ts
Expand Up @@ -101,6 +101,31 @@ const PollSchema = schema.object({
}),
});

const ExportTypeSchema = schema.object({
// Csv reports are enabled in all offerings
csv: schema.object({
enabled: schema.boolean({ defaultValue: true }),
}),
// Png reports are disabled in serverless
png: schema.object({
enabled: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({ defaultValue: false }),
schema.boolean({ defaultValue: true })
),
}),
// Pdf reports are disabled in serverless
pdf: schema.object({
enabled: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({ defaultValue: false }),
schema.boolean({ defaultValue: true })
),
}),
});

export const ConfigSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
kibanaServer: KibanaServerSchema,
Expand All @@ -110,6 +135,7 @@ export const ConfigSchema = schema.object({
encryptionKey: EncryptionKeySchema,
roles: RolesSchema,
poll: PollSchema,
export_types: ExportTypeSchema,
});

export type ReportingConfigType = TypeOf<typeof ConfigSchema>;

0 comments on commit 5864674

Please sign in to comment.