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

Fixes #31545: Add status of Rails cache to Ping API #9793

Merged
merged 1 commit into from
Nov 15, 2023

Conversation

ehelms
Copy link
Member

@ehelms ehelms commented Aug 4, 2023

Output from the API in the current format:

    "results": {
        "foreman": {
            "database": {
                "active": true,
                "duration_ms": "0"
            },
            "cache": {
                "type": "redis_cache_store",
                "servers": {
                    "0": {
                        "status": "ok",
                        "duration_ms": "0"
                    },
                    "1": {
                        "status": "FAIL",
                        "duration_ms": "1"
                    }
                }
            }
        },

Some considerations:

  • Multiple Redis servers can be configured for cache
  • The servers can independently fail and caching continues to work
  • We do not want to leak too much information into the Ping API since it is unauthenticated

@theforeman-bot
Copy link
Member

Issues: #31545

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Do we want to provide an overall OK/FAIL? I've been thinking about a cache set (with a short TTL) to test it end-to-end. Could be a potential attack vector though.

app/services/ping.rb Outdated Show resolved Hide resolved
@ehelms
Copy link
Member Author

ehelms commented Oct 10, 2023

I've done a round of updates here and found that #9857 is required to not get errors.

app/services/ping.rb Outdated Show resolved Hide resolved
@ehelms
Copy link
Member Author

ehelms commented Oct 27, 2023

When using a non-redis cache, do you feel that the response should be:

empty

{:foreman=>
    {
         :database=>{:active=>true, :duration_ms=>0},
         :cache=>{}
}

not present

{:foreman=>
   {
         :database=>{:active=>true, :duration_ms=>0}
},

app/services/ping.rb Outdated Show resolved Hide resolved
@evgeni
Copy link
Member

evgeni commented Oct 30, 2023

I think I prefer either completely omitting cache or returning a generic {status: OK} in there for the non-redis cases, but wouldn't block on either implementation.

@ShimShtein
Copy link
Member

I see that the type property is missing from the final version. Ideally I think there should be at least the type, to indicate that the cache is enabled and what backend it uses.

So I think it should be an empty node, since we do know that the cache should be monitored, but we can't tell anything about its status. For me, missing node means that the status doesn't supply information about cache at all.

@ehelms
Copy link
Member Author

ehelms commented Oct 30, 2023

I see that the type property is missing from the final version. Ideally I think there should be at least the type, to indicate that the cache is enabled and what backend it uses.

This was removed originally to avoid leaking information to a non-authenticated API endpoint.

app/services/ping.rb Outdated Show resolved Hide resolved
@ofedoren
Copy link
Member

Also, this would be nice if we'd have a follow-up PR to hammer https://github.com/theforeman/hammer-cli-foreman/blob/master/lib/hammer_cli_foreman/ping.rb :)

@ehelms
Copy link
Member Author

ehelms commented Oct 31, 2023

Also, this would be nice if we'd have a follow-up PR to hammer https://github.com/theforeman/hammer-cli-foreman/blob/master/lib/hammer_cli_foreman/ping.rb :)

What is the needed follow up? I just assumed hammer outputs whatever the API sends. I'm sensing my assumption is incorrect.

@ofedoren
Copy link
Member

Also, this would be nice if we'd have a follow-up PR to hammer https://github.com/theforeman/hammer-cli-foreman/blob/master/lib/hammer_cli_foreman/ping.rb :)

What is the needed follow up? I just assumed hammer outputs whatever the API sends. I'm sensing my assumption is incorrect.

Well, if it was just a blob, it would be true, but since we use explicit fields there, one must be added. Didn't tests this PR against hammer though, so if you'll see the output then the follow-up is not needed.

@ehelms ehelms requested a review from evgeni October 31, 2023 19:16
@ehelms
Copy link
Member Author

ehelms commented Nov 3, 2023

Once this is merged, I'll take a look at hammer. I think this PR is ready to go?

Copy link
Member

@evgeni evgeni left a comment

Choose a reason for hiding this comment

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

After applying the fix this seems to work fine for me.

hammer is at least not confused by the new fields:

[root@centos8-stream-foreman-nightly foreman]# hammer status
Version:           3.9.0-develop
API Version:       v2
Database:          
    Status:          ok
    Server Response: Duration: 1ms
Plugins:           
 1) Name:    foreman_puppet
    Version: 6.1.0
Smart Proxies:     
 1) Name:     centos8-stream-foreman-nightly.tanso.example.com
    Version:  3.9.0-develop
    Status:   ok
    Features: 
     1) Name:    puppetca
        Version: 3.9.0
     2) Name:    puppet
        Version: 3.9.0
     3) Name:    logs
        Version: 3.9.0
Compute Resources:

[root@centos8-stream-foreman-nightly foreman]# hammer ping
database: 
    Status:          ok
    Server Response: Duration: 0ms

app/services/ping.rb Outdated Show resolved Hide resolved
app/services/ping.rb Outdated Show resolved Hide resolved
app/services/ping.rb Outdated Show resolved Hide resolved
@ehelms ehelms force-pushed the fixes-31545 branch 2 times, most recently from 1e1f4aa to d0e7a5a Compare November 14, 2023 18:06
@evgeni
Copy link
Member

evgeni commented Nov 14, 2023

Wonder if this works w/o rebase:

/packit build

@evgeni
Copy link
Member

evgeni commented Nov 14, 2023

@ofedoren would you mind having a look with hammer eyes? ;-)

I had added

          field :cache, _('cache'), Fields::Label do
            field :servers, _('servers'), Fields::Collection do
              field :status, _('Status')
              field :duration_ms, _('Server Response')
            end
          end

to my hammer ping.rb and things do not look too crazy

@ehelms ehelms merged commit 50f68c3 into theforeman:develop Nov 15, 2023
9 checks passed
@ofedoren
Copy link
Member

to my hammer ping.rb and things do not look too crazy

well, ideally they shouldn't :) And something like that (ideally) I'd expect in hammer to be able to see the cache details in hammer output. 👍

@evgeni
Copy link
Member

evgeni commented Nov 29, 2023

to my hammer ping.rb and things do not look too crazy

well, ideally they shouldn't :) And something like that (ideally) I'd expect in hammer to be able to see the cache details in hammer output. 👍

theforeman/hammer-cli-foreman#622

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.

6 participants