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
7 changes: 7 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,13 @@ jobs:
"type": "mrkdwn",
"text": "*View failure:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Click here>"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<@U08TJ4YNCA3> investigate this CI failure. Check logs, search for existing issues, use git blame to find who last modified failing tests, create issue in coder/internal (not public repo), use title format \"flake: TestName\" for flaky tests, and assign to the person from git blame."
}
}
]
}' ${{ secrets.CI_FAILURE_SLACK_WEBHOOK }}
7 changes: 7 additions & 0 deletions .github/workflows/nightly-gauntlet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ jobs:
"type": "mrkdwn",
"text": "*View failure:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Click here>"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<@U08TJ4YNCA3> investigate this CI failure. Check logs, search for existing issues, use git blame to find who last modified failing tests, create issue in coder/internal (not public repo), use title format \"flake: TestName\" for flaky tests, and assign to the person from git blame."
}
}
]
}' ${{ secrets.CI_FAILURE_SLACK_WEBHOOK }}
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ GEN_FILES := \
coderd/database/pubsub/psmock/psmock.go \
agent/agentcontainers/acmock/acmock.go \
agent/agentcontainers/dcspec/dcspec_gen.go \
coderd/httpmw/loggermw/loggermock/loggermock.go
coderd/httpmw/loggermw/loggermock/loggermock.go \
codersdk/workspacesdk/agentconnmock/agentconnmock.go

# all gen targets should be added here and to gen/mark-fresh
gen: gen/db gen/golden-files $(GEN_FILES)
Expand Down Expand Up @@ -686,6 +687,7 @@ gen/mark-fresh:
agent/agentcontainers/acmock/acmock.go \
agent/agentcontainers/dcspec/dcspec_gen.go \
coderd/httpmw/loggermw/loggermock/loggermock.go \
codersdk/workspacesdk/agentconnmock/agentconnmock.go \
"

for file in $$files; do
Expand Down Expand Up @@ -729,6 +731,10 @@ coderd/httpmw/loggermw/loggermock/loggermock.go: coderd/httpmw/loggermw/logger.g
go generate ./coderd/httpmw/loggermw/loggermock/
touch "$@"

codersdk/workspacesdk/agentconnmock/agentconnmock.go: codersdk/workspacesdk/agentconn.go
go generate ./codersdk/workspacesdk/agentconnmock/
touch "$@"

agent/agentcontainers/dcspec/dcspec_gen.go: \
node_modules/.installed \
agent/agentcontainers/dcspec/devContainer.base.schema.json \
Expand Down
14 changes: 7 additions & 7 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2750,9 +2750,9 @@ func TestAgent_Dial(t *testing.T) {

switch l.Addr().Network() {
case "tcp":
conn, err = agentConn.Conn.DialContextTCP(ctx, ipp)
conn, err = agentConn.TailnetConn().DialContextTCP(ctx, ipp)
case "udp":
conn, err = agentConn.Conn.DialContextUDP(ctx, ipp)
conn, err = agentConn.TailnetConn().DialContextUDP(ctx, ipp)
default:
t.Fatalf("unknown network: %s", l.Addr().Network())
}
Expand Down Expand Up @@ -2811,7 +2811,7 @@ func TestAgent_UpdatedDERP(t *testing.T) {
})

