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

feat(cli): add queues, workers and worker-groups commands #4439

Merged
merged 20 commits into from
Sep 26, 2024
Merged

Conversation

rubenfiszel
Copy link
Contributor

@rubenfiszel rubenfiszel commented Sep 25, 2024

▶ wmill queues                             
Selected instance: localhost2
                                Running Waiting Later RPS (30s) RPS (5min) RPS (30min) RPS (24h)
bun                             0       0       1                          0.006       0.000    
ansible                         0       1       0                                               
yu                              0       2       0                                               
flow                            0       8       0                                      0.000    
bankA                           0       3       0                                               
python3                         0       3       0                                               
bun-foo                         0       1       0                                               
flow-foo                        0       1       0                                               
init_script                     0       0       0                                      0.000    
foo:u/admin/unassailable_script 0       0       0                                      0.000    
▶ wmill workers                                                         
Selected instance: localhost2

Worker Group: default (1 workers)
┌──────────────────────────┬─────────┬──────────────────────────────┬────────┬──────────────────────────────────┬─────────────┐
│  Worker ID               │  Host   │  Queues                      │  Jobs  │  Last job                        │  Last Ping  │
├──────────────────────────┼─────────┼──────────────────────────────┼────────┼──────────────────────────────────┼─────────────┤
│  wk-default-rubx1-MmanA  │  rubx1  │  bash, bigquery, bun, deno,  │  11    │  01922950-4b62-bc85-16b7-0edc95  │  0s ago     │
│                          │         │  dependency, flow, go,       │        │  eb5667 foo                      │             │
│                          │         │  graphql, mssql, mysql,      │        │                                  │             │
│                          │         │  nativets, other, php,       │        │                                  │             │
│                          │         │  postgresql, powershell,     │        │                                  │             │
│                          │         │  python3, snowflake          │        │                                  │             │
└──────────────────────────┴─────────┴──────────────────────────────┴────────┴──────────────────────────────────┴─────────────┘

Worker Group: foo (0 workers)
  No workers in this group

Worker Group: init2 (0 workers)
  No workers in this group

Worker Group: ded1 (0 workers)
  No workers in this group
▶ wmill worker-groups     
2 actions available, pull and push.
Active instance: localhost2
┌───────────┬──────────────────────────────────────────────────────────────────────┐
│  name     │  config                                                              │
├───────────┼──────────────────────────────────────────────────────────────────────┤
│  foo      │  {                                                                   │
│           │    "priority_tags": {},                                              │
│           │    "env_vars_static": {},                                            │
│           │    "dedicated_worker": "supercreator:flow/u/admin/monumental_flow",  │
│           │    "env_vars_allowlist": []                                          │
│           │  }                                                                   │
├───────────┼──────────────────────────────────────────────────────────────────────┤
│  default  │  {                                                                   │
│           │    "worker_tags": [                                                  │
│           │      "deno",                                                         │
│           │      "python3",                                                      │
│           │      "go",                                                           │
│           │      "bash",                                                         │
│           │      "powershell",                                                   │
│           │      "dependency",                                                   │
│           │      "flow",                                                         │
│           │      "other",                                                        │
│           │      "bun",                                                          │
│           │      "php",                                                          │
│           │      "nativets",                                                     │
│           │      "postgresql",                                                   │
│           │      "mysql",                                                        │
│           │      "graphql",                                                      │
│           │      "snowflake",                                                    │
│           │      "mssql",                                                        │
│           │      "bigquery"                                                      │
│           │    ],                                                                │
│           │    "priority_tags": {},                                              │
│           │    "env_vars_static": {},                                            │
│           │    "env_vars_allowlist": []                                          │
│           │  }                                                                   │
├───────────┼──────────────────────────────────────────────────────────────────────┤
│  init2    │  {                                                                   │
│           │    "init_bash": "echo \"foo\"\necho \"bar\"\necho \"bar\"",          │
│           │    "worker_tags": [],                                                │
│           │    "priority_tags": {},                                              │
│           │    "env_vars_static": {},                                            │
│           │    "env_vars_allowlist": []                                          │
│           │  }                                                                   │
├───────────┼──────────────────────────────────────────────────────────────────────┤
│  ded1     │  {                                                                   │
│           │    "priority_tags": {},                                              │
│           │    "env_vars_static": {},                                            │
│           │    "dedicated_worker": "foo:u/admin/unassailable_script",            │
│           │    "env_vars_allowlist": []                                          │
│           │  }                                                                   │
└───────────┴──────────────────────────────────────────────────────────────────────┘

