Skip to content

Events: migrate to new Counter type for Event Rule invocation analytics #12388

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 3 commits into from
Mar 19, 2025

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Mar 13, 2025

Motivation

This PR replaces the analytics Counter used for tracking usage of Event rule invocations. We merge both Counter for success and failure into one, and use the new labels instead.

Changes

  • merge the 2 counters into one with more labels

Testing

To test the changes:

  • run a LocalStack in host mode with this branch checked out
  • run the tests.aws.services.events.test_events_targets.TestEventsTargetSqs.test_put_events_with_target_sqs integration test with TEST_SKIP_LOCALSTACK_START=1 set, to avoid trying to start LocalStack with the test
  • shutdown LocalStack

I've tried without sending the events but only printing the collected metrics and this is what I got:

{
  "metrics": [
    {
      "namespace": "events",
      "name": "rule_invocations",
      "value": 1,
      "type": "counter",
      "label_1_value": "success",
      "label_2_value": "sqs",
      "label_1": "status",
      "label_2": "service"
    }
  ]
}

@bentsku bentsku added aws:events Amazon EventBridge semver: patch Non-breaking changes which can be included in patch releases labels Mar 13, 2025
@bentsku bentsku added this to the 4.3 milestone Mar 13, 2025
@bentsku bentsku self-assigned this Mar 13, 2025
@bentsku bentsku marked this pull request as ready for review March 13, 2025 16:15
Copy link

github-actions bot commented Mar 13, 2025

LocalStack Community integration with Pro

    2 files  ±    0      2 suites  ±0   1h 10m 3s ⏱️ - 45m 24s
2 521 tests  - 1 772  2 416 ✅  - 1 556  105 💤  - 216  0 ❌ ±0 
2 523 runs   - 1 772  2 416 ✅  - 1 556  107 💤  - 216  0 ❌ ±0 

Results for commit 622ad14. ± Comparison against base commit cf90cd4.

This pull request removes 1772 tests.
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_lambda_dynamodb
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_opensearch_crud
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_search_books
tests.aws.scenario.bookstore.test_bookstore.TestBookstoreApplication ‑ test_setup
tests.aws.scenario.kinesis_firehose.test_kinesis_firehose.TestKinesisFirehoseScenario ‑ test_kinesis_firehose_s3
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_destination_sns
tests.aws.scenario.lambda_destination.test_lambda_destination_scenario.TestLambdaDestinationScenario ‑ test_infra
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_prefill_dynamodb_table
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input0-SUCCEEDED]
tests.aws.scenario.loan_broker.test_loan_broker.TestLoanBrokerScenario ‑ test_stepfunctions_input_recipient_list[step_function_input1-SUCCEEDED]
…

♻️ This comment has been updated with latest results.

Copy link
Member

@maxhoheiser maxhoheiser left a comment

Choose a reason for hiding this comment

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

LGTMT - thank you for implementing this :)

rule_invocation.labels(
status=InvocationStatus.error,
service=target_sender.service,
)
Copy link
Member

Choose a reason for hiding this comment

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

should we maybe also capture the error so we know why the invocation failed - we have to capture something that does not reveals any private information

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, maybe just the exception type? I'm not sure how many different types we can have, and also in this sense we'd probably need 2 different counters, as the labels would be different for both.

I don't have a lot of context into those and what we actually need for EventBridge, so if you want to add on this PR, you can 😄

Copy link
Member

@vittoriopolverino vittoriopolverino left a comment

Choose a reason for hiding this comment

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

LGTM 🥳

# number of EventBridge rule invocations per target (e.g., aws:lambda)
# - status label can be `success` or `error`, see InvocationStatus
# - service label is the target service name
rule_invocation = Counter(namespace="events", name="rule_invocations", labels=["status", "service"])
Copy link
Member

Choose a reason for hiding this comment

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

question: would it be interesting for you to also include the rule type? (standard, scheduled, etc.) or is that a detail that's not really useful at the moment?

