Skip to content

Commit 8907115

Browse files
Bound Docker inspection with timeout
1 parent 1202741 commit 8907115

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎internal/docker/reader.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"time"
78

89
"github.com/docker/docker/api/types"
910
client "github.com/docker/docker/client"
@@ -42,6 +43,8 @@ func NewReader() (*Reader, error) {
4243
return &Reader{client: c}, nil
4344
}
4445
func (r *Reader) Snapshot(ctx context.Context) Snapshot {
46+
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
47+
defer cancel()
4548
out := Snapshot{}
4649
if _, err := r.client.Ping(ctx); err != nil {
4750
out.Message = fmt.Sprintf("Docker indisponível: %v", err)

‎web/src/views/Infrastructure.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<script setup lang="ts">import {onMounted,ref} from 'vue';const data=ref<any>({});onMounted(async()=>data.value=await (await fetch('/api/v1/infrastructure')).json())</script><template><div class="hero"><div><p class="kicker">OBSERVABILITY</p><h1>Infrastructure</h1><p class="muted">A clear view of the host running StackHost.</p></div></div><div class="status"><span class="dot"></span><div><strong>Docker engine</strong><p>{{data.docker?.message||'Checking connection...'}}</p></div><span class="pill">Unavailable</span></div><div class="empty"><h2>Swarm is not initialized</h2><p>When Docker Swarm is available, nodes and services will appear here.</p></div></template>
1+
<script setup lang="ts">import {onMounted,ref} from 'vue';const data=ref<any>({});onMounted(async()=>data.value=await (await fetch('/api/v1/infrastructure')).json())</script><template><div class="hero"><div><p class="kicker">OBSERVABILITY</p><h1>Infrastructure</h1><p class="muted">A clear view of the host running StackHost.</p></div></div><div class="status"><span class="dot"></span><div><strong>{{data.available?'Docker engine connected':'Docker engine unavailable'}}</strong><p>{{data.available?`Docker ${data.engine_version} · ${data.running}/${data.containers} containers running`:data.message||'Docker connection needs attention'}}</p></div><span class="pill">{{data.available?'Available':'Unavailable'}}</span></div><div class="empty"><h2>{{data.swarm?.active?'Swarm cluster':'Swarm is not initialized'}}</h2><p>{{data.swarm?.active?`${data.swarm.nodes} nodes · ${data.swarm.services} services`:'When Docker Swarm is available, nodes and services will appear here.'}}</p></div></template>

0 commit comments

Comments
 (0)