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

[LaunchDarkly] Add Deployment Metadata #143002

Merged
merged 6 commits into from
Oct 17, 2022

Conversation

afharo
Copy link
Member

@afharo afharo commented Oct 10, 2022

Summary

This PR adds deployment metadata so we can apply better segmentation and user targeting in our Cloud Experiments A/B tests:

  • is_elastic_staff_owned: true if the owner of the deployment on Elastic Cloud is an Elastician.
  • trial_end_date: The date on which the Elastic Cloud trial ends/ended.
  • in_trial: Periodically calculated from trial_end_date: it indicates if the date has expired.
  • has_data: true if the deployment holds user-created Data Views. While it's false, it is periodically calculated until it turns true.

In order to make this implementation (and future revisions) easier, this PR introduces 2 services in the CloudExperiments plugin:

  • MetadataService: it holds the user metadata and the tools for running periodical calculations
  • LaunchDarkly client (browser and server): This PR moves the LaunchDarkly specifics to internal wrappers to make CloudExperiments plugin a bit simpler. Refer to this comment, where we agreed we'll separate the plugin and client implementation.

Finally, this PR also makes use of the new metadata to enrich the telemetry we send.

Resolves #140055

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@afharo afharo added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting labels Oct 10, 2022
@afharo afharo requested review from a team as code owners October 10, 2022 16:50
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@afharo afharo self-assigned this Oct 10, 2022
@afharo afharo requested a review from arisonl October 10, 2022 16:50
Copy link
Contributor

@watson watson left a comment

Choose a reason for hiding this comment

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

Kibana Platform Security changes LGTM 👍

@afharo
Copy link
Member Author

afharo commented Oct 13, 2022

