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

Rails API with Mission Control #60

Closed
tooney92 opened this issue Feb 5, 2024 · 47 comments
Closed

Rails API with Mission Control #60

tooney92 opened this issue Feb 5, 2024 · 47 comments
Assignees

Comments

@tooney92
Copy link

tooney92 commented Feb 5, 2024

Is there a way to use mission control UI for a rails API backend application?

@rosa
Copy link
Member

rosa commented Feb 6, 2024

Hey @tooney92, yes! It shouldn't be any difference, as long as your application has jobs that you need to manage, you should be able to use Mission Control for it. Are you encountering any problems there?

@tooney92
Copy link
Author

tooney92 commented Feb 6, 2024

Hi @rosa Thanks for the feedback, this is the error I get

Screenshot 2024-02-06 at 15 17 28

for context, I have no assets folder since my application is purely a rails API.

@rosa
Copy link
Member

rosa commented Feb 12, 2024

Oh, right, of course 🤦‍♀️ The API-only app doesn't know about JS assets or anything related to them. I'd need some more time to figure out how to fix this in your app. Let me know if you fix it!

@rails rails deleted a comment from LAEG31 Feb 22, 2024
@zavan
Copy link
Contributor

zavan commented Feb 23, 2024

I had to give up on API mode to use it.

  1. Added gem "propshaft" to gem file (lighter than sprockets and seems to work for this)
  2. ApplicationController extends ActionController::Base instead of ActionController::API and added protect_from_forgery with: :null_session
  3. Removed config.api_only = true from config/application.rb

@tooney92
Copy link
Author

Thanks @zavan I think I would try this route. Thank you also @rosa for helping out. Will close the issue now :)

@joshforbes
Copy link

I'm not exactly sure how they do it but Sidekiq has a web UI that works with an API-only Rails app.

https://github.com/sidekiq/sidekiq/wiki/Monitoring#rails

If anyone has a solution that doesn't involve leaving API mode, I'd be interested in hearing it. 🙏

@zavan
Copy link
Contributor

zavan commented Feb 27, 2024