Copy link
Member

Choose a reason for hiding this comment

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

question: is there a risk that the namespace "events" is too generic and could collide with other services? Would it make sense to use something like "eventbridge" instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point for events, it is the true name of the service so if we were to do a general dashboard based on the list of the official service names, that could be easier, but I can also see the issue with collision. 🤔

For the rule type label, I'd defer to @maxhoheiser: what do you think?

@vittoriopolverino
Copy link
Member

Could you please provide some guidance on how to trigger these event rule invocations locally? This would allow me to test the changes end-to-end, send events to Tinybird, and give you a chance to run queries on the test data before merging the PR. That way, we’ll have time to adjust the counter and refine the labels if needed 💪🏼

You can run the queries in the playground I shared with you: Playground

Copy link
Contributor Author

@bentsku bentsku left a comment

Choose a reason for hiding this comment

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

Good point Vittorio about the testing instructions. I think running an integration test with against a manually launched LocalStack should do it. I'll update the PR description 😄

rule_invocation.labels(
status=InvocationStatus.error,
service=target_sender.service,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, maybe just the exception type? I'm not sure how many different types we can have, and also in this sense we'd probably need 2 different counters, as the labels would be different for both.

I don't have a lot of context into those and what we actually need for EventBridge, so if you want to add on this PR, you can 😄

# number of EventBridge rule invocations per target (e.g., aws:lambda)
# - status label can be `success` or `error`, see InvocationStatus
# - service label is the target service name
rule_invocation = Counter(namespace="events", name="rule_invocations", labels=["status", "service"])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point for events, it is the true name of the service so if we were to do a general dashboard based on the list of the official service names, that could be easier, but I can also see the issue with collision. 🤔

For the rule type label, I'd defer to @maxhoheiser: what do you think?

@bentsku bentsku force-pushed the update-event-ruler-counter branch from 66a4532 to 7ed38c2 Compare March 14, 2025 18:47
@bentsku
Copy link
Contributor Author

bentsku commented Mar 19, 2025

@vittoriopolverino @maxhoheiser the PR has been approved, but there were some comments with some open questions. To avoid changing the "schema" of the sent events, do you think we should follow up on those questions now, or do you deem them closed? Thanks!

@vittoriopolverino
Copy link
Member

vittoriopolverino commented Mar 19, 2025

Thanks for following up on this, @bentsku , I’d prefer to clear up any doubts now before merging 🙏🏼

Sorry for bringing this up so late 😭 but..... I still have some doubts about the naming. Using "events" as a namespace doesn’t seem very intuitive to me, as it’s actually a subset of EventBridge. If we were to monitor other EventBridge functionalities in the future, "events" wouldn’t really fit under the same umbrella as the other metrics where namespace="eventbridge" 🤔

@bentsku
Copy link
Contributor Author

bentsku commented Mar 19, 2025

@vittoriopolverino this was already addressed with 7ed38c2, the namespace is now eventbridge 😄

but the true name of the service in AWS (like in the AWS CLI) really is events and not EventBridge, for example aws events put-events .... So if we were to build automatic dashboards for all services, events will need a special rule.

It is true that in AWS, the EventBridge naming is an umbrella term for many services: Pipes, Scheduler and such.

Maybe if the namespace is EventBridge, then the name field needs to have the events part to it?

@vittoriopolverino
Copy link
Member

vittoriopolverino commented Mar 19, 2025

After a quick chat with @bentsku 🙏🏼 , we decided to follow the existing convention already used in the code and repository structure, choosing not to group pipes, events, scheduler, etc., under the EventBridge namespace.

@bentsku bentsku force-pushed the update-event-ruler-counter branch from 7ed38c2 to 622ad14 Compare March 19, 2025 19:55
@bentsku bentsku merged commit 7f97b18 into master Mar 19, 2025
31 checks passed
@bentsku bentsku deleted the update-event-ruler-counter branch March 19, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:events Amazon EventBridge 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.

3 participants