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
10 changes: 7 additions & 3 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3470,7 +3470,11 @@ func TestAgent_Metrics_SSH(t *testing.T) {
registry := prometheus.NewRegistry()

//nolint:dogsled
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{
// Make sure we always get a DERP connection for
// currently_reachable_peers.
DisableDirectConnections: true,
}, 0, func(_ *agenttest.Client, o *agent.Options) {
o.PrometheusRegistry = registry
})

Expand Down Expand Up @@ -3524,7 +3528,7 @@ func TestAgent_Metrics_SSH(t *testing.T) {
{
Name: "coderd_agentstats_currently_reachable_peers",
Type: proto.Stats_Metric_GAUGE,
Value: 0,
Value: 1,
Labels: []*proto.Stats_Metric_Label{
{
Name: "connection_type",
Expand All @@ -3535,7 +3539,7 @@ func TestAgent_Metrics_SSH(t *testing.T) {
{
Name: "coderd_agentstats_currently_reachable_peers",
Type: proto.Stats_Metric_GAUGE,
Value: 1,
Value: 0,
Labels: []*proto.Stats_Metric_Label{
{
Name: "connection_type",
Expand Down
2 changes: 1 addition & 1 deletion cli/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func summarizeBundle(inv *serpent.Invocation, bun *support.Bundle) {

clientNetcheckSummary := bun.Network.Netcheck.Summarize("Client netcheck:", docsURL)
if len(clientNetcheckSummary) > 0 {
cliui.Warn(inv.Stdout, "Networking issues detected:", deployHealthSummary...)
cliui.Warn(inv.Stdout, "Networking issues detected:", clientNetcheckSummary...)
}
}

Expand Down
6 changes: 6 additions & 0 deletions cryptorand/numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func Int63() (int64, error) {
return rng.Int63(), cs.err
}

// Int63n returns a non-negative integer in [0,maxVal) as an int64.
func Int63n(maxVal int64) (int64, error) {
rng, cs := secureRand()
return rng.Int63n(maxVal), cs.err
}

// Intn returns a non-negative integer in [0,maxVal) as an int.
func Intn(maxVal int) (int, error) {
rng, cs := secureRand()
Expand Down
21 changes: 21 additions & 0 deletions cryptorand/numbers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ func TestInt63(t *testing.T) {
}
}

func TestInt63n(t *testing.T) {
t.Parallel()

for i := 0; i < 20; i++ {
v, err := cryptorand.Int63n(100)
require.NoError(t, err, "unexpected error from Int63n")
t.Logf("value: %v <- random?", v)
require.GreaterOrEqual(t, v, int64(0), "values must be positive")
require.Less(t, v, int64(100), "values must be less than 100")
}

// Ensure Int63n works for int larger than 32 bits
_, err := cryptorand.Int63n(1 << 35)
require.NoError(t, err, "expected Int63n to work for 64-bit int")

// Expect a panic if max is negative
require.PanicsWithValue(t, "invalid argument to Int63n", func() {
cryptorand.Int63n(0)
})
}

func TestIntn(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 2 additions & 2 deletions enterprise/coderd/usage/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func (p *tallymanPublisher) Start() error {
if p.initialDelay <= 0 {
// Pick a random time between tallymanPublishInitialMinimumDelay and
// tallymanPublishInterval.
maxPlusDelay := int(tallymanPublishInterval - tallymanPublishInitialMinimumDelay)
plusDelay, err := cryptorand.Intn(maxPlusDelay)
maxPlusDelay := tallymanPublishInterval - tallymanPublishInitialMinimumDelay
plusDelay, err := cryptorand.Int63n(int64(maxPlusDelay))
if err != nil {
return xerrors.Errorf("could not generate random start delay: %w", err)
}
Expand Down
Loading