// Setup a client connection.
newClientConn := func(derpMap *tailcfg.DERPMap, name string) *workspacesdk.AgentConn {
newClientConn := func(derpMap *tailcfg.DERPMap, name string) workspacesdk.AgentConn {
conn, err := tailnet.NewConn(&tailnet.Options{
Addresses: []netip.Prefix{tailnet.TailscaleServicePrefix.RandomPrefix()},
DERPMap: derpMap,
Expand Down Expand Up @@ -2891,13 +2891,13 @@ func TestAgent_UpdatedDERP(t *testing.T) {

// Connect from a second client and make sure it uses the new DERP map.
conn2 := newClientConn(newDerpMap, "client2")
require.Equal(t, []int{2}, conn2.DERPMap().RegionIDs())
require.Equal(t, []int{2}, conn2.TailnetConn().DERPMap().RegionIDs())
t.Log("conn2 got the new DERPMap")

// If the first client gets a DERP map update, it should be able to
// reconnect just fine.
conn1.SetDERPMap(newDerpMap)
require.Equal(t, []int{2}, conn1.DERPMap().RegionIDs())
conn1.TailnetConn().SetDERPMap(newDerpMap)
require.Equal(t, []int{2}, conn1.TailnetConn().DERPMap().RegionIDs())
t.Log("set the new DERPMap on conn1")
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
Expand Down Expand Up @@ -3264,7 +3264,7 @@ func setupSSHSessionOnPort(
}

func setupAgent(t testing.TB, metadata agentsdk.Manifest, ptyTimeout time.Duration, opts ...func(*agenttest.Client, *agent.Options)) (
*workspacesdk.AgentConn,
workspacesdk.AgentConn,
*agenttest.Client,
<-chan *proto.Stats,
afero.Fs,
Expand Down
8 changes: 8 additions & 0 deletions agent/agentcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,8 @@ func TestAPI(t *testing.T) {

coderBin, err := os.Executable()
require.NoError(t, err)
coderBin, err = filepath.EvalSymlinks(coderBin)
require.NoError(t, err)

mCCLI.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
Containers: []codersdk.WorkspaceAgentContainer{testContainer},
Expand Down Expand Up @@ -2455,6 +2457,8 @@ func TestAPI(t *testing.T) {

coderBin, err := os.Executable()
require.NoError(t, err)
coderBin, err = filepath.EvalSymlinks(coderBin)
require.NoError(t, err)

// Mock the `List` function to always return out test container.
mCCLI.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
Expand Down Expand Up @@ -2549,6 +2553,8 @@ func TestAPI(t *testing.T) {

coderBin, err := os.Executable()
require.NoError(t, err)
coderBin, err = filepath.EvalSymlinks(coderBin)
require.NoError(t, err)

// Mock the `List` function to always return out test container.
mCCLI.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
Expand Down Expand Up @@ -2654,6 +2660,8 @@ func TestAPI(t *testing.T) {

coderBin, err := os.Executable()
require.NoError(t, err)
coderBin, err = filepath.EvalSymlinks(coderBin)
require.NoError(t, err)

// Mock the `List` function to always return our test container.
mCCLI.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
Expand Down
4 changes: 2 additions & 2 deletions cli/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (r *RootCmd) ping() *serpent.Command {
}
defer conn.Close()

derpMap := conn.DERPMap()
derpMap := conn.TailnetConn().DERPMap()

diagCtx, diagCancel := context.WithTimeout(inv.Context(), 30*time.Second)
defer diagCancel()
Expand All @@ -156,7 +156,7 @@ func (r *RootCmd) ping() *serpent.Command {
// Silent ping to determine whether we should show diags
_, didP2p, _, _ := conn.Ping(ctx)

ni := conn.GetNetInfo()
ni := conn.TailnetConn().GetNetInfo()
connDiags := cliui.ConnDiags{
DisableDirect: r.disableDirect,
LocalNetInfo: ni,
Expand Down
2 changes: 1 addition & 1 deletion cli/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (r *RootCmd) portForward() *serpent.Command {
func listenAndPortForward(
ctx context.Context,
inv *serpent.Invocation,
conn *workspacesdk.AgentConn,
conn workspacesdk.AgentConn,
wg *sync.WaitGroup,
spec portForwardSpec,
logger slog.Logger,
Expand Down
4 changes: 2 additions & 2 deletions cli/speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (r *RootCmd) speedtest() *serpent.Command {
if err != nil {
continue
}
status := conn.Status()
status := conn.TailnetConn().Status()
if len(status.Peers()) != 1 {
continue
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func (r *RootCmd) speedtest() *serpent.Command {
outputResult.Intervals[i] = interval
}
}
conn.Conn.SendSpeedtestTelemetry(outputResult.Overall.ThroughputMbits)
conn.TailnetConn().SendSpeedtestTelemetry(outputResult.Overall.ThroughputMbits)
out, err := formatter.Format(inv.Context(), outputResult)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func (r *RootCmd) ssh() *serpent.Command {
}

err = sshSession.Wait()
conn.SendDisconnectedTelemetry()
conn.TailnetConn().SendDisconnectedTelemetry()
if err != nil {
if exitErr := (&gossh.ExitError{}); errors.As(err, &exitErr) {
// Clear the error since it's not useful beyond
Expand Down Expand Up @@ -1364,7 +1364,7 @@ func getUsageAppName(usageApp string) codersdk.UsageAppName {

func setStatsCallback(
ctx context.Context,
agentConn *workspacesdk.AgentConn,
agentConn workspacesdk.AgentConn,
logger slog.Logger,
networkInfoDir string,
networkInfoInterval time.Duration,
Expand Down Expand Up @@ -1437,7 +1437,7 @@ func setStatsCallback(

now := time.Now()
cb(now, now.Add(time.Nanosecond), map[netlogtype.Connection]netlogtype.Counts{}, map[netlogtype.Connection]netlogtype.Counts{})
agentConn.SetConnStatsCallback(networkInfoInterval, 2048, cb)
agentConn.TailnetConn().SetConnStatsCallback(networkInfoInterval, 2048, cb)
return errCh, nil
}

Expand All @@ -1451,13 +1451,13 @@ type sshNetworkStats struct {
UsingCoderConnect bool `json:"using_coder_connect"`
}

func collectNetworkStats(ctx context.Context, agentConn *workspacesdk.AgentConn, start, end time.Time, counts map[netlogtype.Connection]netlogtype.Counts) (*sshNetworkStats, error) {
func collectNetworkStats(ctx context.Context, agentConn workspacesdk.AgentConn, start, end time.Time, counts map[netlogtype.Connection]netlogtype.Counts) (*sshNetworkStats, error) {
latency, p2p, pingResult, err := agentConn.Ping(ctx)
if err != nil {
return nil, err
}
node := agentConn.Node()
derpMap := agentConn.DERPMap()
node := agentConn.TailnetConn().Node()
derpMap := agentConn.TailnetConn().DERPMap()

totalRx := uint64(0)
totalTx := uint64(0)
Expand Down
6 changes: 3 additions & 3 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ func New(options *Options) *API {
})
}

if options.PrometheusRegistry == nil {
options.PrometheusRegistry = prometheus.NewRegistry()
}
if options.Authorizer == nil {
options.Authorizer = rbac.NewCachingAuthorizer(options.PrometheusRegistry)
if buildinfo.IsDev() {
Expand Down Expand Up @@ -381,9 +384,6 @@ func New(options *Options) *API {
if options.FilesRateLimit == 0 {
options.FilesRateLimit = 12
}
if options.PrometheusRegistry == nil {
options.PrometheusRegistry = prometheus.NewRegistry()
}
if options.Clock == nil {
options.Clock = quartz.NewReal()
}
Expand Down
8 changes: 8 additions & 0 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,14 @@ func (q *querier) FetchVolumesResourceMonitorsUpdatedAfter(ctx context.Context,
return q.db.FetchVolumesResourceMonitorsUpdatedAfter(ctx, updatedAt)
}

func (q *querier) FindMatchingPresetID(ctx context.Context, arg database.FindMatchingPresetIDParams) (uuid.UUID, error) {
_, err := q.GetTemplateVersionByID(ctx, arg.TemplateVersionID)
if err != nil {
return uuid.Nil, err
}
return q.db.FindMatchingPresetID(ctx, arg)
}

func (q *querier) GetAPIKeyByID(ctx context.Context, id string) (database.APIKey, error) {
return fetch(q.log, q.auth, q.db.GetAPIKeyByID)(ctx, id)
}
Expand Down
16 changes: 16 additions & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4965,6 +4965,22 @@ func (s *MethodTestSuite) TestPrebuilds() {
template, policy.ActionUse,
).Errors(sql.ErrNoRows)
}))
s.Run("FindMatchingPresetID", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
t1 := testutil.Fake(s.T(), faker, database.Template{})
tv := testutil.Fake(s.T(), faker, database.TemplateVersion{TemplateID: uuid.NullUUID{UUID: t1.ID, Valid: true}})
dbm.EXPECT().FindMatchingPresetID(gomock.Any(), database.FindMatchingPresetIDParams{
TemplateVersionID: tv.ID,
ParameterNames: []string{"test"},
ParameterValues: []string{"test"},
}).Return(uuid.Nil, nil).AnyTimes()
dbm.EXPECT().GetTemplateVersionByID(gomock.Any(), tv.ID).Return(tv, nil).AnyTimes()
dbm.EXPECT().GetTemplateByID(gomock.Any(), t1.ID).Return(t1, nil).AnyTimes()
check.Args(database.FindMatchingPresetIDParams{
TemplateVersionID: tv.ID,
ParameterNames: []string{"test"},
ParameterValues: []string{"test"},
}).Asserts(tv.RBACObject(t1), policy.ActionRead).Returns(uuid.Nil)
}))
s.Run("GetPrebuildMetrics", s.Subtest(func(_ database.Store, check *expects) {
check.Args().
Asserts(rbac.ResourceWorkspace.All(), policy.ActionRead)
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbmetrics/querymetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading