Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
handleErr(err, "failed to connect to database")
defer db.Close()

store, err := storesql.NewPostgreSQL(context.Background(), db)
store, err := storesql.NewTenantStore(context.Background(), db)
handleErr(err, "failed to initialize store")

err = http.ListenAndServe(addr, admin.NewServerMux(store))
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.11.2/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ=
github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
Expand Down Expand Up @@ -164,7 +163,6 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg=
Expand Down
4 changes: 2 additions & 2 deletions integration/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func newCLICommand(ctx context.Context, homeDir string, args ...string) *exec.Cm

// newTestStore creates a new isolated database and store for testing.
// The database is automatically dropped when the test completes.
func newTestStore(t *testing.T) store.Store {
func newTestStore(t *testing.T) store.Tenant {
t.Helper()
ctx := t.Context()

Expand All @@ -140,7 +140,7 @@ func newTestStore(t *testing.T) store.Store {
assert.FailNowf(t, "failed to connect to test database", "error: %v", err)
}

s, err := storesql.NewPostgreSQL(ctx, testDB)
s, err := storesql.NewTenantStore(ctx, testDB)
if err != nil {
testDB.Close()
assert.FailNowf(t, "failed to create test store", "error: %v", err)
Expand Down
24 changes: 24 additions & 0 deletions internal/core/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package core

import "github.com/openkcm/krypton/internal/clock"

// AgentRegistrationStatus represents the status of a registry entry.
type AgentRegistrationStatus string

const (
// AgentRegistrationStatusHealthy indicates that the registry is active and healthy.
AgentRegistrationStatusHealthy AgentRegistrationStatus = "healthy"

// AgentRegistrationStatusUnhealthy indicates that the registry is active but unhealthy.
AgentRegistrationStatusUnhealthy AgentRegistrationStatus = "unhealthy"
)

// AgentRegistration entries are used to track the status of agents and their heartbeats.
type AgentRegistration struct {
Name string
InstanceID string
Status AgentRegistrationStatus
LastHeartbeat clock.UnixNano
CreatedAt clock.UnixNano
UpdatedAt clock.UnixNano
}
4 changes: 2 additions & 2 deletions pkg/api/admin/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
)

// NewServerMux creates the admin API multiplexer with all routes registered.
func NewServerMux(s store.Store) http.Handler {
func NewServerMux(s store.Tenant) http.Handler {
mux := http.NewServeMux()
a := &admin{store: s}
mux.HandleFunc("POST "+PathTenants, a.createTenant)
Expand All @@ -26,7 +26,7 @@ func NewServerMux(s store.Store) http.Handler {
}

type admin struct {
store store.Store
store store.Tenant
}

type (
Expand Down
10 changes: 9 additions & 1 deletion pkg/api/agents/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,32 @@ import (
type Client struct {
baseURL string
agentName string
agentID string
cli *krhttp.Client
}

var (
ErrAgentNameEmpty = errors.New("agent name cannot be empty")
ErrAgentNotFound = errors.New("agent not found in topology")
ErrAgentIDEmpty = errors.New("agent ID cannot be empty")
)

// NewClient creates a new Client with the given base URL and agent name.
func NewClient(baseURL, agentName string) (*Client, error) {
func NewClient(baseURL, agentName, agentID string) (*Client, error) {
if agentName == "" {
return nil, ErrAgentNameEmpty
}
if agentID == "" {
return nil, ErrAgentIDEmpty
}

if baseURL == "" {
return nil, api.ErrBaseURLEmpty
}
return &Client{
baseURL: baseURL,
agentName: agentName,
agentID: agentID,
cli: krhttp.NewClient(),
}, nil
}
Expand All @@ -51,6 +58,7 @@ func (c *Client) Register(ctx context.Context, req RegisterRequest) (RegisterRes
}
httpReq.Header.Set("Content-Type", "application/json")
httpReq.Header.Set(AgentNameHeader, c.agentName)
httpReq.Header.Set(AgentIDHeader, c.agentID)

httpResp, err := c.cli.Do(httpReq)
if err != nil {
Expand Down
Loading
Loading