Important

Add CLI commands for managing queues, workers, and worker groups with corresponding backend and frontend support.

  • CLI Commands:
    • Add queues, workers, and worker-groups commands in cli/main.ts.
    • Implement displayQueues in cli/queues.ts to list queue metrics.
    • Implement displayWorkers in cli/workers.ts to list workers by group.
    • Implement displayWorkerGroups in cli/worker_groups.ts to manage worker group configs.
  • Backend:
    • Add API endpoint /jobs/completed/count_by_tag in openapi.yaml for job count by tag.
    • Update worker_ping table with occupancy_rate_5m and occupancy_rate_30m in migrations/20240924213010_add_last_occupancy_rates.up.sql.
    • Modify list_worker_pings in workers.rs to include new occupancy rates.
  • Frontend:
    • Update +page.svelte to display worker groups and metrics.
  • Misc:
    • Add new SQL queries in .sqlx files for metrics and worker updates.
    • Update instance.ts to handle new CLI commands and options.

This description was created by Ellipsis for eeefdf5. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to aeb3cf3 in 1 minute and 27 seconds

More details
  • Looked at 1648 lines of code in 23 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. backend/src/monitor.rs:1075
  • Draft comment:
    The save_metrics logic defaults to true if last_check is None, which might lead to unnecessary metric saving. Consider handling the None case more explicitly or initializing last_check with a more appropriate default.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment points out a potential inefficiency in the logic that defaults save_metrics to true when last_check is None. This could indeed lead to unnecessary operations if the intention was to avoid saving metrics in such cases. The comment is relevant to the changes made in the diff and suggests a possible improvement.
    The comment assumes that saving metrics when last_check is None is unnecessary, but without more context, it's unclear if this behavior is actually problematic. The current logic might be intentional to ensure metrics are saved at least once if no previous check exists.
    The logic of defaulting to true when last_check is None could be intentional, but the comment raises a valid point about potential inefficiency. It's worth considering if this behavior aligns with the intended functionality.
    The comment is valid as it highlights a potential inefficiency in the logic that defaults save_metrics to true when last_check is None. It is relevant to the changes made in the diff and suggests a possible improvement.
2. backend/windmill-api/src/configs.rs:47
  • Draft comment:
    Consider optimizing the removal of the 'worker__' prefix from config names by handling it at the point of data retrieval or in a single pass to improve efficiency.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    In backend/windmill-api/src/configs.rs, the list_worker_groups function modifies the name field of Config by removing the 'worker__' prefix. This is done in a loop, which is fine, but it would be more efficient to handle this transformation in a single pass or at the point of data retrieval if possible. This would reduce the need for iterating over the data multiple times.
3. backend/windmill-api/src/jobs.rs:5106
  • Draft comment:
    Consider using an integer type for horizon_secs in the SQL query instead of Float8 to avoid unnecessary type conversion.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment seems to address a potential inefficiency in the code by suggesting a type change to avoid unnecessary conversion. The SQL function make_interval might indeed expect an integer, and using f64 could be unnecessary. The comment is actionable and suggests a clear code improvement.
    I might be missing the exact requirements of the make_interval function and whether it strictly requires an integer. The current implementation might work as intended, and the conversion to f64 might not cause any issues.
    The suggestion to use an integer type seems reasonable and could improve code efficiency by avoiding unnecessary type conversion. It's worth considering this change if it aligns with the SQL function's requirements.
    Keep the comment as it suggests a clear and actionable improvement to the code by recommending a type change to avoid unnecessary conversion.
