Skip to content

Conversation

@DZakh
Copy link
Member

@DZakh DZakh commented Jun 10, 2025

Related to https://github.com/enviodev/ui/pull/584

Summary by CodeRabbit

  • New Features
    • Introduced tracking of effect call counts, both locally and via Prometheus metrics, allowing users to monitor how many times each effect has been invoked.
  • Improvements
    • Enhanced metric naming consistency for Prometheus, ensuring clearer and more accurate monitoring labels.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

Walkthrough

The changes introduce tracking for the number of times an effect is called, both locally within the effect structure and via Prometheus metrics. New fields and modules are added to support this, including a mutable callsCount property on effects and a Prometheus gauge metric for effect call counts. Related naming and schema updates are also made.

Changes

File(s) Change Summary
codegenerator/cli/npm/envio/src/Envio.res Modified experimental_createEffect to initialize Prometheus metric and add callsCount field.
codegenerator/cli/npm/envio/src/Internal.res Added mutable callsCount integer field to effect record type.
codegenerator/cli/npm/envio/src/Prometheus.res Renamed metric variable in ReorgCount; added EffectCallsCount module and label schema.
codegenerator/cli/templates/static/codegen/src/LoadLayer.res Incremented callsCount and updated Prometheus metric in loadEffect's load function.
codegenerator/cli/npm/envio/package.json Added prom-client version 15.0.0 to dependencies.
codegenerator/cli/templates/dynamic/codegen/package.json.hbs Removed prom-client version 15.0.0 from dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant LoadLayer
    participant Effect
    participant Prometheus

    Caller->>LoadLayer: Call loadEffect(args)
    LoadLayer->>Effect: Increment callsCount by args.length
    LoadLayer->>Prometheus: EffectCallsCount.set(callsCount, effectName)
    LoadLayer->>Effect: Invoke effect handler
    LoadLayer-->>Caller: Return result
Loading

Poem

In the garden of effects, a counter now grows,
Counting each hop as the function bunny goes.
Prometheus watches, metrics in sight,
Every call tallied, both day and night.
With each effect summoned, the numbers ascend—
Hopping and counting, on metrics we depend!
🐇📈


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 149f22f and 9756781.

📒 Files selected for processing (2)
  • codegenerator/cli/npm/envio/package.json (1 hunks)
  • codegenerator/cli/templates/dynamic/codegen/package.json.hbs (0 hunks)
💤 Files with no reviewable changes (1)
  • codegenerator/cli/templates/dynamic/codegen/package.json.hbs
✅ Files skipped from review due to trivial changes (1)
  • codegenerator/cli/npm/envio/package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@DZakh DZakh requested a review from JonoPrest June 10, 2025 09:37
Copy link
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 275b871 and 149f22f.

📒 Files selected for processing (4)
  • codegenerator/cli/npm/envio/src/Envio.res (1 hunks)
  • codegenerator/cli/npm/envio/src/Internal.res (1 hunks)
  • codegenerator/cli/npm/envio/src/Prometheus.res (3 hunks)
  • codegenerator/cli/templates/static/codegen/src/LoadLayer.res (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build_and_test
🔇 Additional comments (7)
codegenerator/cli/npm/envio/src/Internal.res (1)

200-200: LGTM! Clean addition of call tracking field.

The mutable callsCount field is appropriately added to the effect type for tracking call metrics.

codegenerator/cli/templates/static/codegen/src/LoadLayer.res (1)

99-100: Logic is correct but consider thread safety implications.

The increment logic properly tracks the number of effect handler calls by adding the batch size. However, since callsCount is mutable, consider potential race conditions if effects are called concurrently.

Consider whether synchronization is needed for the mutable callsCount field in concurrent scenarios.

codegenerator/cli/npm/envio/src/Envio.res (2)

42-42: LGTM! Proper metric initialization.

Correctly initializes the Prometheus metric to zero when creating an effect.


50-50: LGTM! Consistent field initialization.

Properly initializes the callsCount field to zero, maintaining consistency with the Prometheus metric.

codegenerator/cli/npm/envio/src/Prometheus.res (3)

449-449: Good refactoring for naming consistency.

Renaming counter to gauge improves code clarity and consistency with the actual metric type being used.


459-459: Consistent variable usage after renaming.

Correctly uses the renamed gauge variable in the increment function.


578-580: Well-structured label schema definition.

The effect labels schema correctly defines the expected structure for Prometheus labels.

Comment on lines +582 to +592
module EffectCallsCount = {
let gauge = SafeGauge.makeOrThrow(
~name="envio_effect_calls_count",
~help="The number of calls to the effect. Including both handler execution and cache hits.",
~labelSchema=effectLabelsSchema,
)

let set = (~callsCount, ~effectName) => {
gauge->SafeGauge.handleInt(~labels=effectName, ~value=callsCount)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the labels parameter type mismatch.

The set function has a type mismatch - it passes effectName directly as labels, but the schema expects an object with an "effect" field.

Apply this fix:

  let set = (~callsCount, ~effectName) => {
-    gauge->SafeGauge.handleInt(~labels=effectName, ~value=callsCount)
+    gauge->SafeGauge.handleInt(~labels={effect: effectName}, ~value=callsCount)
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
module EffectCallsCount = {
let gauge = SafeGauge.makeOrThrow(
~name="envio_effect_calls_count",
~help="The number of calls to the effect. Including both handler execution and cache hits.",
~labelSchema=effectLabelsSchema,
)
let set = (~callsCount, ~effectName) => {
gauge->SafeGauge.handleInt(~labels=effectName, ~value=callsCount)
}
}
module EffectCallsCount = {
let gauge = SafeGauge.makeOrThrow(
~name="envio_effect_calls_count",
~help="The number of calls to the effect. Including both handler execution and cache hits.",
~labelSchema=effectLabelsSchema,
)
let set = (~callsCount, ~effectName) => {
gauge->SafeGauge.handleInt(~labels={effect: effectName}, ~value=callsCount)
}
}
🤖 Prompt for AI Agents
In codegenerator/cli/npm/envio/src/Prometheus.res around lines 582 to 592, the
set function incorrectly passes effectName directly as labels to
SafeGauge.handleInt, causing a type mismatch since the label schema expects an
object with an "effect" field. Fix this by wrapping effectName in an object with
the key "effect" when passing it as the labels argument, ensuring it matches the
expected label schema.

options: effectOptions<'input, 'output>,
handler: effectArgs<'input> => promise<'output>,
) => {
Prometheus.EffectCallsCount.set(~callsCount=0, ~effectName=options.name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be fine but is 32 bit int big enough?

@DZakh DZakh merged commit 637496f into main Jun 10, 2025
2 of 3 checks passed
@DZakh DZakh deleted the dz/effect-calls-count-prom branch June 10, 2025 12:29
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.

3 participants