- Notifications
You must be signed in to change notification settings - Fork914
feat: use Agent v2 API for Service Banner#11806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -18,6 +18,7 @@ import ( | ||
"tailscale.com/tailcfg" | ||
"cdr.dev/slog" | ||
agentproto "github.com/coder/coder/v2/agent/proto" | ||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/coder/coder/v2/codersdk/agentsdk" | ||
drpcsdk "github.com/coder/coder/v2/codersdk/drpc" | ||
@@ -48,6 +49,9 @@ func NewClient(t testing.TB, | ||
} | ||
err := proto.DRPCRegisterTailnet(mux, drpcService) | ||
require.NoError(t, err) | ||
fakeAAPI := NewFakeAgentAPI(t, logger) | ||
err = agentproto.DRPCRegisterAgent(mux, fakeAAPI) | ||
require.NoError(t, err) | ||
server := drpcserver.NewWithOptions(mux, drpcserver.Options{ | ||
Log: func(err error) { | ||
if xerrors.Is(err, io.EOF) { | ||
@@ -64,22 +68,23 @@ func NewClient(t testing.TB, | ||
statsChan: statsChan, | ||
coordinator: coordinator, | ||
server: server, | ||
fakeAgentAPI: fakeAAPI, | ||
derpMapUpdates: derpMapUpdates, | ||
} | ||
} | ||
type Client struct { | ||
t testing.TB | ||
logger slog.Logger | ||
agentID uuid.UUID | ||
manifest agentsdk.Manifest | ||
metadata map[string]agentsdk.Metadata | ||
statsChan chan *agentsdk.Stats | ||
coordinator tailnet.Coordinator | ||
server *drpcserver.Server | ||
fakeAgentAPI *FakeAgentAPI | ||
LastWorkspaceAgentfunc() | ||
PatchWorkspaceLogs func() error | ||
mu sync.Mutex // Protects following. | ||
lifecycleStates []codersdk.WorkspaceAgentLifecycle | ||
@@ -221,20 +226,7 @@ func (c *Client) PatchLogs(ctx context.Context, logs agentsdk.PatchLogs) error { | ||
} | ||
func (c *Client) SetServiceBannerFunc(f func() (codersdk.ServiceBannerConfig, error)) { | ||
c.fakeAgentAPI.SetServiceBannerFunc(f) | ||
} | ||
func (c *Client) PushDERPMapUpdate(update *tailcfg.DERPMap) error { | ||
@@ -254,3 +246,73 @@ type closeFunc func() error | ||
func (c closeFunc) Close() error { | ||
return c() | ||
} | ||
type FakeAgentAPI struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Could you generate this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I could generate it as a Mock, but that won't fit as easily into our existing tests. | ||
sync.Mutex | ||
t testing.TB | ||
logger slog.Logger | ||
getServiceBannerFunc func() (codersdk.ServiceBannerConfig, error) | ||
} | ||
func (*FakeAgentAPI) GetManifest(context.Context, *agentproto.GetManifestRequest) (*agentproto.Manifest, error) { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
func (f *FakeAgentAPI) SetServiceBannerFunc(fn func() (codersdk.ServiceBannerConfig, error)) { | ||
f.Lock() | ||
defer f.Unlock() | ||
f.getServiceBannerFunc = fn | ||
f.logger.Info(context.Background(), "updated ServiceBannerFunc") | ||
} | ||
func (f *FakeAgentAPI) GetServiceBanner(context.Context, *agentproto.GetServiceBannerRequest) (*agentproto.ServiceBanner, error) { | ||
f.Lock() | ||
defer f.Unlock() | ||
if f.getServiceBannerFunc == nil { | ||
return &agentproto.ServiceBanner{}, nil | ||
} | ||
sb, err := f.getServiceBannerFunc() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return agentproto.ServiceBannerFromSDK(sb), nil | ||
} | ||
func (*FakeAgentAPI) UpdateStats(context.Context, *agentproto.UpdateStatsRequest) (*agentproto.UpdateStatsResponse, error) { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
func (*FakeAgentAPI) UpdateLifecycle(context.Context, *agentproto.UpdateLifecycleRequest) (*agentproto.Lifecycle, error) { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
func (*FakeAgentAPI) BatchUpdateAppHealths(context.Context, *agentproto.BatchUpdateAppHealthRequest) (*agentproto.BatchUpdateAppHealthResponse, error) { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
func (*FakeAgentAPI) UpdateStartup(context.Context, *agentproto.UpdateStartupRequest) (*agentproto.Startup, error) { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
func (*FakeAgentAPI) BatchUpdateMetadata(context.Context, *agentproto.BatchUpdateMetadataRequest) (*agentproto.BatchUpdateMetadataResponse, error) { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
func (*FakeAgentAPI) BatchCreateLogs(context.Context, *agentproto.BatchCreateLogsRequest) (*agentproto.BatchCreateLogsResponse, error) { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
func NewFakeAgentAPI(t testing.TB, logger slog.Logger) *FakeAgentAPI { | ||
return &FakeAgentAPI{ | ||
t: t, | ||
logger: logger.Named("FakeAgentAPI"), | ||
} | ||
} |
Uh oh!
There was an error while loading.Please reload this page.