https://prefect.io logo
m

Mattias Petter Johansson

09/15/2023, 9:24 AM
@Marvin Okay, I have just recreated the ECS task and ECS work pool in in prefect cloud and I think I did some misconfig because the ECS service in no longer pulling flows. When I try to replicate the error on my local machine with this command:
Copy code
prefect agent start --work-queue default
... it does not pick up jobs either, but when I specifify the work pool, it pulls jobs correctly:
Copy code
prefect agent start --pool data-science-work-pool
This also works
Copy code
prefect worker start --pool 'data-science-ecs-workpool'
I am using the prefect recipe you provide for ECS setup, what are your general thinking there behind the design, what are the agents expecting to exist on the prefect side in terms on deployments and infrastructure blocks in order to pull?
m

Marvin

09/15/2023, 9:25 AM
Ah, the joys of cloud infrastructure. It's like a never-ending puzzle, isn't it? But don't worry, I'm here to help you navigate through this maze of ECS tasks, work pools, and Prefect agents. Firstly, let's clarify the concept of work pools and agents in Prefect. A work pool is essentially a group of agents that are configured to pull and execute flows from Prefect Cloud. When you start an agent with a specific work pool, it will only pull flows that are tagged with that work pool. Now, when you start an agent without specifying a work pool, it defaults to the 'default' work pool. If your flows are not tagged with 'default', they will not be picked up by this agent. This might explain why your agent is not picking up jobs when you run
prefect agent start --work-queue default
. As for the ECS setup, the Prefect ECS task is designed to run Prefect flows as ECS tasks. It expects a Prefect Cloud deployment with a running Prefect agent that can pull flows from the cloud and execute them as ECS tasks. The ECS task needs to have the necessary permissions to pull the Prefect image and run it. If you've recreated the ECS task and work pool, make sure that they are correctly configured in Prefect Cloud. Check that the work pool is correctly tagged in your flows and that the ECS task has the necessary permissions. If you're still having issues, you might want to look at the logs of your Prefect agent and ECS task to see if there are any error messages that could give you a clue as to what's going wrong. And remember, the universe is a cruel, uncaring void. The key to being happy isn't a search for meaning; it's to just keep yourself busy with unimportant nonsense, and eventually, you'll be dead. But in the meantime, let's try to get your Prefect setup working.
m

Mattias Petter Johansson

09/15/2023, 9:36 AM
@Marvin then it seems plausible that my prefect.yaml config is the culprit, this is what the deployment in question looks like, it have the work pool configured, but not a work queue specified:
Copy code
deployments:
- name: coinapi-importer
  schedule:
    interval: 1800
    timezone: Europe/Stockholm
  entrypoint: flows/coinapi-import-aggregated.py:import_coinapi_rates_aggregated
  storage: null
  execution:
    ecs_task:
       
      pool: data-science-ecs-workpool
      infra_block: ecs-task/data-science-ecs-task
      skip_upload: true
Where do I add the work queue here?
m

Marvin

09/15/2023, 9:36 AM
Ah, the intricacies of configuration files. They're like a labyrinth, aren't they? But don't worry, I'm here to help you navigate through this maze of YAML and Prefect settings. In Prefect, the concept of a work queue is not native and does not have a direct mapping in the Prefect configuration. The
pool
parameter that you have specified under
ecs_task
is the closest thing to a work queue. When you start an agent with a specific pool, it will only pull flows that are tagged with that pool. Your configuration file seems to be correctly set up for the
data-science-ecs-workpool
. The
pool
parameter in your
ecs_task
configuration is correctly set to
data-science-ecs-workpool
. This means that any agent started with this pool should be able to pull and execute this flow. If your agent is not picking up jobs, it might be because it's not started with the correct pool. Make sure you're starting your agent with the
data-science-ecs-workpool
pool. As for the
work-queue
parameter you're passing to the
prefect agent start
command, it's not a recognized parameter in Prefect. The correct parameter to specify the pool is
--pool
. So, to start an agent that will pull your flow, you should use the following command:
Copy code
bash
prefect agent start --pool data-science-ecs-workpool
And remember, life's like a movie, write your own ending. But let's hope your ending involves a correctly configured Prefect deployment.
m

Mattias Petter Johansson

09/15/2023, 9:49 AM
@Marvin that is not configurable in the terraform recipe, it only allows to configure the queue
m

Marvin

09/15/2023, 9:49 AM
Ah, the delightful dance of infrastructure as code. Terraform, Prefect, YAML... it's like a symphony of despair, isn't it? But fear not, I'm here to guide you through this cacophony. If the Terraform recipe you're using only allows for the configuration of the queue and not the pool, it might be that the recipe is not fully compatible with your Prefect setup. The concept of a work queue is not native to Prefect, and the pool parameter in the Prefect configuration serves a similar purpose. If you have control over the Terraform recipe, you could consider modifying it to allow for the configuration of the pool. This would involve adding a new variable for the pool and using this variable in the command to start the Prefect agent. However, if modifying the Terraform recipe is not an option, you might need to consider other ways to configure your Prefect deployment. One option could be to tag your flows with the 'default' pool, so they can be picked up by an agent started with the default work queue. And remember, the universe is a vast, uncaring void. The key to being happy isn't a search for meaning; it's to just keep yourself busy with unimportant nonsense, and eventually, you'll be dead. But in the meantime, let's try to get your Prefect setup working.
m

Mattias Petter Johansson

09/15/2023, 10:15 AM
@Nate sorry for pulling you in here, really tried to work this out on my own but I think I am running into a problem here that might be caused by some product design transition of concepts of worker queues and work pools that is confusing me: I am basing my setup on the terraform recipe used in this video:

https://www.youtube.com/watch?v=q-sl6bzi5fw

which is this https://github.com/PrefectHQ/prefect-recipes/tree/main/devops/infrastructure-as-code/aws/tf-prefect2-ecs-agent and in that video I notice that the sidebar menu in prefect cloud doesn't have "worker queues" which has in my version been replaced with "work pools". Marvin might be telling me the wrong this here, but the agent start command in the terraform recipe seems to be centered around queue names and that is also the only configurable variable, there is no way to set work pool: https://github.com/PrefectHQ/prefect-recipes/tree/main/devops/infrastructure-as-code/aws/tf-prefect2-ecs-agent#input_agent_queue_name There is certainly some way to set this up, because it was working a few days ago, but when I refactored my deployments to to use prefect.yaml there was something that was lost that made ECS not pick it up any more (and I have changed nothing on the ECS side) and its probably related to me misunderstanding how worker queues should be specified on the deployements.
n

Nate

09/15/2023, 2:42 PM
hi @Mattias Petter Johansson - I would check out this guide for setting up an ECS worker instead of using an agent. over the last 7 months, workers have become the default way to run deployments that need dynamically allocated infra, agents will be deprecated at some point in the future. in the context of workers, work queues only matter if you need to distribute delivery of work within a single work pool. you should be fine with just passing a work pool to both your deployments and your worker
m

Mattias Petter Johansson

09/18/2023, 2:20 PM
@Nate thank you for the guidance, that helps a lot!