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 #36418 - Honor TZ in datetime normalizer #369

Merged
merged 1 commit into from May 19, 2023

Conversation

adamruzicka
Copy link
Contributor

No description provided.

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Does it fix the issue?

hammer command TZ:

$ date
Fri May 19 13:24:00 UTC 2023

Browser timezone: Prague; current time 15:24:00

$ hammer job-invocation create --job-template "Run Command - Script Default" --organization-id "1" --location-id "2" --inputs command=date --search-query "nuka.helole.com" --start-at "2023-05-19 16:24:00"
$ Job invocation 28 created
$ hammer job-invocation info --id 28
$ ID: 28
Description: Run date
Status: queued
Success: N/A
Failed: N/A
Pending: N/A
Missing: 0
Total: N/A
Start: '2023-05-19 18:24:00 +0200'
Randomized ordering: false
Job Category: Commands
Mode: future
Time to pickup: 
Hosts: []

ScreenShot-1684503059249

When I log in to check the job invocation list, I see that job will be run in 3 hours instead of 1 hour.

UPD: I think it works properly already? I mean, I'm in UTC timezone running hammer command to schedule something which should happen in 3 hours. And it will be run in 3 hours. If I want the command to be run in 1 hour (relative to the server's timezone), I'd need to explicitly specify the timezone, no?

@ofedoren
Copy link
Member

Looking at the BZ, I think there are two ways to deal with that:

  1. Ignore BZ and say that if hammer and the server in different timezones, hammer should specify the server's timezone explicitly. Pros: no changes. Cons: user must explicitly specify TZ.
  2. Take hammer input, ask the server for it's timezone, convert hammer input to the server's timezone, send the actual request. Pros: BZ is resolved. Cons: we actually ignore explicitly provided TZ?

@ofedoren
Copy link
Member

Damn... Is the BZ about hammer and server being in the same TZ?..

@adamruzicka
Copy link
Contributor Author

Is the BZ about hammer and server being in the same TZ?

I think it is about the fact that unless you explicitly include a time zone information in the time string, hammer will assume it is in utc, ignoring the TZ of machine where hammer runs, machine where server runs and TZ the user in Foreman has configured.

Timezones are hell. Verbose & debug output of hammer looks correct, whatever dynflow gets seems correct as well

# date                                                                                                                                                                                                            
Fri May 19 13:48:25 UTC 2023

# hammer -v -d job-invocation create --job-template "Run Command - Script Default" --organization-id "1" --location-id "2" --inputs command=date --search-query "nuka.helole.com" --start-at "2023-05-19 16:24:00"
-----B<-----SNIP-----B<-----SNIP
[ INFO 2023-05-19T13:48:59 API] POST /api/job_invocations                                                                                                                                                                                                                               
[DEBUG 2023-05-19T13:48:59 API] Params: {                                                                                                                                                                                                                                               
        "location_id" => 2,                                                                                                                                                                                                                                                             
    "organization_id" => 1,                                                                                                                                                                                                                                                             
     "job_invocation" => {                                                                                                                                                                                                                                                              
            "job_template_id" => 175,                                                                                                                                                                                                                                                   
                     "inputs" => {                                                                                                                                                                                                                                                      
            "command" => "date"                                                                                                                                                                                                                                                         
        },                                                                                                                                                                                                                                                                              
                        "ssh" => {},                                                                                                                                                                                                                                                    
                 "recurrence" => {},                                                                                                                                                                                                                                                    
                 "scheduling" => {                                                                                                                                                                                                                                                      
            "start_at" => "2023-05-19T16:24:00+00:00"                                                                                                                                                                                                                                   
        },
        "concurrency_control" => {},
               "search_query" => "nuka.helole.com",
             "targeting_type" => "static_query"
    }
}
[DEBUG 2023-05-19T13:48:59 API] Headers: {}
[DEBUG 2023-05-19T13:48:59 API] Using authenticator: HammerCLIForeman::Api::SessionAuthenticatorWrapper
[DEBUG 2023-05-19T13:48:59 API] Response: {
                "id" => 7,
       "description" => "Run date",
      "job_category" => "Commands",
      "targeting_id" => 7,
            "status" => 2,
          "start_at" => "2023-05-19 16:24:00 UTC",
      "status_label" => "queued",
          "ssh_user" => nil,
    "time_to_pickup" => nil,
      "dynflow_task" => {
           "id" => "46d0fc92-d6d1-4015-860f-e777e594e8e7",
        "state" => "scheduled"
    },
         "succeeded" => "N/A",
            "failed" => "N/A",
           "pending" => "N/A",
             "total" => "N/A",
           "missing" => 0,
         "targeting" => {
                "bookmark_id" => nil,
               "search_query" => "nuka.helole.com",
             "targeting_type" => "static_query",
                    "user_id" => 4,
        "randomized_ordering" => nil,
                      "hosts" => []
    },
              "task" => {
           "id" => "46d0fc92-d6d1-4015-860f-e777e594e8e7",
        "state" => "scheduled"
    },
              "mode" => "future",
        "scheduling" => {
            "start_at" => "2023-05-19 16:24:00 UTC",
        "start_before" => nil
    }
}

