fix(agentworker): stop reporting task worker presence (#1807)
This commit is contained in:
4 files changed
+4
-57
No files matched your search
@@ -3,25 +3,18 @@ package agentworker
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/samcharles93/archie-core/internal/agentexec"
|
"github.com/samcharles93/archie-core/internal/agentexec"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/health"
|
|
||||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
|
||||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
||||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||||
"github.com/samcharles93/archie-core/internal/infrastructure/agentboot"
|
"github.com/samcharles93/archie-core/internal/infrastructure/agentboot"
|
||||||
"github.com/samcharles93/archie-core/internal/infrastructure/agentgit"
|
"github.com/samcharles93/archie-core/internal/infrastructure/agentgit"
|
||||||
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
|
agentnats "github.com/samcharles93/archie-core/internal/infrastructure/agenttransport/nats"
|
||||||
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
|
"github.com/samcharles93/archie-core/internal/infrastructure/egress"
|
||||||
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
|
|
||||||
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
|
"github.com/samcharles93/archie-core/internal/infrastructure/workflowsteps"
|
||||||
"github.com/samcharles93/archie-core/internal/installtype"
|
|
||||||
"github.com/samcharles93/archie-core/internal/logging"
|
"github.com/samcharles93/archie-core/internal/logging"
|
||||||
"github.com/samcharles93/archie-core/internal/storage"
|
"github.com/samcharles93/archie-core/internal/storage"
|
||||||
"github.com/samcharles93/archie-core/internal/taskrun"
|
"github.com/samcharles93/archie-core/internal/taskrun"
|
||||||
@@ -67,8 +60,6 @@ type workerTransport interface {
|
|||||||
Close()
|
Close()
|
||||||
LogPublisher() agentexec.LogPublisher
|
LogPublisher() agentexec.LogPublisher
|
||||||
SubscribeTasks(context.Context, int64, agentnats.TaskHandler, *slog.Logger) (agentnats.Subscription, error)
|
SubscribeTasks(context.Context, int64, agentnats.TaskHandler, *slog.Logger) (agentnats.Subscription, error)
|
||||||
PutPresence(context.Context, storecontract.Presence) error
|
|
||||||
BrokerReady() bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type workerDependencies struct {
|
type workerDependencies struct {
|
||||||
@@ -174,13 +165,6 @@ func run(ctx context.Context, settings Settings, log *slog.Logger, dependencies
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
registry := health.NewRegistry(readiness.NewContractProbe("nats", 0, func(context.Context) error {
|
|
||||||
if !transport.BrokerReady() {
|
|
||||||
return errors.New("broker disconnected")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}))
|
|
||||||
go presence.Run(ctx, presence.Agent, presence.Build{InstanceID: strconv.FormatInt(taskID, 10), Version: Version(), InstallType: installtype.Type()}, transport, registry, log)
|
|
||||||
log.InfoContext(ctx, "archie-agent ready", "nats", settings.NATSURL)
|
log.InfoContext(ctx, "archie-agent ready", "nats", settings.NATSURL)
|
||||||
dependencies.wait(ctx, log)
|
dependencies.wait(ctx, log)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"go.opentelemetry.io/otel/propagation"
|
"go.opentelemetry.io/otel/propagation"
|
||||||
|
|
||||||
"github.com/samcharles93/archie-core/internal/agentexec"
|
"github.com/samcharles93/archie-core/internal/agentexec"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
||||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||||
"github.com/samcharles93/archie-core/internal/events"
|
"github.com/samcharles93/archie-core/internal/events"
|
||||||
@@ -377,12 +376,3 @@ func (*Transport) respondTask(msg *natsio.Msg, response *taskrun.Response, runEr
|
|||||||
log.Error("taskrun respond failed", "err", err)
|
log.Error("taskrun respond failed", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PutPresence publishes the worker's task-scoped record.
|
|
||||||
func (t *Transport) PutPresence(ctx context.Context, record storecontract.Presence) error {
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
return t.state.PutPresence(ctx, record)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Transport) BrokerReady() bool { return t.conn.IsConnected() }
|
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
@@ -18,7 +17,6 @@ import (
|
|||||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/presence"
|
|
||||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||||
"github.com/samcharles93/archie-core/internal/events"
|
"github.com/samcharles93/archie-core/internal/events"
|
||||||
@@ -89,17 +87,6 @@ func authorizesTaskScopedCall(fullMethod string, req any, taskID int64) bool {
|
|||||||
// taskScopedTargets maps each RPC a task grant may call to the task ID its
|
// taskScopedTargets maps each RPC a task grant may call to the task ID its
|
||||||
// request targets.
|
// request targets.
|
||||||
var taskScopedTargets = map[string]func(any) int64{
|
var taskScopedTargets = map[string]func(any) int64{
|
||||||
pb.StatusService_PutPresence_FullMethodName: func(req any) int64 {
|
|
||||||
r, ok := req.(*pb.PutPresenceRequest)
|
|
||||||
if !ok || r.Presence == nil || r.Presence.Service != presence.Agent {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
id, err := strconv.ParseInt(r.Presence.InstanceId, 10, 64)
|
|
||||||
if err != nil || id <= 0 || strconv.FormatInt(id, 10) != r.Presence.InstanceId {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return id
|
|
||||||
},
|
|
||||||
pb.TaskService_Update_FullMethodName: func(req any) int64 {
|
pb.TaskService_Update_FullMethodName: func(req any) int64 {
|
||||||
r, ok := req.(*pb.UpdateRequest)
|
r, ok := req.(*pb.UpdateRequest)
|
||||||
if !ok || r.Task == nil {
|
if !ok || r.Task == nil {
|
||||||
|
|||||||
@@ -6,23 +6,9 @@ import (
|
|||||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWorkerPresenceAuthority(t *testing.T) {
|
func TestTaskGrantRejectsPutPresence(t *testing.T) {
|
||||||
for _, tt := range []struct {
|
req := &pb.PutPresenceRequest{Presence: &pb.Presence{Service: "archie-agent", InstanceId: "7"}}
|
||||||
name, service, instance string
|
if authorizesTaskScopedCall(pb.StatusService_PutPresence_FullMethodName, req, 7) {
|
||||||
allowed bool
|
t.Fatal("task grant authorised PutPresence")
|
||||||
}{
|
|
||||||
{"own task", "archie-agent", "7", true},
|
|
||||||
{"another task", "archie-agent", "8", false},
|
|
||||||
{"daemon", "archied", "7", false},
|
|
||||||
{"broker", "nats", "7", false},
|
|
||||||
{"noncanonical task", "archie-agent", "007", false},
|
|
||||||
{"no task", "archie-agent", "", false},
|
|
||||||
} {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
req := &pb.PutPresenceRequest{Presence: &pb.Presence{Service: tt.service, InstanceId: tt.instance}}
|
|
||||||
if got := authorizesTaskScopedCall(pb.StatusService_PutPresence_FullMethodName, req, 7); got != tt.allowed {
|
|
||||||
t.Fatalf("authorized = %v, want %v", got, tt.allowed)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user