-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Expose projectsUrl
and baseUrl
on the Cloud's plugin setup and start server-side contracts
#163380
Changes from 8 commits
2dd2b45
c8b00a9
af62227
99f26ec
2ee282d
2389481
2beaec9
6ba50a7
abd6896
dbfc3df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,3 @@ | ||
# `cloud` plugin | ||
|
||
The `cloud` plugin adds Cloud-specific features to Kibana. | ||
|
||
## Client-side API | ||
|
||
The client-side plugin provides the following interface. | ||
|
||
### `isCloudEnabled` | ||
|
||
This is set to `true` for both ESS and ECE deployments. | ||
|
||
### `cloudId` | ||
|
||
This is the ID of the Cloud deployment to which the Kibana instance belongs. | ||
|
||
**Example:** `eastus2.azure.elastic-cloud.com:9243$59ef636c6917463db140321484d63cfa$a8b109c08adc43279ef48f29af1a3911` | ||
|
||
**NOTE:** The `cloudId` is a concatenation of the deployment name and a hash. Users can update the deployment name, changing the `cloudId`. However, the changed `cloudId` will not be re-injected into `kibana.yml`. If you need the current `cloudId` the best approach is to split the injected `cloudId` on the semi-colon, and replace the first element with the `persistent.cluster.metadata.display_name` value as provided by a call to `GET _cluster/settings`. | ||
|
||
### `baseUrl` | ||
|
||
This is the URL of the Cloud interface. | ||
|
||
**Example:** `https://cloud.elastic.co` (on the ESS production environment) | ||
|
||
### `deploymentUrl` | ||
|
||
This is the path to the Cloud deployment management page for the deployment to which the Kibana instance belongs. The value is already prepended with `baseUrl`. | ||
|
||
**Example:** `{baseUrl}/deployments/bfdad4ef99a24212a06d387593686d63` | ||
|
||
### `snapshotsUrl` | ||
|
||
This is the path to the Snapshots page for the deployment to which the Kibana instance belongs. The value is already prepended with `deploymentUrl`. | ||
|
||
**Example:** `{deploymentUrl}/elasticsearch/snapshots` | ||
|
||
### `profileUrl` | ||
|
||
This is the path to the Cloud User Profile page. The value is already prepended with `baseUrl`. | ||
|
||
**Example:** `{baseUrl}/user/settings/` | ||
|
||
### `organizationUrl` | ||
|
||
This is the path to the Cloud Account and Billing page. The value is already prepended with `baseUrl`. | ||
|
||
**Example:** `{baseUrl}/account/` | ||
|
||
### `cname` | ||
|
||
This value is the same as `baseUrl` on ESS but can be customized on ECE. | ||
|
||
**Example:** `cloud.elastic.co` (on ESS) | ||
|
||
### `trial_end_date` | ||
|
||
The end date for the Elastic Cloud trial. Only available on Elastic Cloud. | ||
|
||
**Example:** `2020-10-14T10:40:22Z` | ||
|
||
### `is_elastic_staff_owned` | ||
|
||
`true` if the deployment is owned by an Elastician. Only available on Elastic Cloud. | ||
The `cloud` plugin adds Cloud-specific features to Kibana. | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* 2.0. | ||
*/ | ||
|
||
import type { CloudSetup } from './plugin'; | ||
import type { CloudSetup, CloudStart } from './plugin'; | ||
|
||
function createSetupMock(): jest.Mocked<CloudSetup> { | ||
return { | ||
|
@@ -19,6 +19,8 @@ function createSetupMock(): jest.Mocked<CloudSetup> { | |
isCloudEnabled: true, | ||
isElasticStaffOwned: true, | ||
trialEndDate: new Date('2020-10-01T14:13:12Z'), | ||
projectsUrl: 'projects-url', | ||
baseUrl: 'base-url', | ||
apm: { | ||
url: undefined, | ||
secretToken: undefined, | ||
|
@@ -30,6 +32,15 @@ function createSetupMock(): jest.Mocked<CloudSetup> { | |
}; | ||
} | ||
|
||
function createStartMock(): jest.Mocked<CloudStart> { | ||
return { | ||
isCloudEnabled: true, | ||
projectsUrl: 'projects-url', | ||
baseUrl: 'base-url', | ||
}; | ||
} | ||
|
||
export const cloudMock = { | ||
createSetup: createSetupMock, | ||
createStart: createStartMock, | ||
Comment on lines
43
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expose this missing mock for consumers of the |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import { registerCloudUsageCollector } from './collectors'; | |
import { getIsCloudEnabled } from '../common/is_cloud_enabled'; | ||
import { parseDeploymentIdFromDeploymentUrl } from '../common/parse_deployment_id_from_deployment_url'; | ||
import { decodeCloudId, DecodedCloudId } from '../common/decode_cloud_id'; | ||
import { getFullCloudUrl } from '../common/utils'; | ||
import { readInstanceSizeMb } from './env'; | ||
|
||
interface PluginsSetup { | ||
jloleysens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -25,7 +26,11 @@ interface PluginsSetup { | |
*/ | ||
export interface CloudSetup { | ||
/** | ||
* The deployment's Cloud ID. Only available when running on Elastic Cloud. | ||
* This is the ID of the Cloud deployment to which the Kibana instance belongs. | ||
* | ||
* @example `eastus2.azure.elastic-cloud.com:9243$59ef636c6917463db140321484d63cfa$a8b109c08adc43279ef48f29af1a3911` | ||
* | ||
* @note The `cloudId` is a concatenation of the deployment name and a hash. Users can update the deployment name, changing the `cloudId`. However, the changed `cloudId` will not be re-injected into `kibana.yml`. If you need the current `cloudId` the best approach is to split the injected `cloudId` on the semi-colon, and replace the first element with the `persistent.cluster.metadata.display_name` value as provided by a call to `GET _cluster/settings`. | ||
*/ | ||
cloudId?: string; | ||
/** | ||
|
@@ -41,15 +46,27 @@ export interface CloudSetup { | |
*/ | ||
kibanaUrl?: string; | ||
/** | ||
* {host} from the deployment url https://<deploymentId>.<application>.<host><?:port> | ||
* This is the URL to the "projects" interface on cloud. | ||
* | ||
* @example `https://cloud.elastic.co/projects` | ||
*/ | ||
projectsUrl?: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at this naming I'm not convinced it is 100% correct as we default it to a path, not a URL in our serverless config (the typescript, not YAML) 🤔 , will it actually be a full URL in our serverless configuration? CC @Dosant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if these should go under serverless property, provided that they are serverless specific. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I was also thinking that... It's currently not scoped that way in the cloud plugins' Don't feel strongly about it, so I'll go with your opinion if you disagree with my reasoning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looked at each of the 2:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
sidenote on the readme: seems like we can capture this info in one place: the TS interface itself 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't mind, your call. The reason I didn't put it under serverless initially called out here: I wanted to have the default value and be able to test it locally, but to add it also seemed fine to follow other URLs for simplicity. also I can imagine we might need projects_url in the future in non-project deployments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the purpose of the FWIW Pierre made the project_id nullable, but still, if you want to test locally I'm afraid you'll need the https://github.com/elastic/kibana/blob/main/x-pack/plugins/cloud/server/plugin.ts#L112 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH I can see @Dosant reasoning, one could argue this is under the concern of Cloud (since it is a cloud URL) I am happy with it living outside (also already being used in project controller) Let's call it here and commit to placing any future values inside of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, my brain read |
||
/** | ||
* This is the URL of the Cloud interface. | ||
* | ||
* @example `https://cloud.elastic.co` (on the ESS production environment) | ||
*/ | ||
baseUrl?: string; | ||
/** | ||
* {host} of the deployment url https://<deploymentId>.<application>.<host><?:port> | ||
*/ | ||
cloudHost?: string; | ||
/** | ||
* {port} from the deployment url https://<deploymentId>.<application>.<host><?:port> | ||
* {port} of the deployment url https://<deploymentId>.<application>.<host><?:port> | ||
*/ | ||
cloudDefaultPort?: string; | ||
/** | ||
* `true` when running on Elastic Cloud. | ||
* This is set to `true` for both ESS and ECE deployments. | ||
*/ | ||
isCloudEnabled: boolean; | ||
/** | ||
|
@@ -93,9 +110,21 @@ export interface CloudSetup { | |
*/ | ||
export interface CloudStart { | ||
/** | ||
* `true` when running on Elastic Cloud. | ||
* This is set to `true` for both ESS and ECE deployments. | ||
*/ | ||
isCloudEnabled: boolean; | ||
/** | ||
* This is the URL to the "projects" interface on cloud. | ||
* | ||
* @example `https://cloud.elastic.co/projects` | ||
*/ | ||
projectsUrl?: string; | ||
/** | ||
* This is the URL of the Cloud interface. | ||
* | ||
* @example `https://cloud.elastic.co` (on the ESS production environment) | ||
*/ | ||
baseUrl?: string; | ||
} | ||
|
||
export class CloudPlugin implements Plugin<CloudSetup, CloudStart> { | ||
|
@@ -124,6 +153,7 @@ export class CloudPlugin implements Plugin<CloudSetup, CloudStart> { | |
} | ||
|
||
return { | ||
...this.getCloudUrls(), | ||
cloudId: this.config.id, | ||
instanceSizeMb: readInstanceSizeMb(), | ||
deploymentId: parseDeploymentIdFromDeploymentUrl(this.config.deployment_url), | ||
|
@@ -145,9 +175,19 @@ export class CloudPlugin implements Plugin<CloudSetup, CloudStart> { | |
}; | ||
} | ||
|
||
public start() { | ||
public start(): CloudStart { | ||
return { | ||
...this.getCloudUrls(), | ||
isCloudEnabled: getIsCloudEnabled(this.config.id), | ||
}; | ||
} | ||
|
||
private getCloudUrls() { | ||
const { base_url: baseUrl } = this.config; | ||
const projectsUrl = getFullCloudUrl(baseUrl, this.config.projects_url); | ||
return { | ||
baseUrl, | ||
projectsUrl, | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a chore I decided to include here: move all of these definitions onto the TS interfaces where they should be more useful and easier to keep in sync (i.e., be deleted or added when the code changes).