Skip to content

Commit

Permalink
Maintenance: Improve stack log
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaefer committed Nov 16, 2024
1 parent 2594ae3 commit b44c552
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Supervisor.stack_stats(stack_uuid) # Retrieves statistics for a sta
Supervisor.update_stack(stack_uuid, params) # Updates an existing stack
Supervisor.delete_stack(stack_uuid) # Deletes a specified stack
Supervisor.control_stack(stack_uuid, command) # Controls (start, stop) a stack
Supervisore.stack_last_log_entry(stack_uuid) # Retrieves the last log entry for a stack
Supervisor.stack_logs(stack_uuid) { block } # Retrieves logs for a stack (Server-sent events)
Supervisor.health_check # Checks the health of the service
```

Expand Down Expand Up @@ -105,6 +107,8 @@ supervisor stacks <subcommand> [options]
| `show` | Shows details of a specified stack. |
| `stats` | Retrieves statistics for a stack. |
| `list` | Lists all stacks in Supervisor. |
| `control` | Controls (start, stop, rest) a stack. |
| `log` | Retrieves log for a stack. |

#### Subcommand Options

Expand Down
8 changes: 4 additions & 4 deletions etc/bash/completion
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ _supervisor_stack_control() {
__supervisor_stacks_completion
}

_supervisor_stack_logs() {
_supervisor_stack_log() {
local cur prev words
_get_comp_words_by_ref -n : cur prev words

Expand All @@ -209,7 +209,7 @@ _supervisor_stacks() {
local cur prev words
_get_comp_words_by_ref -n : cur prev words

local actions="create delete list show stats update control logs"
local actions="create delete list show stats update control log"

local word
for word in "${words[@]}"; do
Expand Down Expand Up @@ -242,8 +242,8 @@ _supervisor_stacks() {
_supervisor_stack_control
return
;;
logs)
_supervisor_stack_logs
log)
_supervisor_stack_log
return
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions lib/supervisor/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require_relative 'app/stacks/stats'
require_relative 'app/stacks/update'
require_relative 'app/stacks/control'
require_relative 'app/stacks/logs'
require_relative 'app/stacks/log'

module Supervisor
module App
Expand All @@ -25,7 +25,7 @@ class Command < Supervisor::App::BaseCommand
subcommand 'update', 'Update a stack', Supervisor::App::Stacks::UpdateCommand
subcommand 'delete', 'Delete a stack', Supervisor::App::Stacks::DeleteCommand
subcommand 'control', 'Control a stack', Supervisor::App::Stacks::ControlCommand
subcommand 'logs', 'Show the logs of a stack', Supervisor::App::Stacks::LogsCommand
subcommand 'log', 'Show the log of a stack', Supervisor::App::Stacks::LogCommand
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Supervisor
module App
module Stacks
class LogsCommand < BaseCommand
class LogCommand < BaseCommand
parameter 'STACK_UUID', 'the UUID of the stack'
option ['--follow'], :flag, 'follow the log output'
option ['--json'], :flag, 'output as JSON'
Expand All @@ -19,15 +19,15 @@ def execute
end
end

log = call(:stack_last_logs_entry, stack_uuid)
log = call(:stack_last_log_entry, stack_uuid)
puts table(log)
end

private

def stream
configure
Supervisor.stack_logs(stack_uuid) do |chunk|
Supervisor.stack_log(stack_uuid) do |chunk|
regexp = Regexp.new('data: (?<data>.*)\n', Regexp::MULTILINE)
match = regexp.match(chunk)

Expand Down
10 changes: 5 additions & 5 deletions lib/supervisor/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ def control_stack(stack_uuid, command)
true
end

def stack_last_logs_entry(stack_uuid)
request(:get, "/stacks/#{stack_uuid}/last_logs_entry")
def stack_last_log_entry(stack_uuid)
request(:get, "/stacks/#{stack_uuid}/log")
end

def stack_logs(stack_uuid, read_timeout: 3600, &)
path = "/stacks/#{stack_uuid}/logs"
def stack_log(stack_uuid, read_timeout: 3600, &)
path = "/stacks/#{stack_uuid}/log"
headers = { Authorization: "Bearer #{@api_key}" }

begin
response = self.class.get("#{@base_uri}#{path}", headers:, stream_body: true, read_timeout:, &)
response = self.class.get("#{@base_uri}#{path}?follow=true", headers:, stream_body: true, read_timeout:, &)
rescue StandardError => e
raise Supervisor::Error, e.message
end
Expand Down

0 comments on commit b44c552

Please sign in to comment.