@joshforbes They are using a custom rack app to handle routes, views and assets (see https://github.com/sidekiq/sidekiq/tree/main/lib/sidekiq/web). I don't think that's a good option for Mission Control as it's Rails-based.

I may be wrong, but maybe it's possible for the Mission Control Rails engine to load its required middleware if they're not loaded already by the main Application, and add a propshaft dependency if necessary.

@rosa
Copy link
Member

rosa commented Feb 27, 2024

@zavan yes! I think we could make it work; it's just that we didn't think about API mode when we built this. I probably won't have time to work on this soon, but if anyone wants to try, it'd be super welcome. Otherwise, we'll eventually get to it 😊

@zavan
Copy link
Contributor

zavan commented Feb 27, 2024

@rosa Can you take a look at #87?

@joshforbes @tooney92 If you could test the branch out on your applications that would help too:

gem "mission_control-jobs", git: "https://github.com/basecamp/mission_control-jobs.git", ref: "pull/87/head"

@tooney92
Copy link
Author

Will do @zavan

@tooney92
Copy link
Author

Screenshot 2024-02-28 at 12 11 40
Screenshot 2024-02-28 at 12 12 07

Got these errors. I attached my gem file

@zavan
Copy link
Contributor

zavan commented Feb 28, 2024

@tooney92 Yeah I got this a few times too but it worked at some point. Can you try using the branch from my fork please:

gem "mission_control-jobs", github: "zavan/mission_control-jobs", branch: "api-only"

@MarcMogdanz
Copy link

@tooney92 Yeah I got this a few times too but it worked at some point. Can you try using the branch from my fork please:

gem "mission_control-jobs", github: "zavan/mission_control-jobs", branch: "api-only"

Can confirm that this works for my API-only Rails app without any issues so far, thank you so much for your work!

@grin
Copy link

grin commented Mar 20, 2024

I know this is being addressed, just wanted to mention this is not an api-only issue. You'll get the same error if you use something like vite_ruby to manage the assets in your app.

@fabianof
Copy link

Hi, @zavan.

First of all, thanks for your PR focused on API-only apps.

I tried it out, but somehow columns for error and button actions, as well as "Recurring tasks" menu item, are not being shown.

This is what I get from mission_control-jobs 0.2.0 together with sprockets-rails:

Screenshot 2024-03-27 at 15 59 13

This is what I get from mission_control-jobs 0.2.0 together with propshaft (no error column, no discard and retry buttons per job entry):

Screenshot 2024-03-27 at 16 07 31

This is what I get from your PR (no error column, no discard and retry buttons per job entry, no "Recurring tasks" menu item):

Screenshot 2024-03-27 at 15 58 49

Could you please let me know we need any additional changes?

@zavan
Copy link
Contributor

zavan commented Mar 27, 2024

Hey @fabianof, this is because my branch is behind v0.2.0.

I’ll come back to this PR tomorrow and hopefully get it ready to merge.

@fabianof
Copy link

Not sure word breaking will be handled by your branch:

317484959-b4af84ff-f784-4e88-bfde-9a4dda40d2c9

This is what we get from sprockets-rails out of the box:

.jobs td {
   word-break: break-all;
}

Which prevents layout breaking when job has huge words:

317484867-ab16b460-d229-4c55-9e13-23c55ca73102

@fabianof
Copy link

The issue is that following CSS is rendered out of the box by sprockets-rails, but not by propshaft.

.jobs td {
   word-break: break-all;
}

https://github.com/zavan/mission_control-jobs/blob/api-only/app/assets/stylesheets/mission_control/jobs/jobs.css

@fabianof
Copy link

Hi, @zavan. Are you planning coming back to this change any time soon? Unfortunately we are still facing the issue.

Somehow Mission Control Jobs CSS is handled out of the box by sprockets-rails, but not by propshaft.

.jobs td {
   word-break: break-all;
}

https://github.com/zavan/mission_control-jobs/blob/api-only/app/assets/stylesheets/mission_control/jobs/jobs.css

Not sure you will be able to handle that as well.

@zavan
Copy link
Contributor

zavan commented Jul 24, 2024

@fabianof I have rebased my branch to be current with main and I believe fixed the CSS importing.

Can you try it?

@fabianof
Copy link

fabianof commented Aug 8, 2024

Issue persists, @zavan. Somehow Mission Control jobs styles are not being loaded properly. Note that word break is missing here, which prevents showing other dashboard columns:

Screenshot 2024-08-08 at 16 42 26

@arikarim
Copy link

Thanks for your pr @zavan
There is an issue with pausing a queue then resuming it.
currently if you pause a queue it will work, but clicking on resume does not do anything an the queue will stuck including all the jobs inside it.

@rosa
Copy link
Member

rosa commented Aug 19, 2024

@arikarim, huh! That's weird, let me look into that.

@rosa
Copy link
Member

rosa commented Aug 19, 2024

Hmm... @arikarim, I can't reproduce that. Pausing and resuming is working correctly for me, with Solid Queue. Are you referring to Solid Queue or Resque? And can you grab the logs for the Resume request?

@arikarim
Copy link

Hello @rosa thanks for your quick response.
It is so weird, clicking on resume button still sends the pause request.
I am using rails in API mode with solid_queue, also im using @zavan 's forked branch.
image

@rosa
Copy link
Member

rosa commented Aug 19, 2024

That's correct, the request goes to /pause but it should send _method: delete. Does it? Could you check the server logs for that request too?

@arikarim
Copy link

below is the server log:
I, [2024-08-19T14:11:19.737117 #21] INFO -- : [5c99e992-5262-4234-b065-caad31d57be7] {"method":"POST","path":"/jobs/applications/beasprocessesapi/queues/default/pause","format":"turbo_stream","controller":"MissionControl::Jobs::Queues::PausesController","action":"create","status":302,"allocations":3279,"duration":9.33,"view":0.0,"db":4.46,"location":"http://localhost:3000/jobs/applications/beasprocessesapi/queues"}

@rosa
Copy link
Member

rosa commented Aug 19, 2024

Hm... yeah, that's the pause request... so weird. I'll try again to reproduce it.

@rosa rosa reopened this Aug 20, 2024
@rosa rosa self-assigned this Aug 20, 2024
@Jay-Dabo
Copy link

Jay-Dabo commented Sep 7, 2024

After installing i get

{"error":"undefined method `length' for nil"}

on my web

@sasharevzin
Copy link

if css used as CDN, can't we have custom CSS be embedded with <style> tags and remove propshaft despendency?

@HLFH
Copy link

HLFH commented Oct 21, 2024

Since 0.3.3 release, we are getting the error:

/Users/MYUSER/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-8.0.0.rc1/lib/rails/railtie/configuration.rb:109:in `method_missing': undefined method `assets' for an instance of Rails::Application::Configuration (NoMethodError)
Did you mean?  asset_host
        from /Users/MYUSER/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/mission_control-jobs-0.3.3/lib/mission_control/jobs/engine.rb:90:in `block in <class:Engine>'

To revert to the working API-only version, please do the following in your Gemfile:

# Active Job dashboard
gem "mission_control-jobs", "0.3.2"

@blocknotes
Copy link

@sasharevzin: I was trying the same idea but from a fast check you would have troubles with hotwire/turbo rails (used for example for filtering).

From my standpoint, the UI could be updated to use only inline resources (without Hotwire I suppose).
Or creating a bundle of the JS files and loading it from the CDN (since Bulma is loaded via cdn.jsdelivr.net).

Both ways require some effort (in different ways).

@wilbertliu
Copy link

wilbertliu commented Oct 31, 2024

Anyone know what happened here?

I'm on Rails 8 rc2 with Inertia and vite_ruby. Posting here because I saw @grin said vite_ruby users are also affected.

CleanShot 2024-10-31 at 13 29 22@2x
CleanShot 2024-10-31 at 13 31 17@2x

@rosa
Copy link
Member

rosa commented Nov 11, 2024

Here's another take on the API-only version: #203. It simply instructs you to install propshaft instead of adding it as a dependency. I think it's simpler and could be enough for that use-case.

@rosa
Copy link
Member

rosa commented Nov 11, 2024

@grin, what error do you get? The one about assets not being defined?

@wilbertliu: I haven't seen that error before, but it would be useful to see the beginning of the trace, to see where that recursive loop starts 🤔

@rosa
Copy link
Member

rosa commented Nov 12, 2024

Ok, I finally looked into vite_rails and vite_ruby, with whom I wasn't familiar before, and tested this with a demo app using vite_rails. It seems the same solution, installing propshaft, works in that case, too, so I'll add it to the README.

@rosa
Copy link
Member

rosa commented Nov 12, 2024

Ahh, I realised #203 still has a problem with turbo-rails not working correctly. I'm looking into it.

@rosa
Copy link
Member

rosa commented Nov 13, 2024

Figured it out, it wasn't turbo-rails but a missing middleware 😅

@wilbertliu
Copy link

Hey @rosa,

I couldn't reach the beginning of the trace – it was too deep. And now the mission control is not active, so it might take some time to reproduce the error and get the trace.

FYI, I'm not using API-only. Have you found anything helpful to fix it?

Thanks in advance :)

@rosa
Copy link
Member

rosa commented Nov 13, 2024

@wilbertliu, thank you! I haven't found anything to help your error because I don't think it's related to the problem in this issue (related to assets and some modules and middleware not being available for API-only apps) 🤔 I'd need more info in your case to figure it out.

@tooney92
Copy link
Author

tooney92 commented Nov 13, 2024

Hi all, I am guity for starting this issue early in the year and I want to thank @rosa and @zavan for your awesome work. I was able to move my company's backend to Solis Queue from sidekiq.

I however have this issue after I installed 'propshaft'. I cannot access mission control again.

This is a snippet of my gem file:

`ruby '3.3.4'

gem 'nokogiri', '1.16.6'

gem 'slack-notifier'

gem "audited"

gem "mission_control-jobs"

gem "propshaft"`

Screenshot 2024-11-13 at 22 37 05

@tooney92
Copy link
Author

tooney92 commented Nov 13, 2024

Rails

This seems to fix it for me :) --> #60 (comment)

@rosa
Copy link
Member

rosa commented Nov 14, 2024

Hey @tooney92, sorry for the confusion! The new changes are not yet merged, they're in #203, which you'd need to use together with adding propshaft to your app.

@wilbertliu
Copy link

@rosa Sure. I just made a new issue → #205 🙂

@rosa
Copy link
Member

rosa commented Nov 15, 2024

Released version 0.6.0 with these changes, this one should be fixed now!

@rosa rosa closed this as completed Nov 15, 2024
@brtz
Copy link

brtz commented Nov 19, 2024

Hey,
just a little hint and maybe something that should be clarified in the readme regarding mission-control with api-only:

By default, the Dockerfile generated by rails new my_api --api does not include

RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile

(see: https://github.com/rails/rails/blob/main/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt#L86-L88 same for --skip-asset-pipeline)

Therefor you can successfully build the docker image, but it will not contain any assets, leaving mission-control in a sort of broken state :). Hotfix: add the line to your dockerfile in the "build" image section. Right now, the readme says "just install propshaft, you will be fine". I think this should be extended a bit with the note to require assets:precompile. To be honest, I don't want to open a PR just for a new sentence on the docs, so if someone could sneak it in, I'd be grateful =)

@rosa
Copy link
Member

rosa commented Nov 19, 2024

Oh, right! I forgot that bit as I hadn't tested this with an API only app in production. I'll add that line, thank you!

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

No branches or pull requests