@elasticmachine merge upstream

},
fetch: () => {
return {
isCloudEnabled,
isElasticStaffOwned,
trialEndDate,
...(trialEndDate ? { inTrial: Date.now() <= new Date(trialEndDate).getTime() } : {}),
Copy link
Contributor

@gsoldevila gsoldevila Oct 14, 2022

Choose a reason for hiding this comment

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

NIT We should extract the new Date(...) to the outer scope, so that we don't create a new Object at each fetch().

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed :)

return usageCollection.makeUsageCollector<CloudUsage>({
type: 'cloud',
isReady: () => true,
schema: {
isCloudEnabled: { type: 'boolean' },
trialEndDate: { type: 'date' },
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused here, it seems that CloudUsage defines the trialEndDate as a string, whereas this schema defines it as a Date. But then looking at the fetch it would seem that we return a string. 🤔

Copy link
Member Author

@afharo afharo Oct 14, 2022

Choose a reason for hiding this comment

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

haha! yeah... type: 'date' is a string that's supposed to have the format of a date. It's more a declarative intention for the schema reader in the Telemetry receiving side.

@afharo afharo requested a review from gsoldevila October 14, 2022 16:42
@afharo
Copy link
Member Author

afharo commented Oct 17, 2022

@elasticmachine merge upstream

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM

type: 'boolean',
_meta: {
description: '`true` if the owner of the deployment is an Elastician',
optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why optional? is it only for BWC reasons on the schema?

Copy link
Member Author

Choose a reason for hiding this comment

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

This information comes from the cloud configuration. It may not be provided by the cloud deployment configuration (mind the schema.maybe).

if (!this.launchDarklyClient) return defaultValue; // Skip any action if no LD User is defined
await this.launchDarklyClient.waitForInitialization();
return this.launchDarklyClient.variation(configKey, defaultValue);
if (!this.launchDarklyClient) return defaultValue; // Skip any action if no LD Client is defined
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT/optional: code style consistency

if (!this.launchDarklyClient) { 
  return defaultValue;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in commit elastic/kibana@48eaafc (#143002)

@afharo afharo enabled auto-merge (squash) October 17, 2022 14:22
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cloudExperiments 8 12 +4

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
cloud 26 11 -15

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cloud 3.0KB 3.4KB +459.0B
cloudExperiments 7.8KB 10.2KB +2.4KB
total +2.9KB
Unknown metric groups

API count

id before after diff
cloud 34 39 +5

ESLint disabled line counts

id before after diff
cloudExperiments 3 4 +1

Total ESLint disabled count

id before after diff
cloudExperiments 3 4 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @afharo

@afharo afharo merged commit 46ccdc9 into elastic:main Oct 17, 2022
@afharo afharo deleted the launchdarkly/deployment-metadata branch October 17, 2022 15:41
clintandrewhall added a commit that referenced this pull request Feb 22, 2023
…t. (#151548)

## Summary

In-app chat should only be enabled in Cloud if a trial is still active.
#143002 added metadata including
`trial_end_date`. This PR:

- adds a config key to `cloud_integrations` for a `trialBuffer`, in
days, which defaults to ~~`30`~~ `60`.
- adds logic to not display chat if the trial end date + buffer exceeds
the current date.
- adds logic to not add a server route if the trial end date + buffer
exceeds the current date.

## Testing Locally

Add the following config to `kibana.dev.yml`:

```
xpack.cloud.id: "some-id"
xpack.cloud.trial_end_date: "2023-02-21T00:00:00.000Z"

xpack.cloud_integrations.chat.enabled: true
xpack.cloud_integrations.chat.chatURL: "https://elasticcloud-production-chat-us-east-1.s3.amazonaws.com/drift-iframe.html"
xpack.cloud_integrations.chat.chatIdentitySecret: "some-secret"
```

And start Kibana. You can optionally change the default of `30` days by
adding `xpack.cloud_integrations.chat.trialBuffer`.

## Storybook

Run `yarn storybook cloud_chat`.

## Testing in Cloud

Set the same config keys as above on a Cloud deployment.
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 22, 2023
…t. (elastic#151548)

## Summary

In-app chat should only be enabled in Cloud if a trial is still active.
elastic#143002 added metadata including
`trial_end_date`. This PR:

- adds a config key to `cloud_integrations` for a `trialBuffer`, in
days, which defaults to ~~`30`~~ `60`.
- adds logic to not display chat if the trial end date + buffer exceeds
the current date.
- adds logic to not add a server route if the trial end date + buffer
exceeds the current date.

## Testing Locally

Add the following config to `kibana.dev.yml`:

```
xpack.cloud.id: "some-id"
xpack.cloud.trial_end_date: "2023-02-21T00:00:00.000Z"

xpack.cloud_integrations.chat.enabled: true
xpack.cloud_integrations.chat.chatURL: "https://elasticcloud-production-chat-us-east-1.s3.amazonaws.com/drift-iframe.html"
xpack.cloud_integrations.chat.chatIdentitySecret: "some-secret"
```

And start Kibana. You can optionally change the default of `30` days by
adding `xpack.cloud_integrations.chat.trialBuffer`.

## Storybook

Run `yarn storybook cloud_chat`.

## Testing in Cloud

Set the same config keys as above on a Cloud deployment.

(cherry picked from commit 00ab82e)
kibanamachine added a commit that referenced this pull request Feb 22, 2023
…ng chat. (#151548) (#151946)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[drift] Determine if trial is active (plus buffer) before showing
chat. (#151548)](#151548)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Clint Andrew
Hall","email":"clint.hall@elastic.co"},"sourceCommit":{"committedDate":"2023-02-22T21:34:44Z","message":"[drift]
Determine if trial is active (plus buffer) before showing chat.
(#151548)\n\n## Summary\r\n\r\nIn-app chat should only be enabled in
Cloud if a trial is still
active.\r\nhttps://github.com//pull/143002 added metadata
including\r\n`trial_end_date`. This PR:\r\n\r\n- adds a config key to
`cloud_integrations` for a `trialBuffer`, in\r\ndays, which defaults to
~~`30`~~ `60`.\r\n- adds logic to not display chat if the trial end date
+ buffer exceeds\r\nthe current date.\r\n- adds logic to not add a
server route if the trial end date + buffer\r\nexceeds the current
date.\r\n\r\n## Testing Locally\r\n\r\nAdd the following config to
`kibana.dev.yml`:\r\n\r\n```\r\nxpack.cloud.id:
\"some-id\"\r\nxpack.cloud.trial_end_date:
\"2023-02-21T00:00:00.000Z\"\r\n\r\nxpack.cloud_integrations.chat.enabled:
true\r\nxpack.cloud_integrations.chat.chatURL:
\"https://elasticcloud-production-chat-us-east-1.s3.amazonaws.com/drift-iframe.html\"\r\nxpack.cloud_integrations.chat.chatIdentitySecret:
\"some-secret\"\r\n```\r\n\r\nAnd start Kibana. You can optionally
change the default of `30` days by\r\nadding
`xpack.cloud_integrations.chat.trialBuffer`.\r\n\r\n##
Storybook\r\n\r\nRun `yarn storybook cloud_chat`.\r\n\r\n## Testing in
Cloud\r\n\r\nSet the same config keys as above on a Cloud
deployment.","sha":"00ab82ecd7e6c0e33977d7d37b26c6d88e367fd6","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["review","loe:hours","release_note:skip","impact:high","ci:cloud-deploy","v8.7.0","v8.8.0","Feature:Chat"],"number":151548,"url":"https://github.com/elastic/kibana/pull/151548","mergeCommit":{"message":"[drift]
Determine if trial is active (plus buffer) before showing chat.
(#151548)\n\n## Summary\r\n\r\nIn-app chat should only be enabled in
Cloud if a trial is still
active.\r\nhttps://github.com//pull/143002 added metadata
including\r\n`trial_end_date`. This PR:\r\n\r\n- adds a config key to
`cloud_integrations` for a `trialBuffer`, in\r\ndays, which defaults to
~~`30`~~ `60`.\r\n- adds logic to not display chat if the trial end date
+ buffer exceeds\r\nthe current date.\r\n- adds logic to not add a
server route if the trial end date + buffer\r\nexceeds the current
date.\r\n\r\n## Testing Locally\r\n\r\nAdd the following config to
`kibana.dev.yml`:\r\n\r\n```\r\nxpack.cloud.id:
\"some-id\"\r\nxpack.cloud.trial_end_date:
\"2023-02-21T00:00:00.000Z\"\r\n\r\nxpack.cloud_integrations.chat.enabled:
true\r\nxpack.cloud_integrations.chat.chatURL:
\"https://elasticcloud-production-chat-us-east-1.s3.amazonaws.com/drift-iframe.html\"\r\nxpack.cloud_integrations.chat.chatIdentitySecret:
\"some-secret\"\r\n```\r\n\r\nAnd start Kibana. You can optionally
change the default of `30` days by\r\nadding
`xpack.cloud_integrations.chat.trialBuffer`.\r\n\r\n##
Storybook\r\n\r\nRun `yarn storybook cloud_chat`.\r\n\r\n## Testing in
Cloud\r\n\r\nSet the same config keys as above on a Cloud
deployment.","sha":"00ab82ecd7e6c0e33977d7d37b26c6d88e367fd6"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/151548","number":151548,"mergeCommit":{"message":"[drift]
Determine if trial is active (plus buffer) before showing chat.
(#151548)\n\n## Summary\r\n\r\nIn-app chat should only be enabled in
Cloud if a trial is still
active.\r\nhttps://github.com//pull/143002 added metadata
including\r\n`trial_end_date`. This PR:\r\n\r\n- adds a config key to
`cloud_integrations` for a `trialBuffer`, in\r\ndays, which defaults to
~~`30`~~ `60`.\r\n- adds logic to not display chat if the trial end date
+ buffer exceeds\r\nthe current date.\r\n- adds logic to not add a
server route if the trial end date + buffer\r\nexceeds the current
date.\r\n\r\n## Testing Locally\r\n\r\nAdd the following config to
`kibana.dev.yml`:\r\n\r\n```\r\nxpack.cloud.id:
\"some-id\"\r\nxpack.cloud.trial_end_date:
\"2023-02-21T00:00:00.000Z\"\r\n\r\nxpack.cloud_integrations.chat.enabled:
true\r\nxpack.cloud_integrations.chat.chatURL:
\"https://elasticcloud-production-chat-us-east-1.s3.amazonaws.com/drift-iframe.html\"\r\nxpack.cloud_integrations.chat.chatIdentitySecret:
\"some-secret\"\r\n```\r\n\r\nAnd start Kibana. You can optionally
change the default of `30` days by\r\nadding
`xpack.cloud_integrations.chat.trialBuffer`.\r\n\r\n##
Storybook\r\n\r\nRun `yarn storybook cloud_chat`.\r\n\r\n## Testing in
Cloud\r\n\r\nSet the same config keys as above on a Cloud
deployment.","sha":"00ab82ecd7e6c0e33977d7d37b26c6d88e367fd6"}}]}]
BACKPORT-->

Co-authored-by: Clint Andrew Hall <clint.hall@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LaunchDarkly - Retrieve user metadata
7 participants