feat(controlplane): field-level sys_audit table, audit view on settings pages, whole-task time limit
This commit is contained in:
1 parent
49d7527f1c
commit
8fea8e8686
43 files changed
+1176
-174
No files matched your search
@@ -202,12 +202,16 @@ func (b *boot) applyWorkflowExecutionSettings(ctx context.Context, settings work
|
||||
b.cfgHolder.Set(candidate.cfg)
|
||||
b.applyStatus.Report(ctx, controlplane.WorkflowExecutionSettingsKind, version, nil)
|
||||
b.log.Info("workflow execution settings applied", "version", version)
|
||||
if limit, uptime := settings.MaxTaskRuntime, candidate.cfg.Containers.MaxUptime.Std(); uptime > 0 && (limit <= 0 || limit > uptime) {
|
||||
b.log.Warn("containers.max_uptime is shorter than the task time limit; the container is killed first", "max_uptime", uptime, "max_task_runtime", limit)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyExecutionBudgets(cfg *config.Config, settings workflow.ExecutionSettings) {
|
||||
cfg.Budgets = config.Budgets{
|
||||
MaxSteps: settings.MaxModelToolSteps, WallClock: config.Duration(settings.MaxRuntime), GateMaxFailures: settings.MaxConsecutiveGateFailures,
|
||||
TaskWallClock: config.Duration(settings.MaxTaskRuntime),
|
||||
}
|
||||
for i := range cfg.Identities {
|
||||
cfg.Identities[i].Budgets = cfg.Budgets
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
// limits stayed" and a test that asserts "the update was applied" cannot
|
||||
// disagree about what "running" means.
|
||||
var (
|
||||
bootedSettings = workflow.ExecutionSettings{MaxModelToolSteps: 10, MaxRuntime: 5 * time.Minute, MaxConsecutiveGateFailures: 3}
|
||||
bootedSettings = workflow.ExecutionSettings{MaxModelToolSteps: 10, MaxRuntime: 5 * time.Minute, MaxConsecutiveGateFailures: 3, MaxTaskRuntime: 4 * time.Hour}
|
||||
bootedDocument = `{"max_model_tool_steps": 10, "max_runtime_seconds": 300, "max_consecutive_gate_failures": 3}`
|
||||
)
|
||||
|
||||
@@ -124,6 +124,10 @@ func (*settingsWatchStub) History(context.Context, *pb.HistoryRequest, ...grpc.C
|
||||
panic("unexpected History")
|
||||
}
|
||||
|
||||
func (*settingsWatchStub) Audit(context.Context, *pb.AuditRequest, ...grpc.CallOption) (*pb.AuditResponse, error) {
|
||||
return &pb.AuditResponse{}, nil
|
||||
}
|
||||
|
||||
func (*settingsWatchStub) Command(context.Context, *pb.CommandRequest, ...grpc.CallOption) (*pb.CommandResponse, error) {
|
||||
panic("unexpected Command")
|
||||
}
|
||||
@@ -297,7 +301,7 @@ func TestLiveExecutionSettingsRefusalIsReportedThroughTheClient(t *testing.T) {
|
||||
{
|
||||
name: "an update the process can run is applied",
|
||||
document: `{"max_model_tool_steps": 25, "max_runtime_seconds": 3600, "max_consecutive_gate_failures": 4}`,
|
||||
wantRunning: workflow.ExecutionSettings{MaxModelToolSteps: 25, MaxRuntime: time.Hour, MaxConsecutiveGateFailures: 4},
|
||||
wantRunning: workflow.ExecutionSettings{MaxModelToolSteps: 25, MaxRuntime: time.Hour, MaxConsecutiveGateFailures: 4, MaxTaskRuntime: 4 * time.Hour},
|
||||
wantVersion: 2,
|
||||
},
|
||||
{
|
||||
@@ -353,5 +357,6 @@ func budgetsFor(settings workflow.ExecutionSettings) config.Budgets {
|
||||
MaxSteps: settings.MaxModelToolSteps,
|
||||
WallClock: config.Duration(settings.MaxRuntime),
|
||||
GateMaxFailures: settings.MaxConsecutiveGateFailures,
|
||||
TaskWallClock: config.Duration(settings.MaxTaskRuntime),
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,10 @@ func (*controlPlaneStub) History(context.Context, *pb.HistoryRequest, ...grpc.Ca
|
||||
panic("unexpected History")
|
||||
}
|
||||
|
||||
func (*controlPlaneStub) Audit(context.Context, *pb.AuditRequest, ...grpc.CallOption) (*pb.AuditResponse, error) {
|
||||
return &pb.AuditResponse{}, nil
|
||||
}
|
||||
|
||||
func (*controlPlaneStub) Command(context.Context, *pb.CommandRequest, ...grpc.CallOption) (*pb.CommandResponse, error) {
|
||||
panic("unexpected Command")
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ const documentedStaleWindow = 90 * time.Second
|
||||
// fileConfig()'s [budgets] on all three fields, so a process that comes back on
|
||||
// any file value is detectably not on the stored one.
|
||||
var restartEditedSettings = workflow.ExecutionSettings{
|
||||
MaxModelToolSteps: 40, MaxRuntime: 10 * time.Minute, MaxConsecutiveGateFailures: 2,
|
||||
MaxModelToolSteps: 40, MaxRuntime: 10 * time.Minute, MaxConsecutiveGateFailures: 2, MaxTaskRuntime: 4 * time.Hour,
|
||||
}
|
||||
|
||||
// controlPlaneRestartFixture is a real State Store for the restart test: the
|
||||
@@ -181,7 +181,7 @@ func TestRestartKeepsADatabaseOwnedSettingsChange(t *testing.T) {
|
||||
firstCtx, stopFirst := context.WithCancel(t.Context())
|
||||
first := startRestartProcess(firstCtx, t, fixture.dial(t))
|
||||
stopFirst()
|
||||
if got := first.cfgHolder.Get().Budgets; got != budgetsFor(workflow.ExecutionSettings{MaxModelToolSteps: 1, MaxRuntime: time.Minute}) {
|
||||
if got := first.cfgHolder.Get().Budgets; got != budgetsFor(workflow.ExecutionSettings{MaxModelToolSteps: 1, MaxRuntime: time.Minute, MaxTaskRuntime: 4 * time.Hour}) {
|
||||
t.Fatalf("first process budgets = %+v, want the seeded file budgets", got)
|
||||
}
|
||||
if got := first.cfgHolder.Get().PluginDir; got != fileConfig().PluginDir {
|
||||
@@ -191,7 +191,7 @@ func TestRestartKeepsADatabaseOwnedSettingsChange(t *testing.T) {
|
||||
// 1. The dashboard writes the change. Its handler, not this test, supplies
|
||||
// the attribution: webAudit attributes to identity.SystemID.
|
||||
expectedVersion := int64(1)
|
||||
executionSettingsDocument := []byte(`{"max_model_tool_steps":40,"max_runtime_seconds":600,"max_consecutive_gate_failures":2}`)
|
||||
executionSettingsDocument := []byte(`{"max_model_tool_steps":40,"max_runtime_seconds":600,"max_consecutive_gate_failures":2,"max_task_runtime_seconds":14400}`)
|
||||
if version := dashboardReplace(t, dashboard, controlplane.WorkflowExecutionSettingsKind, executionSettingsDocument, expectedVersion); version != 2 {
|
||||
t.Fatalf("workflow execution settings after edit = version %d, want 2", version)
|
||||
}
|
||||
@@ -334,6 +334,7 @@ func decodeExecutionSettingsRevision(t *testing.T, value json.RawMessage) workfl
|
||||
MaxModelToolSteps int `json:"max_model_tool_steps"`
|
||||
MaxRuntimeSeconds int64 `json:"max_runtime_seconds"`
|
||||
MaxConsecutiveGateFailures int `json:"max_consecutive_gate_failures"`
|
||||
MaxTaskRuntimeSeconds int64 `json:"max_task_runtime_seconds"`
|
||||
}
|
||||
if err := json.Unmarshal(value, &document); err != nil {
|
||||
t.Fatalf("decode revision value: %v (%s)", err, value)
|
||||
@@ -342,6 +343,7 @@ func decodeExecutionSettingsRevision(t *testing.T, value json.RawMessage) workfl
|
||||
MaxModelToolSteps: document.MaxModelToolSteps,
|
||||
MaxRuntime: time.Duration(document.MaxRuntimeSeconds) * time.Second,
|
||||
MaxConsecutiveGateFailures: document.MaxConsecutiveGateFailures,
|
||||
MaxTaskRuntime: time.Duration(document.MaxTaskRuntimeSeconds) * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,10 @@ func (*watchStub) History(context.Context, *pb.HistoryRequest, ...grpc.CallOptio
|
||||
panic("unexpected History")
|
||||
}
|
||||
|
||||
func (*watchStub) Audit(context.Context, *pb.AuditRequest, ...grpc.CallOption) (*pb.AuditResponse, error) {
|
||||
return &pb.AuditResponse{}, nil
|
||||
}
|
||||
|
||||
func (*watchStub) Command(context.Context, *pb.CommandRequest, ...grpc.CallOption) (*pb.CommandResponse, error) {
|
||||
panic("unexpected Command")
|
||||
}
|
||||
@@ -177,7 +181,7 @@ func (s *scriptStream) Recv() (*pb.WatchResponse, error) {
|
||||
func TestWorkflowExecutionSettingsWatchIsReEstablishedAfterTheStreamEnds(t *testing.T) {
|
||||
// 25 steps and an hour, so an applied update is unmistakably not the value
|
||||
// the daemon booted with.
|
||||
updated := workflow.ExecutionSettings{MaxModelToolSteps: 25, MaxRuntime: time.Hour, MaxConsecutiveGateFailures: 4}
|
||||
updated := workflow.ExecutionSettings{MaxModelToolSteps: 25, MaxRuntime: time.Hour, MaxConsecutiveGateFailures: 4, MaxTaskRuntime: 4 * time.Hour}
|
||||
updatedDocument := `{"max_model_tool_steps": 25, "max_runtime_seconds": 3600, "max_consecutive_gate_failures": 4}`
|
||||
|
||||
for _, tt := range watchStreamEnds {
|
||||
@@ -358,7 +362,7 @@ func TestWatchTransportFailureDoesNotOverwriteARefusal(t *testing.T) {
|
||||
// already runs, and reported a second time.
|
||||
func TestWatchReconnectDoesNotReplayWhatItAlreadyApplied(t *testing.T) {
|
||||
t.Parallel()
|
||||
updated := workflow.ExecutionSettings{MaxModelToolSteps: 25, MaxRuntime: time.Hour, MaxConsecutiveGateFailures: 4}
|
||||
updated := workflow.ExecutionSettings{MaxModelToolSteps: 25, MaxRuntime: time.Hour, MaxConsecutiveGateFailures: 4, MaxTaskRuntime: 4 * time.Hour}
|
||||
updatedDocument := `{"max_model_tool_steps": 25, "max_runtime_seconds": 3600, "max_consecutive_gate_failures": 4}`
|
||||
b, recorder := newLiveApplyBoot(t, fileConfig())
|
||||
stub := &watchStub{
|
||||
@@ -1089,6 +1093,10 @@ func (busyWatch) History(context.Context, *pb.HistoryRequest, ...grpc.CallOption
|
||||
panic("unexpected History")
|
||||
}
|
||||
|
||||
func (busyWatch) Audit(context.Context, *pb.AuditRequest, ...grpc.CallOption) (*pb.AuditResponse, error) {
|
||||
return &pb.AuditResponse{}, nil
|
||||
}
|
||||
|
||||
func (busyWatch) Command(context.Context, *pb.CommandRequest, ...grpc.CallOption) (*pb.CommandResponse, error) {
|
||||
panic("unexpected Command")
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ var (
|
||||
type ResourceStore interface {
|
||||
Resource(context.Context, string) (storecontract.Resource, error)
|
||||
ResourceHistory(context.Context, string, int) ([]storecontract.Resource, error)
|
||||
Audit(ctx context.Context, table string, keys []string, limit int) ([]storecontract.AuditEntry, error)
|
||||
PutResource(context.Context, storecontract.ResourceWrite) (storecontract.Resource, error)
|
||||
}
|
||||
|
||||
@@ -109,6 +110,33 @@ func (s *Server) History(ctx context.Context, request *pb.HistoryRequest) (*pb.H
|
||||
return &pb.HistoryResponse{Revisions: out}, nil
|
||||
}
|
||||
|
||||
// defaultAuditLimit caps an audit read: a page shows recent changes, not the
|
||||
// whole trail.
|
||||
const defaultAuditLimit = 500
|
||||
|
||||
func (s *Server) Audit(ctx context.Context, request *pb.AuditRequest) (*pb.AuditResponse, error) {
|
||||
if request.GetTable() == "" || len(request.GetRecordKeys()) == 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "table and record keys are required")
|
||||
}
|
||||
limit := int(request.GetLimit())
|
||||
if limit <= 0 || limit > defaultAuditLimit {
|
||||
limit = defaultAuditLimit
|
||||
}
|
||||
entries, err := s.store.Audit(ctx, request.GetTable(), request.GetRecordKeys(), limit)
|
||||
if err != nil {
|
||||
return nil, mapError(err)
|
||||
}
|
||||
out := make([]*pb.AuditEntry, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
out = append(out, &pb.AuditEntry{
|
||||
Id: entry.ID, Table: entry.Table, RecordKey: entry.RecordKey, Field: entry.Field,
|
||||
OldValueJson: entry.OldValue, NewValueJson: entry.NewValue, Version: entry.Version,
|
||||
Actor: entry.Actor, Source: entry.Source, RequestId: entry.RequestID, At: timestamp(entry.At),
|
||||
})
|
||||
}
|
||||
return &pb.AuditResponse{Entries: out}, nil
|
||||
}
|
||||
|
||||
func (s *Server) Command(ctx context.Context, request *pb.CommandRequest) (*pb.CommandResponse, error) {
|
||||
definition, ok := s.definitions[request.GetKind()]
|
||||
if !ok || request.GetCommand() != "replace" {
|
||||
|
||||
@@ -39,6 +39,10 @@ func (scriptedWatchClient) History(context.Context, *pb.HistoryRequest, ...grpc.
|
||||
panic("History is not part of the watch path")
|
||||
}
|
||||
|
||||
func (scriptedWatchClient) Audit(context.Context, *pb.AuditRequest, ...grpc.CallOption) (*pb.AuditResponse, error) {
|
||||
return &pb.AuditResponse{}, nil
|
||||
}
|
||||
|
||||
func (scriptedWatchClient) Command(context.Context, *pb.CommandRequest, ...grpc.CallOption) (*pb.CommandResponse, error) {
|
||||
panic("Command is not part of the watch path")
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ func (*runtimeConfigClient) History(context.Context, *pb.HistoryRequest, ...grpc
|
||||
panic("unexpected History")
|
||||
}
|
||||
|
||||
func (*runtimeConfigClient) Audit(context.Context, *pb.AuditRequest, ...grpc.CallOption) (*pb.AuditResponse, error) {
|
||||
return &pb.AuditResponse{}, nil
|
||||
}
|
||||
|
||||
func (*runtimeConfigClient) Command(context.Context, *pb.CommandRequest, ...grpc.CallOption) (*pb.CommandResponse, error) {
|
||||
panic("unexpected Command")
|
||||
}
|
||||
|
||||
@@ -320,6 +320,10 @@ func (c *definitionsClient) History(context.Context, *pb.HistoryRequest, ...grpc
|
||||
panic("History is not part of the workflow-definitions path")
|
||||
}
|
||||
|
||||
func (c *definitionsClient) Audit(context.Context, *pb.AuditRequest, ...grpc.CallOption) (*pb.AuditResponse, error) {
|
||||
return &pb.AuditResponse{}, nil
|
||||
}
|
||||
|
||||
func (c *definitionsClient) Command(_ context.Context, request *pb.CommandRequest, _ ...grpc.CallOption) (*pb.CommandResponse, error) {
|
||||
c.command = request
|
||||
return &pb.CommandResponse{Resource: &pb.Resource{Version: 5}}, nil
|
||||
|
||||
@@ -14,10 +14,17 @@ import (
|
||||
|
||||
const WorkflowExecutionSettingsKind = "workflow-execution-settings"
|
||||
|
||||
// defaultTaskRuntime bounds a task run when the stored settings predate the
|
||||
// limit.
|
||||
const defaultTaskRuntime = 4 * time.Hour
|
||||
|
||||
type executionSettingsDocument struct {
|
||||
MaxModelToolSteps int `json:"max_model_tool_steps"`
|
||||
MaxRuntimeSeconds int64 `json:"max_runtime_seconds"`
|
||||
MaxRuntimeSeconds int64 `json:"max_runtime_seconds" title:"Max seconds per agent call" doc:"Limit for one agent call inside a stage. 0 disables it."`
|
||||
MaxConsecutiveGateFailures int `json:"max_consecutive_gate_failures"`
|
||||
// MaxTaskRuntimeSeconds is a pointer so a document stored before the
|
||||
// field existed reads as the default, while an explicit 0 disables it.
|
||||
MaxTaskRuntimeSeconds *int64 `json:"max_task_runtime_seconds" title:"Max task runtime seconds" doc:"Limit for a whole task run; the task is parked when it passes. 0 disables it."`
|
||||
}
|
||||
|
||||
// ImportWorkflowExecutionSettings preserves the focused bootstrap API for callers
|
||||
@@ -46,14 +53,18 @@ func workflowDefinition() Definition {
|
||||
return Definition{
|
||||
Kind: WorkflowExecutionSettingsKind, Title: "Workflow execution settings", ApplyMode: "live", Document: executionSettingsDocument{},
|
||||
Seed: func(cfg config.Config) any {
|
||||
return executionSettingsDocument{cfg.Budgets.MaxSteps, int64(time.Duration(cfg.Budgets.WallClock) / time.Second), cfg.Budgets.GateMaxFailures}
|
||||
taskRuntime := time.Duration(cfg.Budgets.TaskWallClock)
|
||||
if taskRuntime == 0 {
|
||||
taskRuntime = defaultTaskRuntime
|
||||
}
|
||||
return executionSettingsDocument{cfg.Budgets.MaxSteps, int64(time.Duration(cfg.Budgets.WallClock) / time.Second), cfg.Budgets.GateMaxFailures, new(int64(taskRuntime / time.Second))}
|
||||
},
|
||||
Validate: func(input []byte) error { _, err := decodeSettings(input); return err },
|
||||
}
|
||||
}
|
||||
|
||||
func encodeSettings(s workflow.ExecutionSettings) ([]byte, error) {
|
||||
return json.Marshal(executionSettingsDocument{s.MaxModelToolSteps, int64(s.MaxRuntime / time.Second), s.MaxConsecutiveGateFailures})
|
||||
return json.Marshal(executionSettingsDocument{s.MaxModelToolSteps, int64(s.MaxRuntime / time.Second), s.MaxConsecutiveGateFailures, new(int64(s.MaxTaskRuntime / time.Second))})
|
||||
}
|
||||
|
||||
func decodeSettings(value []byte) (workflow.ExecutionSettings, error) {
|
||||
@@ -61,7 +72,11 @@ func decodeSettings(value []byte) (workflow.ExecutionSettings, error) {
|
||||
if err := json.Unmarshal(value, &document); err != nil {
|
||||
return workflow.ExecutionSettings{}, fmt.Errorf("%w: invalid JSON: %w", ErrValidation, err)
|
||||
}
|
||||
settings := workflow.ExecutionSettings{MaxModelToolSteps: document.MaxModelToolSteps, MaxRuntime: time.Duration(document.MaxRuntimeSeconds) * time.Second, MaxConsecutiveGateFailures: document.MaxConsecutiveGateFailures}
|
||||
taskRuntime := defaultTaskRuntime
|
||||
if document.MaxTaskRuntimeSeconds != nil {
|
||||
taskRuntime = time.Duration(*document.MaxTaskRuntimeSeconds) * time.Second
|
||||
}
|
||||
settings := workflow.ExecutionSettings{MaxModelToolSteps: document.MaxModelToolSteps, MaxRuntime: time.Duration(document.MaxRuntimeSeconds) * time.Second, MaxConsecutiveGateFailures: document.MaxConsecutiveGateFailures, MaxTaskRuntime: taskRuntime}
|
||||
if err := settings.Validate(); err != nil {
|
||||
return workflow.ExecutionSettings{}, fmt.Errorf("%w: %w", ErrValidation, err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package controlplane
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWorkflowSettingsTaskRuntime(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
value string
|
||||
want time.Duration
|
||||
}{
|
||||
{"stored before the limit existed", `{"max_model_tool_steps":90,"max_runtime_seconds":3600,"max_consecutive_gate_failures":5}`, defaultTaskRuntime},
|
||||
{"explicitly disabled", `{"max_task_runtime_seconds":0}`, 0},
|
||||
{"set", `{"max_task_runtime_seconds":7200}`, 2 * time.Hour},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
settings, err := decodeSettings([]byte(tc.value))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if settings.MaxTaskRuntime != tc.want {
|
||||
t.Fatalf("MaxTaskRuntime = %s, want %s", settings.MaxTaskRuntime, tc.want)
|
||||
}
|
||||
encoded, err := encodeSettings(settings)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
again, err := decodeSettings(encoded)
|
||||
if err != nil || again.MaxTaskRuntime != tc.want {
|
||||
t.Fatalf("round trip = %s, %v; want %s", again.MaxTaskRuntime, err, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -167,11 +167,13 @@ func (r Repo) EffectiveMaxRetries(global int) int {
|
||||
return global
|
||||
}
|
||||
|
||||
// Budgets bound every agent stage. Zero disables a limit.
|
||||
// Budgets bound every agent stage, and TaskWallClock the whole task run. Zero
|
||||
// disables a limit.
|
||||
type Budgets struct {
|
||||
MaxSteps int `toml:"max_steps" json:"max_steps" yaml:"max_steps"`
|
||||
WallClock Duration `toml:"wall_clock" json:"wall_clock" yaml:"wall_clock"`
|
||||
GateMaxFailures int `toml:"gate_max_failures" json:"gate_max_failures" yaml:"gate_max_failures"`
|
||||
TaskWallClock Duration `toml:"task_wall_clock" json:"task_wall_clock" yaml:"task_wall_clock"`
|
||||
}
|
||||
|
||||
// Provider configures one LLM provider for the runtime catalog.
|
||||
|
||||
@@ -547,6 +547,238 @@ func (x *HistoryResponse) GetRevisions() []*Revision {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AuditEntry is one changed field of one record. Old and new values are JSON;
|
||||
// an absent side is empty.
|
||||
type AuditEntry struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Table string `protobuf:"bytes,2,opt,name=table,proto3" json:"table,omitempty"`
|
||||
RecordKey string `protobuf:"bytes,3,opt,name=record_key,json=recordKey,proto3" json:"record_key,omitempty"`
|
||||
Field string `protobuf:"bytes,4,opt,name=field,proto3" json:"field,omitempty"`
|
||||
OldValueJson []byte `protobuf:"bytes,5,opt,name=old_value_json,json=oldValueJson,proto3" json:"old_value_json,omitempty"`
|
||||
NewValueJson []byte `protobuf:"bytes,6,opt,name=new_value_json,json=newValueJson,proto3" json:"new_value_json,omitempty"`
|
||||
Version int64 `protobuf:"varint,7,opt,name=version,proto3" json:"version,omitempty"`
|
||||
Actor string `protobuf:"bytes,8,opt,name=actor,proto3" json:"actor,omitempty"`
|
||||
Source string `protobuf:"bytes,9,opt,name=source,proto3" json:"source,omitempty"`
|
||||
RequestId string `protobuf:"bytes,10,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"`
|
||||
At *timestamppb.Timestamp `protobuf:"bytes,11,opt,name=at,proto3" json:"at,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *AuditEntry) Reset() {
|
||||
*x = AuditEntry{}
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[9]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *AuditEntry) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*AuditEntry) ProtoMessage() {}
|
||||
|
||||
func (x *AuditEntry) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[9]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use AuditEntry.ProtoReflect.Descriptor instead.
|
||||
func (*AuditEntry) Descriptor() ([]byte, []int) {
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{9}
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetId() int64 {
|
||||
if x != nil {
|
||||
return x.Id
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetTable() string {
|
||||
if x != nil {
|
||||
return x.Table
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetRecordKey() string {
|
||||
if x != nil {
|
||||
return x.RecordKey
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetField() string {
|
||||
if x != nil {
|
||||
return x.Field
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetOldValueJson() []byte {
|
||||
if x != nil {
|
||||
return x.OldValueJson
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetNewValueJson() []byte {
|
||||
if x != nil {
|
||||
return x.NewValueJson
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetVersion() int64 {
|
||||
if x != nil {
|
||||
return x.Version
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetActor() string {
|
||||
if x != nil {
|
||||
return x.Actor
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetSource() string {
|
||||
if x != nil {
|
||||
return x.Source
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetRequestId() string {
|
||||
if x != nil {
|
||||
return x.RequestId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AuditEntry) GetAt() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.At
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AuditRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Table string `protobuf:"bytes,1,opt,name=table,proto3" json:"table,omitempty"`
|
||||
RecordKeys []string `protobuf:"bytes,2,rep,name=record_keys,json=recordKeys,proto3" json:"record_keys,omitempty"`
|
||||
// Limit caps the entries returned, newest first. Zero means the server's
|
||||
// own default.
|
||||
Limit int32 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *AuditRequest) Reset() {
|
||||
*x = AuditRequest{}
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[10]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *AuditRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*AuditRequest) ProtoMessage() {}
|
||||
|
||||
func (x *AuditRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[10]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use AuditRequest.ProtoReflect.Descriptor instead.
|
||||
func (*AuditRequest) Descriptor() ([]byte, []int) {
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{10}
|
||||
}
|
||||
|
||||
func (x *AuditRequest) GetTable() string {
|
||||
if x != nil {
|
||||
return x.Table
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AuditRequest) GetRecordKeys() []string {
|
||||
if x != nil {
|
||||
return x.RecordKeys
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *AuditRequest) GetLimit() int32 {
|
||||
if x != nil {
|
||||
return x.Limit
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type AuditResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Entries []*AuditEntry `protobuf:"bytes,1,rep,name=entries,proto3" json:"entries,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *AuditResponse) Reset() {
|
||||
*x = AuditResponse{}
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[11]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *AuditResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*AuditResponse) ProtoMessage() {}
|
||||
|
||||
func (x *AuditResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[11]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use AuditResponse.ProtoReflect.Descriptor instead.
|
||||
func (*AuditResponse) Descriptor() ([]byte, []int) {
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{11}
|
||||
}
|
||||
|
||||
func (x *AuditResponse) GetEntries() []*AuditEntry {
|
||||
if x != nil {
|
||||
return x.Entries
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type CommandRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Kind string `protobuf:"bytes,1,opt,name=kind,proto3" json:"kind,omitempty"`
|
||||
@@ -564,7 +796,7 @@ type CommandRequest struct {
|
||||
|
||||
func (x *CommandRequest) Reset() {
|
||||
*x = CommandRequest{}
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[9]
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[12]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -576,7 +808,7 @@ func (x *CommandRequest) String() string {
|
||||
func (*CommandRequest) ProtoMessage() {}
|
||||
|
||||
func (x *CommandRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[9]
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[12]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -589,7 +821,7 @@ func (x *CommandRequest) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use CommandRequest.ProtoReflect.Descriptor instead.
|
||||
func (*CommandRequest) Descriptor() ([]byte, []int) {
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{9}
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{12}
|
||||
}
|
||||
|
||||
func (x *CommandRequest) GetKind() string {
|
||||
@@ -650,7 +882,7 @@ type CommandResponse struct {
|
||||
|
||||
func (x *CommandResponse) Reset() {
|
||||
*x = CommandResponse{}
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[10]
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[13]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -662,7 +894,7 @@ func (x *CommandResponse) String() string {
|
||||
func (*CommandResponse) ProtoMessage() {}
|
||||
|
||||
func (x *CommandResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[10]
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[13]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -675,7 +907,7 @@ func (x *CommandResponse) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use CommandResponse.ProtoReflect.Descriptor instead.
|
||||
func (*CommandResponse) Descriptor() ([]byte, []int) {
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{10}
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{13}
|
||||
}
|
||||
|
||||
func (x *CommandResponse) GetResource() *Resource {
|
||||
@@ -695,7 +927,7 @@ type WatchRequest struct {
|
||||
|
||||
func (x *WatchRequest) Reset() {
|
||||
*x = WatchRequest{}
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[11]
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[14]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -707,7 +939,7 @@ func (x *WatchRequest) String() string {
|
||||
func (*WatchRequest) ProtoMessage() {}
|
||||
|
||||
func (x *WatchRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[11]
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[14]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -720,7 +952,7 @@ func (x *WatchRequest) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use WatchRequest.ProtoReflect.Descriptor instead.
|
||||
func (*WatchRequest) Descriptor() ([]byte, []int) {
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{11}
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{14}
|
||||
}
|
||||
|
||||
func (x *WatchRequest) GetKind() string {
|
||||
@@ -747,7 +979,7 @@ type WatchResponse struct {
|
||||
|
||||
func (x *WatchResponse) Reset() {
|
||||
*x = WatchResponse{}
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[12]
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[15]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -759,7 +991,7 @@ func (x *WatchResponse) String() string {
|
||||
func (*WatchResponse) ProtoMessage() {}
|
||||
|
||||
func (x *WatchResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[12]
|
||||
mi := &file_controlplane_v1_controlplane_proto_msgTypes[15]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -772,7 +1004,7 @@ func (x *WatchResponse) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use WatchResponse.ProtoReflect.Descriptor instead.
|
||||
func (*WatchResponse) Descriptor() ([]byte, []int) {
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{12}
|
||||
return file_controlplane_v1_controlplane_proto_rawDescGZIP(), []int{15}
|
||||
}
|
||||
|
||||
func (x *WatchResponse) GetResource() *Resource {
|
||||
@@ -832,7 +1064,30 @@ const file_controlplane_v1_controlplane_proto_rawDesc = "" +
|
||||
"\x04kind\x18\x01 \x01(\tR\x04kind\x12\x14\n" +
|
||||
"\x05limit\x18\x02 \x01(\x05R\x05limit\"J\n" +
|
||||
"\x0fHistoryResponse\x127\n" +
|
||||
"\trevisions\x18\x01 \x03(\v2\x19.controlplane.v1.RevisionR\trevisions\"\xd5\x01\n" +
|
||||
"\trevisions\x18\x01 \x03(\v2\x19.controlplane.v1.RevisionR\trevisions\"\xc6\x02\n" +
|
||||
"\n" +
|
||||
"AuditEntry\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
|
||||
"\x05table\x18\x02 \x01(\tR\x05table\x12\x1d\n" +
|
||||
"\n" +
|
||||
"record_key\x18\x03 \x01(\tR\trecordKey\x12\x14\n" +
|
||||
"\x05field\x18\x04 \x01(\tR\x05field\x12$\n" +
|
||||
"\x0eold_value_json\x18\x05 \x01(\fR\foldValueJson\x12$\n" +
|
||||
"\x0enew_value_json\x18\x06 \x01(\fR\fnewValueJson\x12\x18\n" +
|
||||
"\aversion\x18\a \x01(\x03R\aversion\x12\x14\n" +
|
||||
"\x05actor\x18\b \x01(\tR\x05actor\x12\x16\n" +
|
||||
"\x06source\x18\t \x01(\tR\x06source\x12\x1d\n" +
|
||||
"\n" +
|
||||
"request_id\x18\n" +
|
||||
" \x01(\tR\trequestId\x12*\n" +
|
||||
"\x02at\x18\v \x01(\v2\x1a.google.protobuf.TimestampR\x02at\"[\n" +
|
||||
"\fAuditRequest\x12\x14\n" +
|
||||
"\x05table\x18\x01 \x01(\tR\x05table\x12\x1f\n" +
|
||||
"\vrecord_keys\x18\x02 \x03(\tR\n" +
|
||||
"recordKeys\x12\x14\n" +
|
||||
"\x05limit\x18\x03 \x01(\x05R\x05limit\"F\n" +
|
||||
"\rAuditResponse\x125\n" +
|
||||
"\aentries\x18\x01 \x03(\v2\x1b.controlplane.v1.AuditEntryR\aentries\"\xd5\x01\n" +
|
||||
"\x0eCommandRequest\x12\x12\n" +
|
||||
"\x04kind\x18\x01 \x01(\tR\x04kind\x12\x18\n" +
|
||||
"\acommand\x18\x02 \x01(\tR\acommand\x12\x1d\n" +
|
||||
@@ -850,11 +1105,12 @@ const file_controlplane_v1_controlplane_proto_rawDesc = "" +
|
||||
"\rafter_version\x18\x02 \x01(\x03R\fafterVersion\"\\\n" +
|
||||
"\rWatchResponse\x125\n" +
|
||||
"\bresource\x18\x01 \x01(\v2\x19.controlplane.v1.ResourceR\bresource\x12\x14\n" +
|
||||
"\x05error\x18\x02 \x01(\tR\x05error2\x91\x03\n" +
|
||||
"\x05error\x18\x02 \x01(\tR\x05error2\xd9\x03\n" +
|
||||
"\x13ControlPlaneService\x12L\n" +
|
||||
"\aCatalog\x12\x1f.controlplane.v1.CatalogRequest\x1a .controlplane.v1.CatalogResponse\x12F\n" +
|
||||
"\x05Query\x12\x1d.controlplane.v1.QueryRequest\x1a\x1e.controlplane.v1.QueryResponse\x12L\n" +
|
||||
"\aHistory\x12\x1f.controlplane.v1.HistoryRequest\x1a .controlplane.v1.HistoryResponse\x12L\n" +
|
||||
"\aHistory\x12\x1f.controlplane.v1.HistoryRequest\x1a .controlplane.v1.HistoryResponse\x12F\n" +
|
||||
"\x05Audit\x12\x1d.controlplane.v1.AuditRequest\x1a\x1e.controlplane.v1.AuditResponse\x12L\n" +
|
||||
"\aCommand\x12\x1f.controlplane.v1.CommandRequest\x1a .controlplane.v1.CommandResponse\x12H\n" +
|
||||
"\x05Watch\x12\x1d.controlplane.v1.WatchRequest\x1a\x1e.controlplane.v1.WatchResponse0\x01B\xdc\x01\n" +
|
||||
"\x13com.controlplane.v1B\x11ControlplaneProtoP\x01ZUgithub.com/samcharles93/archie-core/internal/contracts/controlplane/v1;controlplanev1\xa2\x02\x03CXX\xaa\x02\x0fControlplane.V1\xca\x02\x0fControlplane\\V1\xe2\x02\x1bControlplane\\V1\\GPBMetadata\xea\x02\x10Controlplane::V1b\x06proto3"
|
||||
@@ -871,7 +1127,7 @@ func file_controlplane_v1_controlplane_proto_rawDescGZIP() []byte {
|
||||
return file_controlplane_v1_controlplane_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_controlplane_v1_controlplane_proto_msgTypes = make([]protoimpl.MessageInfo, 13)
|
||||
var file_controlplane_v1_controlplane_proto_msgTypes = make([]protoimpl.MessageInfo, 16)
|
||||
var file_controlplane_v1_controlplane_proto_goTypes = []any{
|
||||
(*ResourceDescriptor)(nil), // 0: controlplane.v1.ResourceDescriptor
|
||||
(*CatalogRequest)(nil), // 1: controlplane.v1.CatalogRequest
|
||||
@@ -882,35 +1138,42 @@ var file_controlplane_v1_controlplane_proto_goTypes = []any{
|
||||
(*Revision)(nil), // 6: controlplane.v1.Revision
|
||||
(*HistoryRequest)(nil), // 7: controlplane.v1.HistoryRequest
|
||||
(*HistoryResponse)(nil), // 8: controlplane.v1.HistoryResponse
|
||||
(*CommandRequest)(nil), // 9: controlplane.v1.CommandRequest
|
||||
(*CommandResponse)(nil), // 10: controlplane.v1.CommandResponse
|
||||
(*WatchRequest)(nil), // 11: controlplane.v1.WatchRequest
|
||||
(*WatchResponse)(nil), // 12: controlplane.v1.WatchResponse
|
||||
(*timestamppb.Timestamp)(nil), // 13: google.protobuf.Timestamp
|
||||
(*AuditEntry)(nil), // 9: controlplane.v1.AuditEntry
|
||||
(*AuditRequest)(nil), // 10: controlplane.v1.AuditRequest
|
||||
(*AuditResponse)(nil), // 11: controlplane.v1.AuditResponse
|
||||
(*CommandRequest)(nil), // 12: controlplane.v1.CommandRequest
|
||||
(*CommandResponse)(nil), // 13: controlplane.v1.CommandResponse
|
||||
(*WatchRequest)(nil), // 14: controlplane.v1.WatchRequest
|
||||
(*WatchResponse)(nil), // 15: controlplane.v1.WatchResponse
|
||||
(*timestamppb.Timestamp)(nil), // 16: google.protobuf.Timestamp
|
||||
}
|
||||
var file_controlplane_v1_controlplane_proto_depIdxs = []int32{
|
||||
0, // 0: controlplane.v1.CatalogResponse.resources:type_name -> controlplane.v1.ResourceDescriptor
|
||||
13, // 1: controlplane.v1.Resource.updated_at:type_name -> google.protobuf.Timestamp
|
||||
16, // 1: controlplane.v1.Resource.updated_at:type_name -> google.protobuf.Timestamp
|
||||
3, // 2: controlplane.v1.QueryResponse.resource:type_name -> controlplane.v1.Resource
|
||||
13, // 3: controlplane.v1.Revision.at:type_name -> google.protobuf.Timestamp
|
||||
16, // 3: controlplane.v1.Revision.at:type_name -> google.protobuf.Timestamp
|
||||
6, // 4: controlplane.v1.HistoryResponse.revisions:type_name -> controlplane.v1.Revision
|
||||
3, // 5: controlplane.v1.CommandResponse.resource:type_name -> controlplane.v1.Resource
|
||||
3, // 6: controlplane.v1.WatchResponse.resource:type_name -> controlplane.v1.Resource
|
||||
1, // 7: controlplane.v1.ControlPlaneService.Catalog:input_type -> controlplane.v1.CatalogRequest
|
||||
4, // 8: controlplane.v1.ControlPlaneService.Query:input_type -> controlplane.v1.QueryRequest
|
||||
7, // 9: controlplane.v1.ControlPlaneService.History:input_type -> controlplane.v1.HistoryRequest
|
||||
9, // 10: controlplane.v1.ControlPlaneService.Command:input_type -> controlplane.v1.CommandRequest
|
||||
11, // 11: controlplane.v1.ControlPlaneService.Watch:input_type -> controlplane.v1.WatchRequest
|
||||
2, // 12: controlplane.v1.ControlPlaneService.Catalog:output_type -> controlplane.v1.CatalogResponse
|
||||
5, // 13: controlplane.v1.ControlPlaneService.Query:output_type -> controlplane.v1.QueryResponse
|
||||
8, // 14: controlplane.v1.ControlPlaneService.History:output_type -> controlplane.v1.HistoryResponse
|
||||
10, // 15: controlplane.v1.ControlPlaneService.Command:output_type -> controlplane.v1.CommandResponse
|
||||
12, // 16: controlplane.v1.ControlPlaneService.Watch:output_type -> controlplane.v1.WatchResponse
|
||||
12, // [12:17] is the sub-list for method output_type
|
||||
7, // [7:12] is the sub-list for method input_type
|
||||
7, // [7:7] is the sub-list for extension type_name
|
||||
7, // [7:7] is the sub-list for extension extendee
|
||||
0, // [0:7] is the sub-list for field type_name
|
||||
16, // 5: controlplane.v1.AuditEntry.at:type_name -> google.protobuf.Timestamp
|
||||
9, // 6: controlplane.v1.AuditResponse.entries:type_name -> controlplane.v1.AuditEntry
|
||||
3, // 7: controlplane.v1.CommandResponse.resource:type_name -> controlplane.v1.Resource
|
||||
3, // 8: controlplane.v1.WatchResponse.resource:type_name -> controlplane.v1.Resource
|
||||
1, // 9: controlplane.v1.ControlPlaneService.Catalog:input_type -> controlplane.v1.CatalogRequest
|
||||
4, // 10: controlplane.v1.ControlPlaneService.Query:input_type -> controlplane.v1.QueryRequest
|
||||
7, // 11: controlplane.v1.ControlPlaneService.History:input_type -> controlplane.v1.HistoryRequest
|
||||
10, // 12: controlplane.v1.ControlPlaneService.Audit:input_type -> controlplane.v1.AuditRequest
|
||||
12, // 13: controlplane.v1.ControlPlaneService.Command:input_type -> controlplane.v1.CommandRequest
|
||||
14, // 14: controlplane.v1.ControlPlaneService.Watch:input_type -> controlplane.v1.WatchRequest
|
||||
2, // 15: controlplane.v1.ControlPlaneService.Catalog:output_type -> controlplane.v1.CatalogResponse
|
||||
5, // 16: controlplane.v1.ControlPlaneService.Query:output_type -> controlplane.v1.QueryResponse
|
||||
8, // 17: controlplane.v1.ControlPlaneService.History:output_type -> controlplane.v1.HistoryResponse
|
||||
11, // 18: controlplane.v1.ControlPlaneService.Audit:output_type -> controlplane.v1.AuditResponse
|
||||
13, // 19: controlplane.v1.ControlPlaneService.Command:output_type -> controlplane.v1.CommandResponse
|
||||
15, // 20: controlplane.v1.ControlPlaneService.Watch:output_type -> controlplane.v1.WatchResponse
|
||||
15, // [15:21] is the sub-list for method output_type
|
||||
9, // [9:15] is the sub-list for method input_type
|
||||
9, // [9:9] is the sub-list for extension type_name
|
||||
9, // [9:9] is the sub-list for extension extendee
|
||||
0, // [0:9] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_controlplane_v1_controlplane_proto_init() }
|
||||
@@ -924,7 +1187,7 @@ func file_controlplane_v1_controlplane_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_controlplane_v1_controlplane_proto_rawDesc), len(file_controlplane_v1_controlplane_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 13,
|
||||
NumMessages: 16,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
||||
@@ -22,6 +22,7 @@ const (
|
||||
ControlPlaneService_Catalog_FullMethodName = "/controlplane.v1.ControlPlaneService/Catalog"
|
||||
ControlPlaneService_Query_FullMethodName = "/controlplane.v1.ControlPlaneService/Query"
|
||||
ControlPlaneService_History_FullMethodName = "/controlplane.v1.ControlPlaneService/History"
|
||||
ControlPlaneService_Audit_FullMethodName = "/controlplane.v1.ControlPlaneService/Audit"
|
||||
ControlPlaneService_Command_FullMethodName = "/controlplane.v1.ControlPlaneService/Command"
|
||||
ControlPlaneService_Watch_FullMethodName = "/controlplane.v1.ControlPlaneService/Watch"
|
||||
)
|
||||
@@ -33,6 +34,7 @@ type ControlPlaneServiceClient interface {
|
||||
Catalog(ctx context.Context, in *CatalogRequest, opts ...grpc.CallOption) (*CatalogResponse, error)
|
||||
Query(ctx context.Context, in *QueryRequest, opts ...grpc.CallOption) (*QueryResponse, error)
|
||||
History(ctx context.Context, in *HistoryRequest, opts ...grpc.CallOption) (*HistoryResponse, error)
|
||||
Audit(ctx context.Context, in *AuditRequest, opts ...grpc.CallOption) (*AuditResponse, error)
|
||||
Command(ctx context.Context, in *CommandRequest, opts ...grpc.CallOption) (*CommandResponse, error)
|
||||
Watch(ctx context.Context, in *WatchRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[WatchResponse], error)
|
||||
}
|
||||
@@ -75,6 +77,16 @@ func (c *controlPlaneServiceClient) History(ctx context.Context, in *HistoryRequ
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *controlPlaneServiceClient) Audit(ctx context.Context, in *AuditRequest, opts ...grpc.CallOption) (*AuditResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AuditResponse)
|
||||
err := c.cc.Invoke(ctx, ControlPlaneService_Audit_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *controlPlaneServiceClient) Command(ctx context.Context, in *CommandRequest, opts ...grpc.CallOption) (*CommandResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CommandResponse)
|
||||
@@ -111,6 +123,7 @@ type ControlPlaneServiceServer interface {
|
||||
Catalog(context.Context, *CatalogRequest) (*CatalogResponse, error)
|
||||
Query(context.Context, *QueryRequest) (*QueryResponse, error)
|
||||
History(context.Context, *HistoryRequest) (*HistoryResponse, error)
|
||||
Audit(context.Context, *AuditRequest) (*AuditResponse, error)
|
||||
Command(context.Context, *CommandRequest) (*CommandResponse, error)
|
||||
Watch(*WatchRequest, grpc.ServerStreamingServer[WatchResponse]) error
|
||||
mustEmbedUnimplementedControlPlaneServiceServer()
|
||||
@@ -132,6 +145,9 @@ func (UnimplementedControlPlaneServiceServer) Query(context.Context, *QueryReque
|
||||
func (UnimplementedControlPlaneServiceServer) History(context.Context, *HistoryRequest) (*HistoryResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method History not implemented")
|
||||
}
|
||||
func (UnimplementedControlPlaneServiceServer) Audit(context.Context, *AuditRequest) (*AuditResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method Audit not implemented")
|
||||
}
|
||||
func (UnimplementedControlPlaneServiceServer) Command(context.Context, *CommandRequest) (*CommandResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method Command not implemented")
|
||||
}
|
||||
@@ -213,6 +229,24 @@ func _ControlPlaneService_History_Handler(srv interface{}, ctx context.Context,
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ControlPlaneService_Audit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AuditRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ControlPlaneServiceServer).Audit(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ControlPlaneService_Audit_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ControlPlaneServiceServer).Audit(ctx, req.(*AuditRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ControlPlaneService_Command_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CommandRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -261,6 +295,10 @@ var ControlPlaneService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "History",
|
||||
Handler: _ControlPlaneService_History_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Audit",
|
||||
Handler: _ControlPlaneService_Audit_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Command",
|
||||
Handler: _ControlPlaneService_Command_Handler,
|
||||
|
||||
@@ -1276,9 +1276,11 @@ func (d *Daemon) process(ctx context.Context, task *workflow.Task) {
|
||||
// worktreerpc clients to that identity, and the daemon registered one
|
||||
// server pair per identity (plus the root pair), so a container-mode
|
||||
// task is always served by its own forge client and worktree manager.
|
||||
runCtx, stopWatch := withContainerExit(ctx, ctr.Exited())
|
||||
limitCtx, stopLimit := withTaskTimeLimit(ctx, d.configFor(task).Budgets.TaskWallClock.Std())
|
||||
runCtx, stopWatch := withContainerExit(limitCtx, ctr.Exited())
|
||||
d.runViaAgent(runCtx, task, repo, profile)
|
||||
stopWatch()
|
||||
stopLimit()
|
||||
|
||||
// Teardown storage after workflow completes. The Docker backend is a
|
||||
// no-op; future backends (temp volumes, NFS leases) use this hook.
|
||||
@@ -1575,8 +1577,8 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
}
|
||||
|
||||
reply, err := d.requestTaskRun(ctx, task.ID, data)
|
||||
if err != nil && errors.Is(context.Cause(ctx), errContainerExited) {
|
||||
err = errContainerExited
|
||||
if cause := context.Cause(ctx); err != nil && (errors.Is(cause, errContainerExited) || errors.Is(cause, errTaskTimeLimit)) {
|
||||
err = cause
|
||||
}
|
||||
if err != nil {
|
||||
d.Log.Error("taskrun request failed", "task", task.ID, "err", err)
|
||||
@@ -2099,3 +2101,16 @@ func withContainerExit(ctx context.Context, exited <-chan struct{}) (context.Con
|
||||
}()
|
||||
return runCtx, func() { cancel(nil) }
|
||||
}
|
||||
|
||||
// errTaskTimeLimit is the cancellation cause when a task outruns its overall
|
||||
// time limit (the execution settings' max task runtime).
|
||||
var errTaskTimeLimit = errors.New("task exceeded its time limit")
|
||||
|
||||
// withTaskTimeLimit bounds a whole task run. A limit of zero or less applies
|
||||
// no bound.
|
||||
func withTaskTimeLimit(ctx context.Context, limit time.Duration) (context.Context, func()) {
|
||||
if limit <= 0 {
|
||||
return ctx, func() {}
|
||||
}
|
||||
return context.WithTimeoutCause(ctx, limit, fmt.Errorf("%w (%s)", errTaskTimeLimit, limit))
|
||||
}
|
||||
@@ -2399,3 +2399,40 @@ func TestRunViaAgentParksWhenTheContainerExits(t *testing.T) {
|
||||
t.Fatalf("task = %+v, %v; want parked naming the container exit", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
// A task that outruns its overall time limit is parked with the limit named,
|
||||
// even while its agent is still alive and silent.
|
||||
func TestRunViaAgentParksWhenTheTaskTimeLimitPasses(t *testing.T) {
|
||||
d, s, busClient := daemonWithNATS(t)
|
||||
ctx := context.Background()
|
||||
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 22, "t", "b", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, err := s.ClaimNext(ctx)
|
||||
if err != nil || task == nil {
|
||||
t.Fatalf("claim: (%v, %v)", task, err)
|
||||
}
|
||||
sub, err := mustCoreConn(t, busClient).Subscribe(agentnats.SubjectForTask(task.ID), func(*natsio.Msg) {})
|
||||
if err != nil {
|
||||
t.Fatalf("subscribe: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = sub.Unsubscribe() })
|
||||
|
||||
runCtx, stop := withTaskTimeLimit(ctx, 100*time.Millisecond)
|
||||
defer stop()
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
d.runViaAgent(runCtx, task, config.Repo{Owner: "acme", Name: "widget", Base: "main"}, config.AgentProfile{})
|
||||
close(done)
|
||||
}()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("runViaAgent still blocked after the task time limit passed")
|
||||
}
|
||||
|
||||
got, err := s.TaskByID(ctx, task.ID)
|
||||
if err != nil || got.Status != workflow.StatusParked || !strings.Contains(got.ParkReason, "task exceeded its time limit (100ms)") {
|
||||
t.Fatalf("task = %+v, %v; want parked naming the time limit", got, err)
|
||||
}
|
||||
}
|
||||
@@ -450,6 +450,27 @@ type Resource struct {
|
||||
At time.Time
|
||||
}
|
||||
|
||||
// AuditTableResources is the sys_audit table name for control-plane resources,
|
||||
// keyed by resource kind.
|
||||
const AuditTableResources = "resources"
|
||||
|
||||
// AuditEntry is one changed field of one record, as sys_audit holds it. Any
|
||||
// store table may write entries; Table and RecordKey locate the record.
|
||||
// OldValue and NewValue are JSON; an absent side is empty.
|
||||
type AuditEntry struct {
|
||||
ID int64
|
||||
Table string
|
||||
RecordKey string
|
||||
Field string
|
||||
OldValue []byte
|
||||
NewValue []byte
|
||||
Version int64
|
||||
Actor string
|
||||
Source string
|
||||
RequestID string
|
||||
At time.Time
|
||||
}
|
||||
|
||||
// ResourceWrite is a control-plane resource write request. ExpectedVersion is
|
||||
// the optimistic-concurrency guard: a write whose expectation does not match
|
||||
// the stored revision is refused with ErrResourceVersionConflict.
|
||||
|
||||
@@ -11,6 +11,7 @@ type ExecutionSettings struct {
|
||||
MaxModelToolSteps int `json:"max_model_tool_steps"`
|
||||
MaxRuntime time.Duration `json:"max_runtime"`
|
||||
MaxConsecutiveGateFailures int `json:"max_consecutive_gate_failures"`
|
||||
MaxTaskRuntime time.Duration `json:"max_task_runtime"`
|
||||
}
|
||||
|
||||
// Validate rejects negative limits. Zero preserves the established meaning of
|
||||
@@ -23,6 +24,9 @@ func (s ExecutionSettings) Validate() error {
|
||||
if s.MaxRuntime < 0 {
|
||||
errs = append(errs, fmt.Errorf("max runtime must not be negative"))
|
||||
}
|
||||
if s.MaxTaskRuntime < 0 {
|
||||
errs = append(errs, fmt.Errorf("max task runtime must not be negative"))
|
||||
}
|
||||
if s.MaxConsecutiveGateFailures < 0 {
|
||||
errs = append(errs, fmt.Errorf("max consecutive gate failures must not be negative"))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
-- sys_audit is the field-level audit trail: one row per changed field of one
|
||||
-- record, whatever the table. Settings resources are the first writer.
|
||||
|
||||
-- +goose Up
|
||||
CREATE TABLE sys_audit (
|
||||
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
at timestamptz NOT NULL,
|
||||
table_name text NOT NULL,
|
||||
record_key text NOT NULL,
|
||||
field text NOT NULL,
|
||||
old_value jsonb,
|
||||
new_value jsonb,
|
||||
record_version bigint NOT NULL,
|
||||
actor text NOT NULL,
|
||||
source text NOT NULL,
|
||||
request_id text NOT NULL
|
||||
);
|
||||
CREATE INDEX idx_sys_audit_record ON sys_audit (table_name, record_key, id DESC);
|
||||
|
||||
-- audit_json_diff lists the top-level fields that differ between two JSON
|
||||
-- documents. A document that is not an object is audited whole, as field ''.
|
||||
-- +goose StatementBegin
|
||||
CREATE FUNCTION audit_json_diff(prev jsonb, doc jsonb)
|
||||
RETURNS TABLE (field text, old_value jsonb, new_value jsonb)
|
||||
LANGUAGE sql IMMUTABLE AS $$
|
||||
SELECT k, prev -> k, doc -> k
|
||||
FROM (
|
||||
SELECT jsonb_object_keys(doc) AS k WHERE jsonb_typeof(doc) = 'object'
|
||||
UNION
|
||||
SELECT jsonb_object_keys(prev) WHERE jsonb_typeof(prev) = 'object'
|
||||
) keys
|
||||
WHERE jsonb_typeof(COALESCE(doc, '{}')) = 'object'
|
||||
AND jsonb_typeof(COALESCE(prev, '{}')) = 'object'
|
||||
AND (prev -> k) IS DISTINCT FROM (doc -> k)
|
||||
UNION ALL
|
||||
SELECT '', prev, doc
|
||||
WHERE NOT (jsonb_typeof(COALESCE(doc, '{}')) = 'object'
|
||||
AND jsonb_typeof(COALESCE(prev, '{}')) = 'object')
|
||||
AND prev IS DISTINCT FROM doc
|
||||
$$;
|
||||
-- +goose StatementEnd
|
||||
|
||||
INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id)
|
||||
SELECT h.at, 'resources', h.kind, d.field, d.old_value, d.new_value, h.version, h.actor, h.source, h.request_id
|
||||
FROM (
|
||||
SELECT kind, version, actor, source, request_id, at,
|
||||
convert_from(value, 'UTF8')::jsonb AS doc,
|
||||
lag(convert_from(value, 'UTF8')::jsonb) OVER (PARTITION BY kind ORDER BY version) AS prev
|
||||
FROM resource_history
|
||||
) h
|
||||
CROSS JOIN LATERAL audit_json_diff(h.prev, h.doc) d
|
||||
ORDER BY h.kind, h.version, d.field;
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE sys_audit;
|
||||
DROP FUNCTION audit_json_diff(jsonb, jsonb);
|
||||
@@ -0,0 +1,96 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: audit.sql
|
||||
|
||||
package postgresdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const auditForRecords = `-- name: AuditForRecords :many
|
||||
SELECT id, at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id
|
||||
FROM sys_audit
|
||||
WHERE table_name = $1::text AND record_key = ANY($2::text[])
|
||||
ORDER BY id DESC
|
||||
LIMIT $3::bigint
|
||||
`
|
||||
|
||||
type AuditForRecordsParams struct {
|
||||
TableName string
|
||||
RecordKeys []string
|
||||
EntryLimit int64
|
||||
}
|
||||
|
||||
func (q *Queries) AuditForRecords(ctx context.Context, arg AuditForRecordsParams) ([]SysAudit, error) {
|
||||
rows, err := q.db.Query(ctx, auditForRecords, arg.TableName, arg.RecordKeys, arg.EntryLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SysAudit
|
||||
for rows.Next() {
|
||||
var i SysAudit
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.At,
|
||||
&i.TableName,
|
||||
&i.RecordKey,
|
||||
&i.Field,
|
||||
&i.OldValue,
|
||||
&i.NewValue,
|
||||
&i.RecordVersion,
|
||||
&i.Actor,
|
||||
&i.Source,
|
||||
&i.RequestID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const insertResourceAudit = `-- name: InsertResourceAudit :exec
|
||||
INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id)
|
||||
SELECT $1::timestamptz, 'resources', $2::text, d.field, d.old_value, d.new_value,
|
||||
$3::bigint, $4::text, $5::text, $6::text
|
||||
FROM audit_json_diff(
|
||||
(SELECT convert_from(h.value, 'UTF8')::jsonb FROM resource_history h
|
||||
WHERE h.kind = $2::text AND h.version = $7::bigint),
|
||||
convert_from($8::bytea, 'UTF8')::jsonb
|
||||
) d
|
||||
ORDER BY d.field
|
||||
`
|
||||
|
||||
type InsertResourceAuditParams struct {
|
||||
At time.Time
|
||||
Kind string
|
||||
Version int64
|
||||
Actor string
|
||||
Source string
|
||||
RequestID string
|
||||
PreviousVersion int64
|
||||
Value []byte
|
||||
}
|
||||
|
||||
// Records the fields one resource write changed, against the version it
|
||||
// replaced. Runs in the write's own transaction.
|
||||
func (q *Queries) InsertResourceAudit(ctx context.Context, arg InsertResourceAuditParams) error {
|
||||
_, err := q.db.Exec(ctx, insertResourceAudit,
|
||||
arg.At,
|
||||
arg.Kind,
|
||||
arg.Version,
|
||||
arg.Actor,
|
||||
arg.Source,
|
||||
arg.RequestID,
|
||||
arg.PreviousVersion,
|
||||
arg.Value,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -212,6 +212,20 @@ type Source struct {
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type SysAudit struct {
|
||||
ID int64
|
||||
At time.Time
|
||||
TableName string
|
||||
RecordKey string
|
||||
Field string
|
||||
OldValue []byte
|
||||
NewValue []byte
|
||||
RecordVersion int64
|
||||
Actor string
|
||||
Source string
|
||||
RequestID string
|
||||
}
|
||||
|
||||
type Task struct {
|
||||
ID int64
|
||||
Owner string
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
-- name: InsertResourceAudit :exec
|
||||
-- Records the fields one resource write changed, against the version it
|
||||
-- replaced. Runs in the write's own transaction.
|
||||
INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id)
|
||||
SELECT sqlc.arg(at)::timestamptz, 'resources', sqlc.arg(kind)::text, d.field, d.old_value, d.new_value,
|
||||
sqlc.arg(version)::bigint, sqlc.arg(actor)::text, sqlc.arg(source)::text, sqlc.arg(request_id)::text
|
||||
FROM audit_json_diff(
|
||||
(SELECT convert_from(h.value, 'UTF8')::jsonb FROM resource_history h
|
||||
WHERE h.kind = sqlc.arg(kind)::text AND h.version = sqlc.arg(previous_version)::bigint),
|
||||
convert_from(sqlc.arg(value)::bytea, 'UTF8')::jsonb
|
||||
) d
|
||||
ORDER BY d.field;
|
||||
|
||||
-- name: AuditForRecords :many
|
||||
SELECT id, at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id
|
||||
FROM sys_audit
|
||||
WHERE table_name = sqlc.arg(table_name)::text AND record_key = ANY(sqlc.arg(record_keys)::text[])
|
||||
ORDER BY id DESC
|
||||
LIMIT sqlc.arg(entry_limit)::bigint;
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
@@ -54,6 +55,29 @@ func (s *Resources) ResourceHistory(ctx context.Context, kind string, limit int)
|
||||
return resources, nil
|
||||
}
|
||||
|
||||
// Audit returns the field-level audit of the named records of one table,
|
||||
// newest first. A limit of zero or less returns every entry.
|
||||
func (s *Resources) Audit(ctx context.Context, table string, keys []string, limit int) ([]storecontract.AuditEntry, error) {
|
||||
if limit <= 0 {
|
||||
limit = math.MaxInt32
|
||||
}
|
||||
rows, err := postgresdb.New(s.pool).AuditForRecords(ctx, postgresdb.AuditForRecordsParams{
|
||||
TableName: table, RecordKeys: keys, EntryLimit: int64(limit),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
entries := make([]storecontract.AuditEntry, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
entries = append(entries, storecontract.AuditEntry{
|
||||
ID: row.ID, Table: row.TableName, RecordKey: row.RecordKey, Field: row.Field,
|
||||
OldValue: row.OldValue, NewValue: row.NewValue, Version: row.RecordVersion,
|
||||
Actor: row.Actor, Source: row.Source, RequestID: row.RequestID, At: row.At,
|
||||
})
|
||||
}
|
||||
return entries, nil
|
||||
}
|
||||
|
||||
func (s *Resources) PutResource(ctx context.Context, write storecontract.ResourceWrite) (_ storecontract.Resource, retErr error) {
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -111,6 +135,12 @@ func (s *Resources) PutResource(ctx context.Context, write storecontract.Resourc
|
||||
if err != nil {
|
||||
return storecontract.Resource{}, err
|
||||
}
|
||||
if err := queries.InsertResourceAudit(ctx, postgresdb.InsertResourceAuditParams{
|
||||
At: write.At, Kind: write.Kind, Version: resource.Version, Actor: write.Actor,
|
||||
Source: write.Source, RequestID: write.RequestID, PreviousVersion: current, Value: write.Value,
|
||||
}); err != nil {
|
||||
return storecontract.Resource{}, err
|
||||
}
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return storecontract.Resource{}, err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package postgres
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -296,3 +298,37 @@ func TestConcurrentResourceWritesAcceptOnlyOneExpectedVersion(t *testing.T) {
|
||||
t.Fatalf("history after race = %+v, want exactly one version 1", history)
|
||||
}
|
||||
}
|
||||
|
||||
// TestResourceWritesRecordFieldLevelAudit: each write records one sys_audit row
|
||||
// per field it changed, newest first, and a replayed write records nothing.
|
||||
func TestResourceWritesRecordFieldLevelAudit(t *testing.T) {
|
||||
resources := resourcesFor(t)
|
||||
put := func(value string, expected int64, request string) {
|
||||
t.Helper()
|
||||
if _, err := resources.PutResource(t.Context(), storecontract.ResourceWrite{
|
||||
Kind: "settings", Value: []byte(value), Actor: "sam", Source: "archie-ui",
|
||||
RequestID: request, ExpectedVersion: expected,
|
||||
}); err != nil {
|
||||
t.Fatalf("PutResource(%s): %v", value, err)
|
||||
}
|
||||
}
|
||||
put(`{"a":1,"b":2}`, 0, "r1")
|
||||
put(`{"a":1,"b":3,"c":4}`, 1, "r2")
|
||||
put(`{"a":1,"b":3,"c":4}`, 1, "r2")
|
||||
|
||||
audit, err := resources.Audit(t.Context(), storecontract.AuditTableResources, []string{"settings"}, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("ResourceAudit: %v", err)
|
||||
}
|
||||
got := make([]string, 0, len(audit))
|
||||
for _, entry := range audit {
|
||||
got = append(got, fmt.Sprintf("v%d %s %s->%s by %s", entry.Version, entry.Field, entry.OldValue, entry.NewValue, entry.Actor))
|
||||
}
|
||||
want := []string{
|
||||
"v2 c ->4 by sam", "v2 b 2->3 by sam",
|
||||
"v1 b ->2 by sam", "v1 a ->1 by sam",
|
||||
}
|
||||
if strings.Join(got, "; ") != strings.Join(want, "; ") {
|
||||
t.Fatalf("audit =\n%s\nwant\n%s", strings.Join(got, "\n"), strings.Join(want, "\n"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
)
|
||||
|
||||
// auditEntryView is one changed field of one record. An absent side of the
|
||||
// change is JSON null.
|
||||
type auditEntryView struct {
|
||||
ID int64 `json:"id"`
|
||||
Table string `json:"table"`
|
||||
RecordKey string `json:"record_key"`
|
||||
Field string `json:"field"`
|
||||
OldValue json.RawMessage `json:"old_value"`
|
||||
NewValue json.RawMessage `json:"new_value"`
|
||||
Version int64 `json:"version"`
|
||||
Actor string `json:"actor"`
|
||||
Source string `json:"source"`
|
||||
At *time.Time `json:"at,omitempty"`
|
||||
}
|
||||
|
||||
// handleAudit is GET /api/control-plane/audit?table=T&key=K1&key=K2: the
|
||||
// field-level audit of the named records of one table, newest first. A page
|
||||
// passes the records it shows, so its audit list is scoped to that page.
|
||||
func (s *Server) handleAudit(w http.ResponseWriter, r *http.Request) {
|
||||
if s.ControlPlane == nil {
|
||||
http.Error(w, "control plane unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
query := r.URL.Query()
|
||||
response, err := s.ControlPlane.Audit(r.Context(), &controlpb.AuditRequest{Table: query.Get("table"), RecordKeys: query["key"]})
|
||||
if err != nil {
|
||||
writeControlPlaneError(w, err)
|
||||
return
|
||||
}
|
||||
entries := make([]auditEntryView, 0, len(response.Entries))
|
||||
for _, entry := range response.Entries {
|
||||
view := auditEntryView{
|
||||
ID: entry.Id, Table: entry.Table, RecordKey: entry.RecordKey, Field: entry.Field,
|
||||
OldValue: jsonOrNull(entry.OldValueJson), NewValue: jsonOrNull(entry.NewValueJson),
|
||||
Version: entry.Version, Actor: entry.Actor, Source: entry.Source,
|
||||
}
|
||||
if entry.At != nil {
|
||||
at := entry.At.AsTime()
|
||||
view.At = &at
|
||||
}
|
||||
entries = append(entries, view)
|
||||
}
|
||||
writeJSON(w, map[string]any{"entries": entries})
|
||||
}
|
||||
|
||||
func jsonOrNull(value []byte) json.RawMessage {
|
||||
if len(value) == 0 {
|
||||
return json.RawMessage("null")
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -23,6 +23,8 @@ type controlPlaneClientStub struct {
|
||||
query *controlpb.Resource
|
||||
history *controlpb.HistoryRequest
|
||||
revisions []*controlpb.Revision
|
||||
audit *controlpb.AuditRequest
|
||||
entries []*controlpb.AuditEntry
|
||||
watch grpc.ServerStreamingClient[controlpb.WatchResponse]
|
||||
err error
|
||||
}
|
||||
@@ -40,6 +42,11 @@ func (f *controlPlaneClientStub) History(_ context.Context, request *controlpb.H
|
||||
return &controlpb.HistoryResponse{Revisions: f.revisions}, f.err
|
||||
}
|
||||
|
||||
func (f *controlPlaneClientStub) Audit(_ context.Context, request *controlpb.AuditRequest, _ ...grpc.CallOption) (*controlpb.AuditResponse, error) {
|
||||
f.audit = request
|
||||
return &controlpb.AuditResponse{Entries: f.entries}, f.err
|
||||
}
|
||||
|
||||
func (f *controlPlaneClientStub) Command(_ context.Context, request *controlpb.CommandRequest, _ ...grpc.CallOption) (*controlpb.CommandResponse, error) {
|
||||
f.command = request
|
||||
if f.err != nil {
|
||||
@@ -177,3 +184,39 @@ func TestControlPlaneHistoryWithoutAControlPlaneIsUnavailable(t *testing.T) {
|
||||
t.Fatalf("status = %d, want 503", response.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// TestControlPlaneAuditFiltersByTableAndRecord: the page names its table and
|
||||
// records; the endpoint forwards exactly those and returns each changed field
|
||||
// with its JSON values intact.
|
||||
func TestControlPlaneAuditFiltersByTableAndRecord(t *testing.T) {
|
||||
client := &controlPlaneClientStub{entries: []*controlpb.AuditEntry{{
|
||||
Id: 9, Table: "resources", RecordKey: "workflow-execution-settings", Field: "max_model_tool_steps",
|
||||
OldValueJson: []byte("90"), NewValueJson: []byte("120"), Version: 2, Actor: "system", Source: "archie-ui",
|
||||
}}}
|
||||
server := &Server{ControlPlane: client}
|
||||
request := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/control-plane/audit?table=resources&key=workflow-execution-settings&key=model-settings", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
server.Handler().ServeHTTP(response, request)
|
||||
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, body = %q", response.Code, response.Body.String())
|
||||
}
|
||||
if client.audit.GetTable() != "resources" || strings.Join(client.audit.GetRecordKeys(), ",") != "workflow-execution-settings,model-settings" {
|
||||
t.Fatalf("forwarded %+v", client.audit)
|
||||
}
|
||||
var got struct {
|
||||
Entries []struct {
|
||||
Field string `json:"field"`
|
||||
OldValue json.RawMessage `json:"old_value"`
|
||||
NewValue json.RawMessage `json:"new_value"`
|
||||
Version int64 `json:"version"`
|
||||
} `json:"entries"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got.Entries) != 1 || got.Entries[0].Field != "max_model_tool_steps" || string(got.Entries[0].OldValue) != "90" || string(got.Entries[0].NewValue) != "120" || got.Entries[0].Version != 2 {
|
||||
t.Fatalf("entries = %+v", got.Entries)
|
||||
}
|
||||
}
|
||||
@@ -293,6 +293,7 @@ func (s *Server) registerConfigAndLogRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /api/control-plane/resources/{kind}/history", s.handleControlPlaneHistory)
|
||||
mux.HandleFunc("POST /api/control-plane/resources/{kind}/commands/{command}", s.handleControlPlaneCommand)
|
||||
mux.HandleFunc("GET /api/control-plane/watch/{kind}", s.handleControlPlaneWatch)
|
||||
mux.HandleFunc("GET /api/control-plane/audit", s.handleAudit)
|
||||
mux.HandleFunc("GET /api/identities", s.handleIdentitiesList)
|
||||
mux.HandleFunc("GET /api/identities/watch", s.handleIdentitiesWatch)
|
||||
mux.HandleFunc("POST /api/identities", s.handleIdentityCreate)
|
||||
|
||||
Reference in new issue
Block a user