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

Discuss: namespace rules prototype #532

Closed
wants to merge 4 commits into from
Closed

Conversation

ychebotarev
Copy link
Contributor

@ychebotarev ychebotarev commented Jan 27, 2025

What changed?
This is a proposal for "namespace level rules". First implementation will be "activity pause".
Each rule is defined by:

  • predicate - SQL like (or "visibility-like") filtering conditions. Format is specific for provided type.
  • type. Type defines both triggering condition and available columns. Right now the only available one is "activity".
  • action. Define the action. Currently mostly activity related. Will be expanded to "workflow pause", and then for other rules.

Why?
Part of the operational efforts. In case of ongoing issues users don't only want to affect (pause for example) running workflows/activities, but also prevent incoming workflows/activities from running into the same issues.
But based on the feedback the scope can be wider, and this can be solved in more generable way. Thus this proposal.

Comment on lines +119 to +120
// NamespaceRule describes a rule that can be to any workflow in this namespace.
message NamespaceRule {
Copy link
Member

@cretz cretz Jan 28, 2025

Choose a reason for hiding this comment

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

That sounds more like NamespaceWorkflowRule. Or is it intended to possibly house rules about more than just workflows (and their activities)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for now I think it will be restricted to workflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

more like:

  • I can't imagine this to be on a higher level then workflows
  • even if it is I probably want them to be separated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will rename it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or not. This can be used to pause TaskQueue for example. Technically it is not a part of workflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Overall - yes, NamespaceRule fills like scope is too big. But NamespaceWorkflowRule feels like scope is too narrow.

Copy link
Member

Choose a reason for hiding this comment

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

I like NamespaceRule the most.

Copy link
Member

Choose a reason for hiding this comment

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

We should update the doc that says it's only intended for workflows (unsure if we can expect such a thing when the expected scope-expanse occurs)

@ychebotarev ychebotarev requested a review from cretz January 28, 2025 20:45
Comment on lines +53 to +56
// I will remove it once we agree on the overall design
// RULE_ACTION_TYPE_EMIT_VISIBILITY = 3;
// RULE_ACTION_TYPE_PAUSE_WORKFLOW = 4;
// RULE_ACTION_TYPE_SIGNAL = 5;
Copy link
Member

Choose a reason for hiding this comment

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

I would move them inside enum (still commented out) with comment saying something like here are other possible actions which might be implemented in future.

Comment on lines +115 to +117
// I will remove it once we agree on the overall design.
// Payload of the rule action. The payload is specific to the rule action type.
// temporal.api.common.v1.Payload payload = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Same. Leave it commented out. I think it is acceptable.

Comment on lines +119 to +120
// NamespaceRule describes a rule that can be to any workflow in this namespace.
message NamespaceRule {
Copy link
Member

Choose a reason for hiding this comment

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

I like NamespaceRule the most.

Comment on lines +122 to +126
// Name of the rule.
string name = 1;

// ID must be unique within the namespace
string id = 2;
Copy link
Member

Choose a reason for hiding this comment

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

I think you should follow the same approach as we do for namespaces themselves. Id is hidden from the user (mostly). When user creates rule, it specifies only name and gets Id back in response. Then user can address rule by name (and by Id too). Yes, you can't guarantee uniqueness of the name. We need to discuss what we can do in this case.

}

// ApplyNamespaceRule allows to apply rule to a certain workflow instance without creating a rule.
// This is useful for one-off operations.
Copy link
Member

Choose a reason for hiding this comment

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

and for tests too. I mean users can test how feature works with test workflows.

message DescribeNamespaceRuleRequest {
string namespace = 1;

string rule_id = 2;
Copy link
Member

Choose a reason for hiding this comment

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

It would be great if you use oneof for both id and name. And for Delete too.


message RuleAction {
// Type of the rule action.
temporal.api.enums.v1.RuleActionType type = 1;
Copy link
Member

Choose a reason for hiding this comment

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

I think you should consider structured data for the action instead of an enum. Therefore if an action needs data, it can be properly modeled data and not arbitrary payload or whatever. I recommend a oneof with specific messages representing the actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that is exactly what I did, PR is not updated - I want to update it after the discussion.

// Type of the rule trigger. Right now only activity is supported.
// Trigger type defines when the rule should be evaluated.
// It also defines the columns available in the predicate.
// - activity: Rule will be triggered when an activity is about to start.
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't sound like an ACTIVITY trigger, but rather an ACTIVITY_START trigger. There are many event situations in an activity.

Comment on lines +65 to +66
RULE_TRIGGER_TYPE_ACTIVITY = 1;
RULE_TRIGGER_TYPE_WORKFLOW = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Can we define what these represent? And if workflow is not in use it does not need to be present.

enum RuleActionType {
RULE_ACTION_TYPE_UNSPECIFIED = 0;
RULE_ACTION_TYPE_PAUSE_ACTIVITY = 1;
RULE_ACTION_TYPE_EMIT_METRIC = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Can you clarify what emit metric means exactly? There are lots of details to emitting a metric (metric name, labels, etc) but I can't find where such things would be set. Also, is that part of this project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about emitting metrics with predefined name, with dimensions like namespace, "type". May be with "rule name" as well.

Copy link
Member

Choose a reason for hiding this comment

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

Can you document the exact behavior of this enum? It was unclear to me and I suspect other users of the API what this means exactly? I do think this and other actions make sense as structured messages instead of just enumerates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, in the doc I moved from enum to "oneof" and messages, so we can have structured action payload later if we need to.

// Trigger type defines when the rule should be evaluated.
// It also defines the columns available in the predicate.
// - activity: Rule will be triggered when an activity is about to start.
temporal.api.enums.v1.RuleTriggerType trigger_type = 3;
Copy link
Member

Choose a reason for hiding this comment

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

I think the concept of "action" and the "trigger" should be merged. Some actions make no sense with some triggers I assume. I think an action should also define when it should take place alongside its other options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no 1:1 mapping between "action" and "trigger". For example workflow pause can be triggered by activity rule.

// RULE_ACTION_TYPE_EMIT_VISIBILITY = 3;
// RULE_ACTION_TYPE_PAUSE_WORKFLOW = 4;
// RULE_ACTION_TYPE_SIGNAL = 5;
enum RuleActionType {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
enum RuleActionType {
enum NamespaceRuleActionType {

Not sure it's safe to assume every use of the term "rule" will apply to namespace rules (same in other places where not qualified)

// If true, the rule will be applied immediately via batch job.
bool force_apply = 3;

// the workflow query to use to apply the rule
Copy link
Member

Choose a reason for hiding this comment

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

Pedantic, but there is a lot of inconsistent with capitalization of comments, punctuation, etc

bool force_apply = 3;

// the workflow query to use to apply the rule
string workflow_query = 4;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this already in the rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I go back and force on this a lot...
we will discuss it offline

// - backoffInterval: The current backoff interval of the activity.
// - activityStatus: The status of the activity. Can be one of "scheduled", "started", "paused".
// - taskQueue: The name of the task queue of the activity.
string predicate = 4;
Copy link
Member

Choose a reason for hiding this comment

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

What is a "predicate"? Is this some kind of new query format? Is it possible to use well-typed structured representations of this? If not, I would at least request a grammar (we didn't have it for the longest time for workflow query and people were confused for a long time), but ideally we are stronger typed and more structural than that.

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