feat(state): carry channel lifecycle from the Messaging Service to the dashboard
archie-core-8cda.6.8's carrier. The service now records channel lifecycle and has nowhere to put it: /api/channels answered with nothing because webui.Server.Channels had no production source, and reload answered 501 for the same reason. This adds the surface the register decided on, following the split archie-core-ymut established for config snapshots -- a pair of administrative RPCs whose writer is one process and whose reader is the UI -- and wires both ends. Wire and store: PutChannelStatus / ListChannelStatus, with ChannelStatus carrying id, name, state, detail, configured, reload_supported and observed_at. The store holds one row per channel and replaces the reported set, so a channel the reporter no longer mentions is deleted rather than left standing as a stale "running"; an empty report clears the table, because hosting no channels is a fact worth reporting. A row without an id is refused: it could never be replaced or removed by a later report. Writer: the service publishes on every lifecycle transition through a coalescing signal -- a burst of transitions is one write, since a reader only wants the latest state of every channel -- plus a start-up report and a final report after shutdown, so a stopped service leaves the store honest. A failed write is logged and retried on the next signal; the dashboard losing channel state is worth a warning and never worth failing a channel start over. Reader: webui.Server.Channels becomes a source rather than a concrete manager, and webui.RemoteChannelStatus reads the store the way RemoteConfigView reads the config snapshot. A store it cannot reach reports nothing rather than a stale "running", and a state the reader does not recognise is carried through rather than dropped. The contract's own index gains the group in the same change that adds the RPCs -- a surface the grouped table does not list is one nobody finds -- and the count moves to 51. The register records why the surface is the State Store rather than a resource kind, and why reload gets its own surface rather than a field here: reading status must not be able to retrigger an action, a transient request is not distinguishable from state once anything polls it, and it would invert the writer/reader relationship the precedent establishes. Verified: task check exit 0. New coverage: the store's replace-the-set semantics and its refusal of an id-less row, the reader's mapping including an unknown state, and the publisher's start-up, transition and final reports.
This commit is contained in:
23 files changed
+1445
-406
No files matched your search
@@ -418,6 +418,48 @@ func chatChannelConfigured(chat config.ChatConfig) bool {
|
||||
// RemoteConfigView reads the projection the configuration owner published.
|
||||
// The reading process cannot edit it: it has no update path, and the page is
|
||||
// told so rather than offering a control that would 503.
|
||||
// ChannelStatusSource reports the live state of each configured channel.
|
||||
type ChannelStatusSource interface {
|
||||
Snapshot() []status.Status
|
||||
}
|
||||
|
||||
// RemoteChannelStatus reads channel state from the State Store, where the
|
||||
// process hosting the channels publishes it. It is the reader half of the same
|
||||
// split RemoteConfigView serves: the writer is another process and the reader is
|
||||
// this one, so a reader that cannot reach the store reports nothing rather than
|
||||
// inventing a state, and the page shows no channels instead of wrong ones.
|
||||
func RemoteChannelStatus(channels storecontract.ChannelStatusStore) ChannelStatusSource {
|
||||
return remoteChannelStatus{channels: channels}
|
||||
}
|
||||
|
||||
type remoteChannelStatus struct {
|
||||
channels storecontract.ChannelStatusStore
|
||||
}
|
||||
|
||||
func (r remoteChannelStatus) Snapshot() []status.Status {
|
||||
// The handler has no error to return, so a failed read is an empty report.
|
||||
// That is the honest answer: the dashboard must not show a stale "running"
|
||||
// for a channel it cannot currently ask about.
|
||||
rows, err := r.channels.ChannelStatus(context.Background())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]status.Status, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
out = append(out, status.Status{
|
||||
Descriptor: status.Descriptor{
|
||||
ID: row.ID,
|
||||
Name: row.Name,
|
||||
Configured: row.Configured,
|
||||
ReloadSupported: row.ReloadSupported,
|
||||
Detail: row.Detail,
|
||||
},
|
||||
State: status.State(row.State),
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func RemoteConfigView(snapshots storecontract.ConfigSnapshotStore) ConfigViewSource {
|
||||
return func(ctx context.Context) (ConfigView, bool, error) {
|
||||
snapshot, found, err := snapshots.ConfigSnapshot(ctx)
|
||||
|
||||
@@ -513,10 +513,14 @@ func TestHandleChannelsWithoutManagerIsEmpty(t *testing.T) {
|
||||
|
||||
func TestHandleChannelsUsesRuntimeManager(t *testing.T) {
|
||||
srv := newTestServer(t)
|
||||
srv.Channels = status.NewManager([]status.Descriptor{{
|
||||
// Channels is a source rather than a concrete manager now: a process that
|
||||
// hosts channels supplies its own, and the dashboard process supplies a reader
|
||||
// over the State Store. This test drives the first.
|
||||
manager := status.NewManager([]status.Descriptor{{
|
||||
ID: "telegram", Name: "Telegram", Configured: true, ReloadSupported: true,
|
||||
}})
|
||||
srv.Channels.MarkFailed("telegram", "token rejected")
|
||||
manager.MarkFailed("telegram", "token rejected")
|
||||
srv.Channels = manager
|
||||
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/channels", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/channels/status"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
)
|
||||
|
||||
type fakeChannelStatusStore struct {
|
||||
rows []storecontract.ChannelStatus
|
||||
err error
|
||||
}
|
||||
|
||||
func (f fakeChannelStatusStore) PutChannelStatus(context.Context, []storecontract.ChannelStatus) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f fakeChannelStatusStore) ChannelStatus(context.Context) ([]storecontract.ChannelStatus, error) {
|
||||
return f.rows, f.err
|
||||
}
|
||||
|
||||
// TestRemoteChannelStatusMapsReportedState: the dashboard process reads channel
|
||||
// state another process published, so the mapping is the whole of its
|
||||
// responsibility -- including carrying an unknown state through rather than
|
||||
// dropping the channel, because a reader that hides a channel it does not
|
||||
// recognise shows a healthy page for a channel that is down.
|
||||
func TestRemoteChannelStatusMapsReportedState(t *testing.T) {
|
||||
source := RemoteChannelStatus(fakeChannelStatusStore{rows: []storecontract.ChannelStatus{
|
||||
{ID: "telegram", Name: "telegram", State: "running", Configured: true, ReloadSupported: true},
|
||||
{ID: "webhook", Name: "webhook", State: "failed", Detail: "listen: address in use", Configured: true},
|
||||
{ID: "email", Name: "email", State: "invented-later", Configured: true},
|
||||
}})
|
||||
|
||||
snapshot := source.Snapshot()
|
||||
if len(snapshot) != 3 {
|
||||
t.Fatalf("Snapshot() = %+v, want all three reported channels", snapshot)
|
||||
}
|
||||
if snapshot[0].State != status.StateRunning || !snapshot[0].ReloadSupported {
|
||||
t.Errorf("telegram = %+v, want running and reload-capable", snapshot[0])
|
||||
}
|
||||
if snapshot[1].State != status.StateFailed || snapshot[1].Detail == "" {
|
||||
t.Errorf("webhook = %+v, want the failure and its reason", snapshot[1])
|
||||
}
|
||||
if snapshot[2].State != status.State("invented-later") {
|
||||
t.Errorf("email state = %q, want the reported value carried through", snapshot[2].State)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRemoteChannelStatusReportsNothingWhenTheStoreFails: the handler has no
|
||||
// error to return, and the honest answer is an empty report. Showing a cached or
|
||||
// assumed state for a channel the dashboard cannot currently ask about is how a
|
||||
// dead channel keeps looking alive.
|
||||
func TestRemoteChannelStatusReportsNothingWhenTheStoreFails(t *testing.T) {
|
||||
source := RemoteChannelStatus(fakeChannelStatusStore{err: errors.New("state store unreachable")})
|
||||
if got := source.Snapshot(); len(got) != 0 {
|
||||
t.Fatalf("Snapshot() = %+v, want nothing when the store cannot answer", got)
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/channels/status"
|
||||
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/health"
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
@@ -54,10 +53,11 @@ type Server struct {
|
||||
// of them is about configuration.
|
||||
TaskLogs TaskLogSource
|
||||
|
||||
// Channels reports actual adapter lifecycle, independently of configuration
|
||||
// presence. Nil preserves the configuration-only fallback for tests and
|
||||
// minimal embedding.
|
||||
Channels *status.Manager
|
||||
// Channels reports actual adapter lifecycle, independently of configuration.
|
||||
// A process that hosts channels satisfies it from its own manager; the
|
||||
// dashboard process satisfies it by reading the State Store, where the
|
||||
// hosting process publishes (webui.RemoteChannelStatus).
|
||||
Channels ChannelStatusSource
|
||||
|
||||
// ReloadChannel invokes a channel-specific reload seam. Only adapters that
|
||||
// explicitly support reload are wired here; nil means reload is unavailable.
|
||||
|
||||
Reference in new issue
Block a user