4. backend/windmill-api/src/workers.rs:92
  • Draft comment:
    Ensure that occupancy_rate_5m and occupancy_rate_30m fields are correctly populated in the database to avoid runtime errors when fetching worker pings.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    In backend/windmill-api/src/workers.rs, the list_worker_pings function fetches data from the worker_ping table. The query includes occupancy_rate_5m and occupancy_rate_30m, which are new fields. Ensure that these fields are correctly populated in the database to avoid runtime errors.

Workflow ID: wflow_rRYxmVsJVe0iJMgy


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

cloudflare-workers-and-pages bot commented Sep 25, 2024

Deploying windmill with  Cloudflare Pages  Cloudflare Pages

Latest commit: eeefdf5
Status:⚡️  Build in progress...

View logs

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Incremental review on e24dc6a in 41 seconds

More details
  • Looked at 114 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_p9JjFKvtFH7ghuTN


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

cli/workers.ts Outdated
} else {

new Table()
.header(["Worker ID", "Host", "Queues", "Jobs", "Occupancy rate 5m/30m/ever)", "Last job", "Last Ping"])
Copy link
Contributor

Choose a reason for hiding this comment

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

The header 'Occupancy rate 5m/30m/ever)' has a misplaced closing parenthesis. It should be 'Occupancy rate (5m/30m/ever)'.

Suggested change
.header(["Worker ID", "Host", "Queues", "Jobs", "Occupancy rate 5m/30m/ever)", "Last job", "Last Ping"])
.header(["Worker ID", "Host", "Queues", "Jobs", "Occupancy rate (5m/30m/ever)", "Last job", "Last Ping"])

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 0c7e73b in 28 seconds

More details
  • Looked at 950 lines of code in 34 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. backend/windmill-worker/src/worker.rs:1374
  • Draft comment:
    The function update_occupancy_metrics is correctly refactored to encapsulate the logic for updating occupancy metrics. This improves code readability and maintainability by separating concerns.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The function update_occupancy_metrics is defined in common.rs and used in worker.rs. The function is correctly refactored to encapsulate the logic for updating occupancy metrics. This refactoring improves code readability and maintainability by separating concerns. The function is used in run_worker to update the worker's occupancy metrics, which is consistent with its intended purpose. The refactoring does not introduce any logical errors or performance issues.

Workflow ID: wflow_ljZVvuYbDSZQIomI


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on d94b803 in 27 seconds

More details
  • Looked at 810 lines of code in 32 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. backend/src/ee.rs:7
  • Draft comment:
    Consider using a custom error type to indicate that this feature is not available in the community edition. This would make error handling more consistent and informative.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The code in backend/src/ee.rs and backend/windmill-api/src/ee.rs uses anyhow::anyhow! for error handling, which is fine for general errors. However, in the context of enterprise features, it might be more appropriate to use a custom error type that clearly indicates the feature is not available in the community edition. This would make error handling more consistent and informative.
2. backend/windmill-api/src/ee.rs:9
  • Draft comment:
    Consider using a custom error type to indicate that this feature is not available in the community edition. This would make error handling more consistent and informative.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The code in backend/src/ee.rs and backend/windmill-api/src/ee.rs uses anyhow::anyhow! for error handling, which is fine for general errors. However, in the context of enterprise features, it might be more appropriate to use a custom error type that clearly indicates the feature is not available in the community edition. This would make error handling more consistent and informative.

Workflow ID: wflow_eZ02RZqRBBrpdMTY


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 2815221 in 54 seconds

More details
  • Looked at 1148 lines of code in 14 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. backend/windmill-worker/src/deno_executor.rs:8
  • Draft comment:
    The handle_child function is imported from handle_child module here. Ensure consistent import paths across the codebase for better maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The handle_child function is used in multiple files, but the import path is inconsistent. It should be imported from handle_child module consistently.
2. backend/windmill-worker/src/graphql_executor.rs:15
  • Draft comment:
    The run_future_with_polling_update_job_poller function is imported from handle_child module here. Ensure consistent import paths across the codebase for better maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The run_future_with_polling_update_job_poller function is used in multiple files, but the import path is inconsistent. It should be imported from handle_child module consistently.
3. backend/windmill-worker/src/js_eval.rs:43
  • Draft comment:
    The run_future_with_polling_update_job_poller function is imported from handle_child module here. Ensure consistent import paths across the codebase for better maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The run_future_with_polling_update_job_poller function is used in multiple files, but the import path is inconsistent. It should be imported from handle_child module consistently.
4. backend/windmill-worker/src/mssql_executor.rs:19
  • Draft comment:
    The run_future_with_polling_update_job_poller function is imported from handle_child module here. Ensure consistent import paths across the codebase for better maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The run_future_with_polling_update_job_poller function is used in multiple files, but the import path is inconsistent. It should be imported from handle_child module consistently.

Workflow ID: wflow_kWakeWJEKwfElFUA


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on d96b4ab in 53 seconds

More details
  • Looked at 957 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. backend/windmill-worker/src/handle_child.rs:577
  • Draft comment:
    Using unwrap here can cause a panic if the child process does not have a handle to stdout. Consider handling this case more gracefully, perhaps by returning a Result or using expect with a clear error message.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
2. backend/windmill-worker/src/handle_child.rs:582
  • Draft comment:
    Using unwrap here can cause a panic if the child process does not have a handle to stderr. Consider handling this case more gracefully, perhaps by returning a Result or using expect with a clear error message.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. backend/windmill-worker/src/handle_child.rs:595
  • Draft comment:
    Using unwrap_or(0) here can lead to unexpected behavior if poll_next_line fails. Consider handling this case explicitly to avoid potential issues.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment points out a potential issue with error handling in the lines_to_stream function. The use of unwrap_or(0) could indeed mask errors, leading to unexpected behavior. This is a valid concern as it relates to error handling, which is crucial in robust software development.
    The comment assumes that the error handling is inadequate without considering the context in which lines_to_stream is used. It's possible that the surrounding code handles errors appropriately, making this comment less relevant.
    Even if the surrounding code handles errors, it's generally good practice to handle errors explicitly where they occur to avoid unexpected behavior. The comment highlights a potential improvement in error handling.
    The comment raises a valid point about error handling in the lines_to_stream function. It suggests an improvement that could prevent unexpected behavior, making it a useful comment to keep.
4. backend/windmill-worker/src/job_logger.rs:322
  • Draft comment:
    Using unwrap_or(0) here can lead to unexpected behavior if the char_indices iterator is empty. Consider handling this case explicitly to avoid potential issues.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The use of unwrap_or(0) is a common pattern to provide a default value when an option is None. In this context, it seems to be used to handle the case where the iterator is empty, which is a valid use case. The comment suggests that this might lead to unexpected behavior, but without specific evidence of an issue, it seems speculative.
    The comment might be pointing out a potential edge case that could lead to a bug, but without specific evidence or examples, it's hard to determine if it's a real issue.
    While the comment is speculative, it does raise a valid point about potential edge cases. However, without concrete evidence of an issue, it might not be necessary to address it immediately.
    The comment is speculative and does not provide strong evidence of an issue. It should be removed unless there is a clear indication of a problem.

Workflow ID: wflow_sOFVao50a6lKMioH


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on eeefdf5 in 52 seconds

More details
  • Looked at 2167 lines of code in 30 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. cli/workers.ts:69
  • Draft comment:
    There's an extra parenthesis in the header text for occupancy rate. It should be removed for consistency.
            .header(["Worker ID", "Host", "Queues",  "Jobs", "Occupancy rate 15s/5m/30m/ever", "Last job", "Last Ping"])
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The code in cli/workers.ts and frontend/src/routes/(root)/(logged)/workers/+page.svelte is related to displaying worker information, including occupancy rates. The occupancy rate is displayed in both the CLI and frontend, and the format is consistent. However, there is a minor inconsistency in the header text for occupancy rate in the CLI output, which includes an extra parenthesis. This should be corrected for consistency and clarity.

Workflow ID: wflow_bXYXsRZRWrUYy9Z3


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@rubenfiszel rubenfiszel merged commit 610bb7b into main Sep 26, 2024
2 of 4 checks passed
@rubenfiszel rubenfiszel deleted the rf/cliv3 branch September 26, 2024 08:32
@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant