Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@ on:
push:
branches: [main]
pull_request:
workflow_dispatch:

permissions:
contents: read
packages: read

concurrency:
group: e2e-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
e2e:
runs-on: ubuntu-latest
timeout-minutes: 60
env:
GOTOOLCHAIN: local
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Provision cluster
uses: agynio/bootstrap/.github/actions/provision@main
uses: agynio/e2e/.github/actions/provision-vm@main

- name: Setup DevSpace
uses: agynio/e2e/.github/actions/setup-devspace@main
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.gen/
Dockerfile.localtest
Dockerfile.localtest.dockerignore
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ RUN --mount=type=cache,target=/go/pkg/mod \
go mod download

COPY buf.gen.yaml buf.yaml ./
RUN buf generate buf.build/agynio/api \
--path agynio/api/apps/v1 \
--path agynio/api/authorization/v1 \
--path agynio/api/identity/v1 \
--path agynio/api/ziti_management/v1 \
--path agynio/api/groups/v1
# The module and paths come from buf.gen.yaml, so the list lives in one place.
RUN buf generate

COPY . .

Expand Down
3 changes: 3 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ inputs:
- agynio/api/identity/v1
- agynio/api/ziti_management/v1
- agynio/api/groups/v1
# Agents and LLM own the entities an x-agyn-ref names.
- agynio/api/agents/v1
- agynio/api/llm/v1
20 changes: 20 additions & 0 deletions cmd/apps-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"os/signal"
"syscall"

agentsv1 "github.com/agynio/apps/.gen/go/agynio/api/agents/v1"
appsv1 "github.com/agynio/apps/.gen/go/agynio/api/apps/v1"
authorizationv1 "github.com/agynio/apps/.gen/go/agynio/api/authorization/v1"
groupsv1 "github.com/agynio/apps/.gen/go/agynio/api/groups/v1"
identityv1 "github.com/agynio/apps/.gen/go/agynio/api/identity/v1"
llmv1 "github.com/agynio/apps/.gen/go/agynio/api/llm/v1"
zitimanagementv1 "github.com/agynio/apps/.gen/go/agynio/api/ziti_management/v1"
"github.com/jackc/pgx/v5/pgxpool"
"google.golang.org/grpc"
Expand Down Expand Up @@ -78,6 +80,18 @@ func run() error {
}
defer groupsConn.Close()

agentsConn, err := grpc.NewClient(cfg.AgentsGRPCTarget, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("connect to agents: %w", err)
}
defer agentsConn.Close()

llmConn, err := grpc.NewClient(cfg.LLMGRPCTarget, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("connect to llm: %w", err)
}
defer llmConn.Close()