# TZ=America/New_York date
Fri May 19 09:50:08 EDT 2023

# TZ=America/New_York hammer -v -d job-invocation create --job-template "Run Command - Script Default" --organization-id "1" --location-id "2" --inputs command=date --search-query "nuka.helole.com" --start-at "2023-05-19 16:24:00"

[ INFO 2023-05-19T09:49:43 API] POST /api/job_invocations                                                                                                                                                                                                                               
[DEBUG 2023-05-19T09:49:43 API] Params: {                                                                                                                                                                                                                                               
        "location_id" => 2,                                                                                                                                                                                                                                                             
    "organization_id" => 1,                                                                                                                                                                                                                                                             
     "job_invocation" => {                                                                                                                                                                                                                                                              
            "job_template_id" => 175,                                                                                                                                                                                                                                                   
                     "inputs" => {                                                                                                                                                                                                                                                      
            "command" => "date"                                                                                                                                                                                                                                                         
        },                                                                                                                                                                                                                                                                              
                        "ssh" => {},                                                                                                                                                                                                                                                    
                 "recurrence" => {},                                                                                                                                                                                                                                                    
                 "scheduling" => {                                                                                                                                                                                                                                                      
            "start_at" => "2023-05-19T16:24:00-04:00"                                                                                                                                                                                                                                   
        },                                                                                                                                                                                                                                                                              
        "concurrency_control" => {},                                                                                                                                                                                                                                                    
               "search_query" => "nuka.helole.com",                                                                                                                                                                                                                                     
             "targeting_type" => "static_query"                                                                                                                                                                                                                                         
    }
}
[DEBUG 2023-05-19T09:49:43 API] Headers: {}
[DEBUG 2023-05-19T09:49:43 API] Using authenticator: HammerCLIForeman::Api::SessionAuthenticatorWrapper
[DEBUG 2023-05-19T09:49:44 API] Response: {
                "id" => 8,
       "description" => "Run date",
      "job_category" => "Commands",
      "targeting_id" => 8,
            "status" => 2,
          "start_at" => "2023-05-19 20:24:00 UTC",
      "status_label" => "queued",
          "ssh_user" => nil,
    "time_to_pickup" => nil,
      "dynflow_task" => {
           "id" => "9047a32f-fb92-462a-835d-2654e2395351",
        "state" => "scheduled"
    },
         "succeeded" => "N/A",
            "failed" => "N/A",
           "pending" => "N/A",
             "total" => "N/A",
           "missing" => 0,
         "targeting" => {
                "bookmark_id" => nil,
               "search_query" => "nuka.helole.com",
             "targeting_type" => "static_query",
                    "user_id" => 4,
        "randomized_ordering" => nil,
                      "hosts" => []
    },
              "task" => {
           "id" => "9047a32f-fb92-462a-835d-2654e2395351",
        "state" => "scheduled"
    },
              "mode" => "future",
        "scheduling" => {
            "start_at" => "2023-05-19 20:24:00 UTC",
        "start_before" => nil
    }
}

16:24 UTC is 18:24 CEST (+02:00)
16:24 EDT is 20:24 UTC

What dynflow sees

select ddp.execution_plan_uuid,ddp.start_at from dynflow_delayed_plans as ddp inner join foreman_tasks_tasks as ftt on ftt.external_id = ddp.execution_plan_uuid::varchar where ftt.id in ('9047a32f-fb92-462a-835d-2654e2395351', '46d0fc92-d6d1-4015-860f-e777e594e8e7');
         execution_plan_uuid          |      start_at       
--------------------------------------+---------------------
 dba49f6c-761a-4fdc-af26-b665c78208a7 | 2023-05-19 16:24:00
 5dddaa05-9a60-495c-8625-36b46d7cdfa0 | 2023-05-19 20:24:00
(2 rows)

It seem ok all the way up until the ui tries to display it?

Copy link
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

I'm sorry, @adamruzicka, wrong testing. This patch indeed seems to fix the issue.

@ofedoren ofedoren merged commit 5c0846b into theforeman:master May 19, 2023
2 checks passed
@adamruzicka adamruzicka deleted the local-time branch May 19, 2023 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants