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

Support combining multiple output variables. #737

Merged
merged 3 commits into from
Dec 18, 2024

Conversation

dblock
Copy link
Member

@dblock dblock commented Dec 16, 2024

Description

  • Support combining multiple output variables, e.g. task_id: ${task.node}:${task.id}. I ended up not using this and getting the task ID from delete_by_query, but it's a useful feature IMO.

Issues Resolved

Part of #663.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Contributor

github-actions bot commented Dec 16, 2024

Changes Analysis

Commit SHA: 43dc5f2
Comparing To SHA: 1b6935f

API Changes

Summary

NO CHANGES

Report

The full API changes report is available at: https://github.com/opensearch-project/opensearch-api-specification/actions/runs/12397608942/artifacts/2338846969

API Coverage

Before After Δ
Covered (%) 606 (59.35 %) 606 (59.35 %) 0 (0 %)
Uncovered (%) 415 (40.65 %) 415 (40.65 %) 0 (0 %)
Unknown 43 43 0

@dblock dblock force-pushed the tasks-vars branch 5 times, most recently from 2990ceb to 3b06ff0 Compare December 16, 2024 18:32
Copy link
Contributor

github-actions bot commented Dec 16, 2024

Spec Test Coverage Analysis

Total Tested
536 536 (100 %)

@dblock dblock changed the title Support combining multiple output variables. Support combining multiple output variables, added tests for tasks. Dec 16, 2024
@dblock dblock marked this pull request as ready for review December 16, 2024 22:24
@dblock
Copy link
Member Author

dblock commented Dec 17, 2024

@nhtruong care to take a look pls?

@@ -87,16 +87,42 @@ export enum Result {
export class OutputReference {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed this when this was first added but this file is meant to hold type definitions only. This class should be in its own file.

Comment on lines 107 to 117
static replace(str: string, callback: (chapter_id: any, variable: any) => string): any {
// preserve type if 1 value is returned
let full_match = str.match(/^\$\{([^}]+)\}$/)
if (full_match) {
const spl = this.#split(full_match[1], '.', 2)
return callback(spl[0], spl[1])
} else return str.replace(/\$\{([^}]+)\}/g, (_, k) => {
const spl = this.#split(k, '.', 2)
return callback(spl[0], spl[1])
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should add a comment explaining what this function does because it's not clear what it's trying to achieve.

Comment on lines 119 to 126
static #split(str: any, delim: string, count: number): string[] {
if (str === undefined) return [str]
if (count <= 0) return [str]
const parts = str.split(delim)
if (parts.length <= count) return parts
const result = parts.slice(0, count - 1)
result.push(parts.slice(count - 1).join(delim))
return result
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs an explanation as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to helpers.

} else {
return str
}
return OutputReference.replace(str, (chapter_id, output_name) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is the only place the replace function is used, then having a generic replace function that can handle any callback is a bit over-engineered, IMO.

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 think it's best we keep the parsing regex values/logic in one place so it doesn't leak into the usage of it.

expect(OutputReference.replace('string', f)).toEqual('string')
expect(OutputReference.replace('${k.v}', f)).toEqual('[k:v]')
expect(OutputReference.replace('${k.value}', f)).toEqual('[k:value]')
expect(OutputReference.replace('${k.v.m}', f)).toEqual('[k:v.m]')
Copy link
Collaborator

@nhtruong nhtruong Dec 17, 2024

Choose a reason for hiding this comment

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

I was on board until the last example. It's not clearly why k is treated differently from v and m and how the callback f caused such an output.

Copy link
Member Author

Choose a reason for hiding this comment

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

Our output variables are split with namespace.xyz where namespace=payload and is meaningful, but the rest of it is not and can be anything, including something that contains periods. That's basically what this is testing.

@dblock dblock mentioned this pull request Dec 17, 2024
@dblock dblock marked this pull request as draft December 17, 2024 20:14
@dblock
Copy link
Member Author

dblock commented Dec 17, 2024

Converted this to draft, will iterate. Extracted unrelated tests to #746.

@dblock dblock force-pushed the tasks-vars branch 2 times, most recently from f632b2a to c546f0e Compare December 18, 2024 15:06
@dblock dblock marked this pull request as ready for review December 18, 2024 15:07
@dblock dblock requested a review from nhtruong December 18, 2024 15:07
@dblock dblock changed the title Support combining multiple output variables, added tests for tasks. Support combining multiple output variables. Dec 18, 2024
@dblock
Copy link
Member Author

dblock commented Dec 18, 2024

Ready to be reviewed again, thanks @nhtruong!

@nhtruong nhtruong merged commit 4231dad into opensearch-project:main Dec 18, 2024
29 of 30 checks passed
Tokesh pushed a commit to Tokesh/opensearch-api-specification that referenced this pull request Dec 18, 2024
* Support combining multiple output variables.

Signed-off-by: dblock <[email protected]>
Tokesh pushed a commit to Tokesh/opensearch-api-specification that referenced this pull request Dec 18, 2024
* Support combining multiple output variables.

Signed-off-by: dblock <[email protected]>
Signed-off-by: Tokesh <[email protected]>
@dblock dblock deleted the tasks-vars branch December 18, 2024 20:16
dblock added a commit that referenced this pull request Dec 19, 2024
* adding missing tests

Signed-off-by: Tokesh <[email protected]>

* fixing validate ci, links, added node failure in specs

Signed-off-by: Tokesh <[email protected]>

* adding node failures to changelog, fixing path in specs of update by query and small fix in response of query group tests

Signed-off-by: Tokesh <[email protected]>

* Support combining multiple output variables. (#737)

* Support combining multiple output variables.

Signed-off-by: dblock <[email protected]>
Signed-off-by: Tokesh <[email protected]>

* hotfix of method in snapshots

Signed-off-by: Tokesh <[email protected]>

* hotfix with snapshot tests

Signed-off-by: Tokesh <[email protected]>

* hotfix race condition

Signed-off-by: Tokesh <[email protected]>

* adding chapter in snapshot tests

Signed-off-by: Tokesh <[email protected]>

* correcting path to repository in snapshot tests

Signed-off-by: Tokesh <[email protected]>

* adding verbose to check ci

Signed-off-by: Tokesh <[email protected]>

* deleting verbose

Signed-off-by: Tokesh <[email protected]>

* added retry to status in snapshots

Signed-off-by: Tokesh <[email protected]>

* added retry to correct place

Signed-off-by: Tokesh <[email protected]>

* adding verbose to check

Signed-off-by: Tokesh <[email protected]>

* renaming to avoid race condition

Signed-off-by: Tokesh <[email protected]>

* refactoring folder organization, adding retries, fixing naming

Signed-off-by: Tokesh <[email protected]>

---------

Signed-off-by: Tokesh <[email protected]>
Signed-off-by: dblock <[email protected]>
Signed-off-by: Niyazbek Torekeldi <[email protected]>
Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
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