grpcServer := grpc.NewServer()
serverInstance := server.NewWithGroups(
store.New(pool),
Expand All @@ -86,6 +100,12 @@ func run() error {
zitimanagementv1.NewZitiManagementServiceClient(zitiConn),
groupsv1.NewGroupsServiceClient(groupsConn),
)
// Without a resolver an installation carrying an x-agyn-ref is refused
// rather than stored unvalidated.
serverInstance.SetReferenceResolver(server.NewServiceReferenceResolver(
agentsv1.NewAgentsServiceClient(agentsConn),
llmv1.NewLLMServiceClient(llmConn),
))
appsv1.RegisterAppsServiceServer(grpcServer, serverInstance)

serverInstance.StartGroupMembershipConsumerLoop(ctx, cfg.NATSURL, cfg.GroupSyncDurable)
Expand Down
9 changes: 2 additions & 7 deletions devspace.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: v2beta1

vars:
APPS_NAMESPACE: platform
APPS_NAMESPACE: agyn-platform

functions:
patch_deployment: |-
Expand Down Expand Up @@ -101,12 +101,7 @@ pipelines:
echo "Using go: ${GO_BIN}"
"${GO_BIN}" version
cd /opt/app/data
buf generate buf.build/agynio/api \
--path agynio/api/apps/v1 \
--path agynio/api/authorization/v1 \
--path agynio/api/identity/v1 \
--path agynio/api/ziti_management/v1 \
--path agynio/api/groups/v1
buf generate
nohup "${GO_BIN}" run ./cmd/apps-service >/tmp/apps-service.log 2>&1 &
'
echo "Waiting for apps to be healthy on :50051..."
Expand Down
17 changes: 14 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ type Config struct {
AuthorizationGRPCTarget string
ZitiManagementGRPCTarget string
GroupsGRPCTarget string
NATSURL string
GroupSyncDurable string
ReconciliationInterval time.Duration
// Agents and LLM own the entities an x-agyn-ref names.
AgentsGRPCTarget string
LLMGRPCTarget string
NATSURL string
GroupSyncDurable string
ReconciliationInterval time.Duration
}

func FromEnv() (Config, error) {
Expand Down Expand Up @@ -44,6 +47,14 @@ func FromEnv() (Config, error) {
if cfg.GroupsGRPCTarget == "" {
cfg.GroupsGRPCTarget = "groups:50051"
}
cfg.AgentsGRPCTarget = os.Getenv("AGENTS_GRPC_TARGET")
if cfg.AgentsGRPCTarget == "" {
cfg.AgentsGRPCTarget = "agents:50051"
}
cfg.LLMGRPCTarget = os.Getenv("LLM_GRPC_TARGET")
if cfg.LLMGRPCTarget == "" {
cfg.LLMGRPCTarget = "llm:50051"
}
cfg.NATSURL = os.Getenv("NATS_URL")
if cfg.NATSURL == "" {
cfg.NATSURL = "nats://nats:4222"
Expand Down
145 changes: 145 additions & 0 deletions internal/schema/compatibility.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package schema

import "fmt"

// CarriedCount reports how many installations of the app hold a value for a
// configuration key. A deprecated property may be removed only once nothing
// carries it, which is a question only the Apps Service can answer because it
// spans organizations the reporting app cannot see.
type CarriedCount func(key string) (int, error)

// CheckCompatible reports whether s still accepts every configuration prev
// accepted. A schema is a contract with configuration that already exists in
// organizations the app's author cannot reach and cannot migrate, so narrowing
// it is refused rather than discovered one organization at a time.
func (s *Schema) CheckCompatible(prev *Schema, carried CarriedCount) error {
if prev == nil {
return nil // first report: nothing to be compatible with
}

for _, name := range prev.Names {
before := prev.Properties[name]
after, kept := s.Properties[name]
if !kept {
if !before.Deprecated {
return fmt.Errorf("property %q was removed; mark it deprecated instead", name)
}
n, err := carried(name)
if err != nil {
return fmt.Errorf("property %q: cannot check whether installations still carry it: %w", name, err)
}
if n > 0 {
return fmt.Errorf("deprecated property %q cannot be removed: %d installation(s) still carry it", name, n)
}
continue
}
if err := compareProperty(before, after); err != nil {
return err
}
}

for _, name := range s.Required {
if _, existed := prev.Properties[name]; !existed {
continue // a brand new property may be required; nothing stored lacks it
}
if !prev.isRequired(name) {
return fmt.Errorf("property %q became required; configurations written without it would stop validating", name)
}
}
return nil
}

func compareProperty(before, after *Property) error {
name := before.Name
if before.Type != after.Type {
return fmt.Errorf("property %q changed type from %s to %s; add a new property and deprecate this one", name, before.Type, after.Type)
}
if before.ItemsType != after.ItemsType {
return fmt.Errorf("property %q changed its item type from %s to %s", name, before.ItemsType, after.ItemsType)
}
if before.Ref != after.Ref && after.Ref != "" {
if before.Ref == "" {
return fmt.Errorf("property %q gained x-agyn-ref %q; values that name nothing would stop validating", name, after.Ref)
}
return fmt.Errorf("property %q changed x-agyn-ref from %q to %q", name, before.Ref, after.Ref)
}
if err := compareEnum(before, after); err != nil {
return err
}
if before.Pattern != after.Pattern && after.Pattern != "" {
return fmt.Errorf("property %q narrowed its pattern", name)
}
if before.Format != after.Format && after.Format != "" && !isDisplayFormat(after.Format) {
return fmt.Errorf("property %q narrowed its format to %q", name, after.Format)
}
if err := compareBound(name, "minLength", before.MinLength, after.MinLength, true); err != nil {
return err
}
if err := compareBound(name, "maxLength", before.MaxLength, after.MaxLength, false); err != nil {
return err
}
if err := compareBound(name, "minItems", before.MinItems, after.MinItems, true); err != nil {
return err
}
if err := compareBound(name, "maxItems", before.MaxItems, after.MaxItems, false); err != nil {
return err
}
if err := compareFloatBound(name, "minimum", before.Minimum, after.Minimum, true); err != nil {
return err
}
return compareFloatBound(name, "maximum", before.Maximum, after.Maximum, false)
}

func compareEnum(before, after *Property) error {
if len(after.Enum) == 0 {
return nil // dropping an enum widens
}
if len(before.Enum) == 0 {
return fmt.Errorf("property %q gained an enum; values outside it would stop validating", before.Name)
}
allowed := make(map[any]struct{}, len(after.Enum))
for _, v := range after.Enum {
allowed[v] = struct{}{}
}
for _, v := range before.Enum {
if _, ok := allowed[v]; !ok {
return fmt.Errorf("property %q dropped enum value %v", before.Name, v)
}
}
return nil
}

// compareBound rejects a narrowed integer bound. A lower bound narrows by
// rising or by appearing; an upper bound narrows by falling or by appearing.
func compareBound(name, key string, before, after *int, lower bool) error {
if after == nil {
return nil
}
if before == nil {
return fmt.Errorf("property %q gained %s", name, key)
}
if (lower && *after > *before) || (!lower && *after < *before) {
return fmt.Errorf("property %q narrowed %s from %d to %d", name, key, *before, *after)
}
return nil
}

func compareFloatBound(name, key string, before, after *float64, lower bool) error {
if after == nil {
return nil
}
if before == nil {
return fmt.Errorf("property %q gained %s", name, key)
}
if (lower && *after > *before) || (!lower && *after < *before) {
return fmt.Errorf("property %q narrowed %s from %v to %v", name, key, *before, *after)
}
return nil
}

// isDisplayFormat reports whether a format only changes how a client draws the
// field. Gaining one narrows nothing, so it is an ordinary compatible change.
func isDisplayFormat(format string) bool {
_, ok := displayFormats[format]
return ok
}
Loading
Loading