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

(POOLER-81) Add time_remaining information #276

Merged
merged 2 commits into from
Jul 9, 2018
Merged

(POOLER-81) Add time_remaining information #276

merged 2 commits into from
Jul 9, 2018

Conversation

smcelmurry
Copy link
Contributor

Before, the only time calculation displayed for a given VM was the
lifetime parameter. Added the time_remaining parameter which will
display time until the VM is destroyed in hours, minutes, seconds.

Additionally, updated the running parameter to display in a similar
fashion as time_remaining.

Before, the only time calculation displayed for a given VM was the
lifetime parameter. Added the time_remaining parameter which will
display time until the VM is destroyed in hours, minutes, seconds.

Additionally, updated the running parameter to display in a similar
fashion as time_remaining.
@@ -644,7 +644,10 @@ def invalid_template_or_path(payload)
result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
result[params[:hostname]]['state'] = 'destroyed'
elsif rdata['checkout']
result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
running = Time.now - Time.parse(rdata['checkout'])
result[params[:hostname]]['running'] = format("%02dh %02dm %02ds", running / (60 * 60), (running / 60) % 60, running % 60)
Copy link
Contributor

Choose a reason for hiding this comment

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

modulos! modulo

@@ -644,7 +644,10 @@ def invalid_template_or_path(payload)
result[params[:hostname]]['running'] = ((Time.parse(rdata['destroy']) - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
result[params[:hostname]]['state'] = 'destroyed'
elsif rdata['checkout']
result[params[:hostname]]['running'] = ((Time.now - Time.parse(rdata['checkout'])) / 60 / 60).round(2)
running = Time.now - Time.parse(rdata['checkout'])
result[params[:hostname]]['running'] = format("%02dh %02dm %02ds", running / (60 * 60), (running / 60) % 60, running % 60)
Copy link
Contributor

Choose a reason for hiding this comment

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

My only question would be if something is using this existing API, like kermi or bitbar/vmfloaty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested this with vmfloaty and it just returns the json:

➜  vmpooler git:(pooler-81) # floaty get debian-7-i386
{"debian-7-i386":"poolvm-me51df2cadymlq0.company.com"}
➜  vmpooler git:(pooler-81) # floaty query poolvm-me51df2cadymlq0
     {
      "ok"=>true,
      "poolvm-me51df2cadymlq0"=>
       {"template"=>"debian-7-i386",
        "lifetime"=>24,
        "running"=>"00h 00m 08s",
        "time_remaining"=>"23h 59m 51s",
        "state"=>"running",
        "ip"=>"",
        "domain"=>"company.com"}
     }
➜  vmpooler git:(pooler-81) #

Not sure about bitbar or kerminator. Is there a plugin for kermi? I wasn't aware of that

Copy link
Contributor

@mattkirby mattkirby Jul 9, 2018

Choose a reason for hiding this comment

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

It looks like bitbar expects this to be a float64 value. So, we may consider pushing an update there before rolling out this change. Either way I think it's reasonable to merge and we can discuss whether to update bitbar before pushing this change out to instances.

/~https://github.com/johnmccabe/go-vmpooler/blob/1d64f9d873440ac7aa8e921b7b3ddd7b8b78e803/vm/vm.go#L18

Copy link

@johnmccabe johnmccabe Jul 10, 2018

Choose a reason for hiding this comment

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

I'd personally prefer if the running/time_remaining returned from the API didn't come formatted, would be preferable to leave this up to the client.

Or even better a start_time field, with TZ.

Copy link
Contributor

Choose a reason for hiding this comment

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

As this is a public API, this would be considered a breaking change (going from a Float to Formatted String). I know my PowerShell Pooler code will blow up because of this.

+1 to @johnmccabe . If the data is coming back formatted, the API should expose the raw data somehow and/or the explicitly say this is the "friendly" text version e.g.

     {
      "ok"=>true,
      "poolvm-me51df2cadymlq0"=>
       {"template"=>"debian-7-i386",
        "lifetime"=>24,
        "running"=>"0.01",
        "start_time" => "2018-01-01 01:02:03Z"
        "time_remaining"=>"23.99",
        "end_time" => "2018-01-02 01:02:03Z"
        "state"=>"running",
        "ip"=>"",
        "domain"=>"company.com"}
     }

@mattkirby
Copy link
Contributor

This looks reasonable to me. I wonder if we can add a block to the vm_spec tests
to validate this additional behavior. /~https://github.com/puppetlabs/vmpooler/blob/27c9ee75912a96377daaa48ecf4e0821d3d0538a/spec/integration/api/v1/vm_spec.rb

@mattkirby mattkirby merged commit 1910cff into master Jul 9, 2018
@mattkirby mattkirby deleted the pooler-81 branch July 9, 2018 23:22
smcelmurry added a commit that referenced this pull request Jul 10, 2018
mattkirby pushed a commit that referenced this pull request Jul 10, 2018
* Revert "(POOLER-34) Ship clone request to ready time to metrics (#277)"

This reverts commit a865e6b.

* Revert "(POOLER-81) Add time_remaining information (#276)"

This reverts commit 1910cff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants