8000 add product and edition to session analytics by ackdav · Pull Request #12198 · localstack/localstack · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add product and edition to session analytics #12198

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

Merged
merged 8 commits into from
Feb 10, 2025
Merged

Conversation

ackdav
Copy link
Member
@ackdav ackdav commented Jan 28, 2025

Motivation

This PR adds product and edition to the session's ClientMetadata. Given LocalStack's growing number of products, the distinction will help distinguish where a session is coming from.

Both product and edition can be overwritten by environment variables to cover cases where a runtime is not necessarily given or correct (e.g. when packaging an extension).

Changes

  • adds product and edition to the session's ClientMetadata
  • adds mock_runtime fixture. Analytics unit tests rely on client metadata - but get_current_runtime() throws an error when not having an initialized runtime.

@ackdav ackdav added the semver: patch Non-breaking changes which can be included in patch releases label Jan 28, 2025
Copy link
github-actions bot commented Jan 28, 2025

LocalStack Community integration with Pro

    2 files  ± 0      2 suites  ±0   1h 49m 23s ⏱️ - 1m 40s
4 083 tests +13  3 766 ✅ +11  317 💤 +2  0 ❌ ±0 
4 085 runs  +13  3 766 ✅ +11  319 💤 +2  0 ❌ ±0 

Results for commit 213ee75. ± Comparison against base commit 25b920c.

♻️ This comment has been updated with latest results.

@ackdav ackdav marked this pull request as ready for review January 29, 2025 07:09
@ackdav ackdav requested a review from thrau as a code owner January 29, 2025 07:09
@ackdav ackdav added this to the 4.1 milestone Jan 29, 2025
@vittoriopolverino
Copy link
Member
vittoriopolverino commented Jan 29, 2025

@ackdav @thrau
If we aim to align with the decisions in the Top level products document, where the edition seems to map 1:1 with the Docker image used by customers, we might want to refactor get_localstack_edition() to something like this:

@dataclasses.dataclass(frozen=True)
class LocalStackEdition:
    ENTERPRISE: Literal["localstack-enterprise"] = "localstack-enterprise"
    PRO: Literal["localstack-pro"] = "localstack-pro"
    COMMUNITY: Literal["localstack"] = "localstack"
    AZURE_ALPHA: Literal["localstack-azure-alpha"] = "localstack-azure-alpha"
    UNKNOWN: Literal["unknown"] = "unknown"

def get_localstack_edition() -> Optional[str]:
    image_name = get_docker_image_to_start()
    edition = image_name.removeprefix("localstack/")
    return edition if edition in {
        LocalStackEdition.ENTERPRISE,
        LocalStackEdition.PRO,
        LocalStackEdition.COMMUNITY,
        LocalStackEdition.AZURE_ALPHA
    } else LocalStackEdition.UNKNOWN

Then, we could use this function to set the edition attribute in the ClientMetadata class.

❓ Are there any planned changes to the naming of the Docker images?

@ackdav ackdav modified the milestones: 4.1, 4.2 Jan 29, 2025
@@ -60,6 +62,8 @@ def read_client_metadata() -> ClientMetadata:
is_ci=os.getenv("CI") is not None,
is_docker=config.is_in_docker,
is_testing=config.is_local_test_mode(),
product="aws",
Copy link
Member
@whummer whummer Jan 29, 2025

Choose a reason for hiding this comment

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

@ackdav As briefly discussed, perhaps we can add an environment variable override here, to allow specialized images (separate products like Azure, Snowflake) to define custom product strings. (this environment variable can then be defined in the respective Dockerfiles of the specific products)

Something like (simplified):

Suggested change
product="aws",
product=os.getenv("LOCALSTACK_TELEMETRY_PRODUCT") or "aws",

Same for the edition, and also use the existing get_localstack_edition() function as the default.

@ackdav ackdav marked this pull request as draft January 29, 2025 16:16
@ackdav ackdav marked this pull request as ready for review February 5, 2025 14:37
@ackdav ackdav requested review from whummer and alexrashed February 5, 2025 14:41
Copy link
Member
@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

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

I think this is a nice small and concise change! 💯 🚀
Maybe we could - here in the PR description - add some examples of what the current products and editions are? That would make it more concrete for me.

@vittoriopolverino: Concerning your question on the edition. The edition is right now defined by the "*-version" file in /usr/lib/localstack/ added when building the Docker image. For example, for community this is happening here:

RUN touch /usr/lib/localstack/.community-version

Does this clarify your question? Happy to discuss this further! :)

Comment on lines 23 to 26
runtime = MockRuntime()
set_current_runtime(runtime)
yield
set_current_runtime(None)
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (not blocking): This really just affects the analytics module, but it might make sense to play safe and really only set it if the runtime is really not set. Something like this:

Suggested change
runtime = MockRuntime()
set_current_runtime(runtime)
yield
set_current_runtime(None)
try:
# don't do anything if a runtime is set
get_current_runtime()
yield
except ValueError:
# set a mock runtime if no runtime is set
set_current_runtime(MockRuntime())
yield
set_current_runtime(None)

Comment on lines 67 to 68
product=os.getenv("LOCALSTACK_TELEMETRY_PRODUCT") or runtime.components.name or "unknown",
edition=os.getenv("LOCALSTACK_TELEMETRY_EDITION") or get_localstack_edition(),
Copy link
Member

Choose a reason for hiding this comment

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

praise: Nice and simple enhancement! 💯

@@ -60,6 +64,8 @@ def read_client_metadata() -> ClientMetadata:
is_ci=os.getenv("CI") is not None,
is_docker=config.is_in_docker,
is_testing=config.is_local_test_mode(),
product=os.getenv("LOCALSTACK_TELEMETRY_PRODUCT") or runtime.components.name or "unknown",
Copy link
Member

Choose a reason for hiding this comment

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

super nitpick (absolutely not blocking): I think it might make sense to create a new function here as well, similar to get_localstack_edition. This gives a nice little abstraction layer which allows us to easily adjust the way we determine the product later on.

Copy link
Member
@whummer whummer left a comment

Choose a reason for hiding this comment

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

LGTM, modulo Alex' comments. 👍 Kudos for driving this topic forward @ackdav @vittoriopolverino ! 🚀

@vittoriopolverino
Copy link
Member

I think this is a nice small and concise change! 💯 🚀 Maybe we could - here in the PR description - add some examples of what the current products and editions are? That would make it more concrete for me.

@vittoriopolverino: Concerning your question on the edition. The edition is right now defined by the "*-version" file in /usr/lib/localstack/ added when building the Docker image. For example, for community this is happening here:

RUN touch /usr/lib/localstack/.community-version

Does this clarify your question? Happy to discuss this further! :)

Yes, +1 on highlighting all the expected values for the different Docker images we are currently providing.

@ackdav ackdav merged commit 7c364d1 into master Feb 10, 2025
31 checks passed
@ackdav ackdav deleted the add_analytics_product branch February 10, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 parti 37E4 cipants
0