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

feat(metrics): be able to send new tags on stop functions #7

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

hmoragrega
Copy link
Contributor

@hmoragrega hmoragrega commented Oct 7, 2024

This PR enables sending more tags on Stop functions, enabling us to send metadata calculated during the functions

This change is backwards compatible and should not break any call

Summary by CodeRabbit

  • New Features

    • Enhanced metrics reporting with flexible tagging options for error reporting.
    • New test cases introduced to validate the updated tagging functionality.
  • Bug Fixes

    • Improved accuracy in timing metrics with the addition of new tags.
  • Tests

    • Updated existing tests to reflect changes in function signatures and tagging.
    • Introduced new tests to ensure correct handling of deferred tags and error reporting.

Copy link

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes in this pull request primarily modify the metrics.go and metrics_test.go files. In metrics.go, the function signatures for reporting metrics have been updated to include an additional tags ...Tags parameter, enhancing the flexibility of tagging during error reporting. The StopTimerFunc type has also been adjusted to accept tags. Correspondingly, metrics_test.go has been updated to reflect these changes, with modifications to test cases ensuring that the new tagging functionality is properly validated.

Changes

File Change Summary
metrics.go Updated ReportFuncCallAndTimingWithErr to accept tags ...Tags. Modified StopTimerFunc type to accept tags ...Tags. Adjusted internal logic for timing functions to handle new stopTags.
metrics_test.go Updated Test_ReportTimedFuncWithError to include additional tags in function calls. Introduced new test case for deferred tags and error reporting. Changed assertions to use assert.ElementsMatch.

Possibly related PRs

  • feat(GEN-95|HELIX-1134): add datadog and mixpanel support  #6: The changes in metrics.go within this PR introduce new functions for error reporting and event tracking using the Mixpanel library, which is directly related to the modifications made in the main PR regarding the ReportFuncCallAndTimingWithErr function and its handling of tags.

Suggested reviewers

  • proofofze

Poem

In the land of metrics, we hop and play,
New tags are here, hip-hip-hooray!
Reporting with flair, no error in sight,
With each little change, our data takes flight.
So let’s bounce along, with joy in our hearts,
For every new function, a fresh work of art! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 815d3fe and 1e09411.

📒 Files selected for processing (2)
  • metrics.go (6 hunks)
  • metrics_test.go (3 hunks)
🧰 Additional context used
🔇 Additional comments (9)
metrics_test.go (6)

46-46: Correct inclusion of additional tags in deferred function

The deferred call to ReportFuncCallAndTimingWithErr now includes an additional Tags parameter Tags{"stop": "error"}, which correctly tests the new functionality of passing additional tags when stopping functions.


58-58: Proper use of assert.ElementsMatch for tag comparison

The test assertions have been updated to use assert.ElementsMatch instead of assert.Equal when comparing tags. This is appropriate because the order of tags may not be guaranteed, and assert.ElementsMatch correctly verifies that all expected tags are present regardless of order.

Also applies to: 63-63, 67-67


60-60: Updated expected tags to include new stop tag

The expectedTags slice has been updated to include the new tag "stop=error", ensuring that the test correctly validates the presence of all expected tags.


84-98: New test case added for deferred function with new tags

A new test case t.Run("can be deferred with new tags and skip error reporting", ...) has been added to verify that additional tags can be passed when deferring ReportFuncCallAndTimingWithErr, and that error reporting is skipped when err is nil.


88-88: Ensure additional tags are correctly handled in deferred call

In the deferred call, ReportFuncCallAndTimingWithErr is called with Tags{"foo": "bar"} and an additional Tags{"something": "new"} when stopping. This correctly tests the ability to pass extra tags upon stopping.


94-97: Validate expected tags in assertions

The expectedTags slice includes the new tag "something=new", and the assertions correctly use assert.ElementsMatch to verify that all expected tags are present in the recorded calls.

metrics.go (3)

173-181: Ensure correct handling of additional stop tags in timing functions

In the anonymous function returned by reportTiming, the stopTags are now accepted as a parameter and appended to tagArray. Please confirm that this modification correctly accumulates the intended tags and does not introduce any unintended side effects.


220-220: Appending stop tags in ReportClosureFuncTiming

Appending stopTags to tagArray in ReportClosureFuncTiming changes the reported tags. Ensure that this change aligns with the intended behavior and that all tags are correctly merged.


86-93: ⚠️ Potential issue

Potential backward compatibility issue due to function signature change

The function ReportFuncCallAndTimingWithErr has been modified to return a function with a new signature: func(err *error, tags ...Tags) instead of func(err *error). This change can break existing code that uses this function, as the returned function's signature has changed.

To ensure backward compatibility, please verify if any existing callers depend on the previous function signature.

✅ Verification successful

Backward compatibility maintained for ReportFuncCallAndTimingWithErr

No compatibility issues found with existing callers.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usages of `ReportFuncCallAndTimingWithErr` to check for compatibility issues

rg --type go 'ReportFuncCallAndTimingWithErr' --threads 4

Length of output: 446

@@ -111,7 +111,7 @@ func reportFunc(fn, action string, tags ...Tags) {
client.Incr(fmt.Sprintf("func.%v", action), tagArray, 0.77)
}

type StopTimerFunc func()
type StopTimerFunc func(tags ...Tags)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Changing StopTimerFunc type may break existing implementations

The type StopTimerFunc has been updated from func() to func(tags ...Tags). This modification can affect all existing implementations and usages of this type, potentially causing compatibility issues.

@@ -127,7 +127,7 @@ func reportTiming(ctx context.Context, tags ...Tags) (context.Context, StopTimer
defer clientMux.RUnlock()

if client == nil {
return ctx, func() {}
return ctx, func(...Tags) {}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Anonymous function signature changed to accept ...Tags

The anonymous function returned now accepts variadic ...Tags as parameters. This change modifies the function signature from func() to func(...Tags), which may disrupt existing code expecting a parameterless function.

@@ -187,7 +189,7 @@ func ReportClosureFuncTiming(name string, tags ...Tags) StopTimerFunc {
clientMux.RLock()
defer clientMux.RUnlock()
if client == nil {
return func() {}
return func(...Tags) {}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Change in returned function's signature may affect callers

The returned function now accepts ...Tags as parameters, changing its signature from func() to func(...Tags). Verify that any callers of this function are updated to accommodate this change.

@hmoragrega hmoragrega merged commit 6e9c82a into master Oct 7, 2024
2 checks passed
@hmoragrega hmoragrega deleted the f/stop-fn-tags branch October 7, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants