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

KS-15 Add a capabilities library to the core node #11811

Merged
merged 33 commits into from
Feb 2, 2024

Conversation

DeividasK
Copy link
Collaborator

@DeividasK DeividasK commented Jan 18, 2024

Paired with @cedric-cordenier (and by paired, I mean that he did most of the work 😅).

The initial set of interfaces. This will be iterated in follow-up PRs, but we want to create a reference point to parallelize capability development.

Copy link
Contributor

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

@cedric-cordenier cedric-cordenier force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from 8ff53ea to 7528c5f Compare January 18, 2024 17:40
@cedric-cordenier cedric-cordenier force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from 7528c5f to 7c66aba Compare January 19, 2024 10:51
@cedric-cordenier cedric-cordenier force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from 7c66aba to e60d1d9 Compare January 19, 2024 11:38
@cedric-cordenier cedric-cordenier force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from e60d1d9 to cabc0f6 Compare January 19, 2024 13:55
@cedric-cordenier cedric-cordenier force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from cabc0f6 to cff4ea5 Compare January 19, 2024 13:56
@cedric-cordenier cedric-cordenier force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from cff4ea5 to 1ed979b Compare January 19, 2024 14:39
@cedric-cordenier cedric-cordenier force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from 1ed979b to f636f06 Compare January 22, 2024 12:53
@DeividasK DeividasK force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from 3e413bd to 2291339 Compare January 23, 2024 10:24
go.mod Show resolved Hide resolved
// when the context is cancelled. When a request has been completed the capability
// is also expected to close the callback channel.
// Request specific configuration is passed in via the inputs parameter.
Execute(ctx context.Context, callback chan values.Value, inputs values.Map) error
Copy link
Contributor

Choose a reason for hiding this comment

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

are we adding the name field?

core/capabilities/capability.go Outdated Show resolved Hide resolved
}

// CapabilityInfo is a struct for the info of a capability.
type CapabilityInfo struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where does this return what the strong type is?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmm -- what do you mean by "strong type"?

Copy link
Contributor

Choose a reason for hiding this comment

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

@nolag are you talking about CapabilityType?

}

// Info returns the info of the capability.
func (c CapabilityInfo) Info() CapabilityInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

May want to return map[string]CapabilityInfo so we can add name to execute.

Copy link
Contributor

Choose a reason for hiding this comment

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

CapabilityInfo includes ID, isn't that enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a separate conversation that is resolved now - we've parked this for now and @cedric-cordenier will write an exploration doc on whether we want to pass in a name field or not.

core/capabilities/registry.go Outdated Show resolved Hide resolved
core/capabilities/capability.go Outdated Show resolved Hide resolved
// when the context is cancelled. When a request has been completed the capability
// is also expected to close the callback channel.
// Request specific configuration is passed in via the inputs parameter.
Execute(ctx context.Context, callback chan values.Value, inputs values.Map) error
Copy link
Contributor

Choose a reason for hiding this comment

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

I left this question in the CRON doc: if Execute() registers a trigger, how do we de-register it when a workflow is deleted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the responsibility of a workflow engine. There are 2 steps to capabilities:

  • A capability is registered by a NOP.
  • A capability is started when a workflow requiring it is received.
    (I can already see the comment on line 47 being wrong 😅)

Similarly, when a workflow requiring a capability is removed, the capability should be stoped. @cedric-cordenier we'll need to add more details here.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, if start/stop is per workflow then it makes more sense.

core/capabilities/capability.go Show resolved Hide resolved
core/capabilities/capability.go Outdated Show resolved Hide resolved
HenryNguyen5
HenryNguyen5 previously approved these changes Feb 1, 2024
// Capability must respect context.Done and cleanup any request specific resources
// when the context is cancelled. When a request has been completed the capability
// is also expected to close the callback channel.
// Request specific configuration is passed in via the inputs parameter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Outdated comment? I do not see an inputs parameter

@cedric-cordenier cedric-cordenier force-pushed the KS-15-add-a-capabilities-library-to-the-core-node branch from 974d6f2 to 7b8ac45 Compare February 1, 2024 23:57
@DeividasK DeividasK changed the title start working on capability.go KS-15 Add a capabilities library to the core node Feb 2, 2024
panic("unknown capability type")
}

// IsValid checks if the capability type is valid.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: some comments feel excessive in this file, code is self-explanatory

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

golint

Copy link
Contributor

Choose a reason for hiding this comment

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

huh? is golint forcing us to have comments everywhere?

}

// CapabilityInfo is a struct for the info of a capability.
type CapabilityInfo struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

@nolag are you talking about CapabilityType?

}

// Info returns the info of the capability.
func (c CapabilityInfo) Info() CapabilityInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

CapabilityInfo includes ID, isn't that enough?

core/capabilities/capability.go Outdated Show resolved Hide resolved
core/capabilities/capability.go Show resolved Hide resolved
core/capabilities/examples/on_demand_trigger_test.go Outdated Show resolved Hide resolved
core/capabilities/registry_test.go Outdated Show resolved Hide resolved
"v1.0.0",
)

// OnDemandTrigger is an example on-demand trigger.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we explain that this trigger supports sending ad-hoc events to registered listeners?

core/capabilities/examples/on_demand_trigger_test.go Outdated Show resolved Hide resolved
}

// Execute executes the on-demand trigger.
func (o *OnDemandTrigger) SendEvent(ctx context.Context, wid string, event capabilities.CapabilityResponse) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if this is a good example. Should a trigger ever support targeting a particular workflow ID? It seems like listeners should be transparent to triggers. Let me know if I'm missing an obvious use case.

@cl-sonarqube-production
Copy link

@bolekk bolekk added this pull request to the merge queue Feb 2, 2024
Merged via the queue into develop with commit ec1479e Feb 2, 2024
93 checks passed
@bolekk bolekk deleted the KS-15-add-a-capabilities-library-to-the-core-node branch February 2, 2024 18:45
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.

5 participants