Skip to content

Conversation

timl3136
Copy link
Member

What changed?

  • Define metrics using Prometheus
  • also add cursorrules for running uv command

Why?
It enables metrics collection for monitoring Cadence workflows and activities

How did you test it?
unit tests

Potential risks

Release notes

Documentation Changes



# Default Cadence metrics names
class CadenceMetrics:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think these should be in a class, maybe an enum if you want to namespace them.

Do these match the Java/Go client or are these just examples for the sake of testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I replaced them with enums.



# Global default handler
_default_handler: Optional[MetricsHandler] = None
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should have a global for this, I'd rather we pass it into the Client which propagates to the Workers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks



@dataclass
class PrometheusConfig:
Copy link
Member

Choose a reason for hiding this comment

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

I'm not very familiar with Prometheus. Is the expectation that the user needs to configure all of this? How does the setup compare to the Java/Go clients and the server? They also all support Prometheus, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

The setup should be done at service start up, which is the same process if we want to use prometheus in java client

except Exception as e:
logger.error(f"Failed to send histogram {key}: {e}")

def start_http_server(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Does the user need to call this and manage the lifecycle of this object?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I change the behavior so that it will initialize when client start



# Default Cadence metrics names
class CadenceMetrics(Enum):
Copy link
Member

Choose a reason for hiding this comment

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

Move out of prometheus.py

WORKFLOW_DURATION_SECONDS = "workflow_duration_seconds"

# Activity metrics
ACTIVITY_STARTED_TOTAL = "activity_started_total"
Copy link
Member

Choose a reason for hiding this comment

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

Are these metrics actual ones that exist? Do they match the Go/Java client?

@@ -0,0 +1,12 @@
"""Visibility and metrics collection components for Cadence client."""
Copy link
Member

Choose a reason for hiding this comment

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

MetricsEmitter and the prometheus stuff should be in a public package. Users need to specify it in the ClientOptions so it should be visibile. Maybe cadence/metrics

Additionally we should go with metrics as the package name. I don't think visibility accurately describes it.

HISTOGRAM = "histogram"


class MetricsEmitter(Protocol):
Copy link
Member

Choose a reason for hiding this comment

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

Is this also the interface that users should use within Workflows or will we add something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, user will be using this in their workflow/activity

"""Configuration for Prometheus metrics."""

# Metric name prefix
metric_prefix: str = "cadence_"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we actually want to expose this as an option unless our other clients do. It makes standard dashboards impossible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will make this into a hardcoded constant to match other clients

Signed-off-by: Tim Li <[email protected]>
@timl3136 timl3136 merged commit ffda2b1 into cadence-workflow:main Sep 30, 2025
5 checks passed
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