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

[cloud plugin] Add serverless projectName to configuration and contract #166330

Merged
Merged
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 @@ -230,6 +230,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.cloud.projects_url (any)', // It's a string (any because schema.conditional)
// can't be used to infer urls or customer id from the outside
'xpack.cloud.serverless.project_id (string)',
'xpack.cloud.serverless.project_name (string)',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elastic/kibana-security I don't think this is a problem given it's only exposed on authenticated page and given we're going to expose the info in the Kibana navigation header, but still pointing this out.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, considering that we're already exposing project_id which is more important.

Just curious, if we ever allow user to rename the project, does it mean we'll have to restart Kibana to apply the config change? Feels a bit heavy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way the project controller works, changing the name from the Cloud UI will trigger an update of the deployment, yes. But there's isn't really ways around this until Cloud exposes an API for Kibana to get the info less passively

'xpack.discoverEnhanced.actions.exploreDataInChart.enabled (boolean)',
'xpack.discoverEnhanced.actions.exploreDataInContextMenu.enabled (boolean)',
'xpack.fleet.agents.enabled (boolean)',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cloud/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function createSetupMock(): jest.Mocked<CloudSetup> {
isServerlessEnabled: false,
serverless: {
projectId: undefined,
projectName: undefined,
},
};
}
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/cloud/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ describe('Cloud Plugin', () => {
});
expect(setup.serverless.projectId).toBe('my-awesome-project');
});

it('exposes `serverless.projectName`', () => {
const { setup } = setupPlugin({
serverless: {
project_id: 'my-awesome-project',
project_name: 'My Awesome Project',
},
});
expect(setup.serverless.projectName).toBe('My Awesome Project');
});
});
});

Expand Down Expand Up @@ -222,5 +232,17 @@ describe('Cloud Plugin', () => {
const start = plugin.start(coreStart);
expect(start.serverless.projectId).toBe('my-awesome-project');
});

it('exposes `serverless.projectName`', () => {
const { plugin } = startPlugin({
serverless: {
project_id: 'my-awesome-project',
project_name: 'My Awesome Project',
},
});
const coreStart = coreMock.createStart();
const start = plugin.start(coreStart);
expect(start.serverless.projectName).toBe('My Awesome Project');
});
});
});
3 changes: 3 additions & 0 deletions x-pack/plugins/cloud/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface CloudConfigType {
is_elastic_staff_owned?: boolean;
serverless?: {
project_id: string;
project_name?: string;
};
}

Expand Down Expand Up @@ -91,6 +92,7 @@ export class CloudPlugin implements Plugin<CloudSetup> {
isServerlessEnabled: this.isServerlessEnabled,
serverless: {
projectId: this.config.serverless?.project_id,
projectName: this.config.serverless?.project_name,
},
registerCloudService: (contextProvider) => {
this.contextProviders.push(contextProvider);
Expand Down Expand Up @@ -145,6 +147,7 @@ export class CloudPlugin implements Plugin<CloudSetup> {
isServerlessEnabled: this.isServerlessEnabled,
serverless: {
projectId: this.config.serverless?.project_id,
projectName: this.config.serverless?.project_name,
},
performanceUrl,
usersAndRolesUrl,
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/cloud/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export interface CloudStart {
* Will always be present if `isServerlessEnabled` is `true`
*/
projectId?: string;
/**
* The serverless project name.
* Will always be present if `isServerlessEnabled` is `true`
*/
projectName?: string;
Comment on lines +75 to +79
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, will only be present once the PR to inject the info from the controller is merged, but I don't think we need to have this in the comments.

};
}

Expand Down Expand Up @@ -172,5 +177,10 @@ export interface CloudSetup {
* Will always be present if `isServerlessEnabled` is `true`
*/
projectId?: string;
/**
* The serverless project name.
* Will always be present if `isServerlessEnabled` is `true`
*/
projectName?: string;
};
}

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

23 changes: 23 additions & 0 deletions x-pack/plugins/cloud/server/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { config } from './config';

describe('Cloud plugin config', () => {
it('evicts unknown properties under the `serverless` structure', () => {
const output = config.schema.validate({
serverless: {
project_id: 'project_id',
unknown_prop: 'some unknown prop',
},
});

expect(output.serverless).toEqual({
project_id: 'project_id',
});
});
});
12 changes: 9 additions & 3 deletions x-pack/plugins/cloud/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ const configSchema = schema.object({
trial_end_date: schema.maybe(schema.string()),
is_elastic_staff_owned: schema.maybe(schema.boolean()),
serverless: schema.maybe(
schema.object({
project_id: schema.string(),
})
schema.object(
{
project_id: schema.string(),
project_name: schema.maybe(schema.string()),
},
// avoid future chicken-and-egg situation with the component populating the config
{ unknowns: 'ignore' }
)
Comment on lines +36 to +43
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For future additions, this will allow to inject the data from the controller before having the version of Kibana knowing of the new setting is promoted to production

),
});

Expand All @@ -57,6 +62,7 @@ export const config: PluginConfigDescriptor<CloudConfigType> = {
is_elastic_staff_owned: true,
serverless: {
project_id: true,
project_name: true,
},
},
schema: configSchema,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cloud/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function createSetupMock(): jest.Mocked<CloudSetup> {
isServerlessEnabled: false,
serverless: {
projectId: undefined,
projectName: undefined,
},
};
}
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/cloud/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ describe('Cloud Plugin', () => {
});
expect(setup.serverless.projectId).toBe('my-awesome-project');
});

it('exposes `serverless.projectName`', () => {
const { setup } = setupPlugin({
serverless: {
project_id: 'my-awesome-project',
project_name: 'My Awesome Project',
},
});
expect(setup.serverless.projectName).toBe('My Awesome Project');
});
});
});

Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/cloud/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export interface CloudSetup {
* Will always be present if `isServerlessEnabled` is `true`
*/
projectId?: string;
/**
* The serverless project name.
* Will always be present if `isServerlessEnabled` is `true`
*/
projectName?: string;
};
}

Expand Down Expand Up @@ -175,6 +180,7 @@ export class CloudPlugin implements Plugin<CloudSetup, CloudStart> {
isServerlessEnabled,
serverless: {
projectId: this.config.serverless?.project_id,
projectName: this.config.serverless?.project_name,
},
};
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/.storybook/context/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const getCloud = ({ isCloudEnabled }: { isCloudEnabled: boolean }) => {
isServerlessEnabled: false,
serverless: {
projectId: undefined,
projectName: undefined,
},
};

Expand Down