Skip to content

Commit 0052830

Browse files
committed
cli/serve: funnel interactive enablement flow tweaks
1. Add metrics to funnel flow. 2. Stop blocking users from turning off funnels when no longer in their node capabilities. 3. Rename LocalClient.IncrementMetric to IncrementCounter to better callout its usage is only for counter clientmetrics. Updates tailscale/corp#10577 Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
1 parent 8e63d75 commit 0052830

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

client/tailscale/localclient.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,12 @@ func (lc *LocalClient) DaemonMetrics(ctx context.Context) ([]byte, error) {
259259
return lc.get200(ctx, "/localapi/v0/metrics")
260260
}
261261

262-
// IncrementMetric increments the value of a Tailscale daemon's metric by
263-
// the given delta. If the metric has yet to exist, a new counter metric is
264-
// created and initialized to delta.
262+
// IncrementCounter increments the value of a Tailscale daemon's counter
263+
// metric by the given delta. If the metric has yet to exist, a new counter
264+
// metric is created and initialized to delta.
265265
//
266-
// IncrementMetric only supports counter metrics and non-negative delta values.
267-
// Gauge metrics are unsupported.
268-
func (lc *LocalClient) IncrementMetric(ctx context.Context, name string, delta int) error {
266+
// IncrementCounter does not support gauge metrics or negative delta values.
267+
func (lc *LocalClient) IncrementCounter(ctx context.Context, name string, delta int) error {
269268
type metricUpdate struct {
270269
Name string `json:"name"`
271270
Type string `json:"type"`

cmd/tailscale/cli/funnel.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ func (e *serveEnv) runFunnel(ctx context.Context, args []string) error {
9494
}
9595
port := uint16(port64)
9696

97-
if err := e.verifyFunnelEnabled(ctx, st, port); err != nil {
98-
return err
97+
if on {
98+
// Don't block from turning off existing Funnel if
99+
// network configuration/capabilities have changed.
100+
// Only block from starting new Funnels.
101+
if err := e.verifyFunnelEnabled(ctx, st, port); err != nil {
102+
return err
103+
}
99104
}
100105

101106
dnsName := strings.TrimSuffix(st.Self.DNSName, ".")
@@ -176,7 +181,7 @@ func printFunnelWarning(sc *ipn.ServeConfig) {
176181
p, _ := strconv.ParseUint(portStr, 10, 16)
177182
if _, ok := sc.TCP[uint16(p)]; !ok {
178183
warn = true
179-
fmt.Fprintf(os.Stderr, "Warning: funnel=on for %s, but no serve config\n", hp)
184+
fmt.Fprintf(os.Stderr, "\nWarning: funnel=on for %s, but no serve config\n", hp)
180185
}
181186
}
182187
if warn {

cmd/tailscale/cli/serve.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type localServeClient interface {
133133
SetServeConfig(context.Context, *ipn.ServeConfig) error
134134
QueryFeature(ctx context.Context, feature string) (*tailcfg.QueryFeatureResponse, error)
135135
WatchIPNBus(ctx context.Context, mask ipn.NotifyWatchOpt) (*tailscale.IPNBusWatcher, error)
136+
IncrementCounter(ctx context.Context, name string, delta int) error
136137
}
137138

138139
// serveEnv is the environment the serve command runs within. All I/O should be
@@ -796,17 +797,19 @@ func (e *serveEnv) enableFeatureInteractive(ctx context.Context, feature string,
796797
return nil // already enabled
797798
}
798799
if info.Text != "" {
799-
fmt.Fprintln(os.Stdout, info.Text)
800+
fmt.Fprintln(os.Stdout, "\n"+info.Text)
800801
}
801802
if info.URL != "" {
802-
fmt.Fprintln(os.Stdout, "\n "+info.URL)
803+
fmt.Fprintln(os.Stdout, "\n "+info.URL+"\n")
803804
}
804805
if !info.ShouldWait {
806+
e.lc.IncrementCounter(ctx, fmt.Sprintf("%s_not_awaiting_enablement", feature), 1)
805807
// The feature has not been enabled yet,
806808
// but the CLI should not block on user action.
807809
// Once info.Text is printed, exit the CLI.
808810
os.Exit(0)
809811
}
812+
e.lc.IncrementCounter(ctx, fmt.Sprintf("%s_awaiting_enablement", feature), 1)
810813
// Block until feature is enabled.
811814
watchCtx, cancelWatch := context.WithCancel(ctx)
812815
defer cancelWatch()
@@ -816,6 +819,7 @@ func (e *serveEnv) enableFeatureInteractive(ctx context.Context, feature string,
816819
// don't block. We still present the URL in the CLI,
817820
// then close the process. Swallow the error.
818821
log.Fatalf("lost connection to tailscaled: %v", err)
822+
e.lc.IncrementCounter(ctx, fmt.Sprintf("%s_enablement_lost_connection", feature), 1)
819823
return err
820824
}
821825
defer watcher.Close()
@@ -826,11 +830,13 @@ func (e *serveEnv) enableFeatureInteractive(ctx context.Context, feature string,
826830
// Let the user finish enablement then rerun their
827831
// command themselves.
828832
log.Fatalf("lost connection to tailscaled: %v", err)
833+
e.lc.IncrementCounter(ctx, fmt.Sprintf("%s_enablement_lost_connection", feature), 1)
829834
return err
830835
}
831836
if nm := n.NetMap; nm != nil && nm.SelfNode != nil {
832837
if hasRequiredCapabilities(nm.SelfNode.Capabilities) {
833-
fmt.Fprintln(os.Stdout, "\nSuccess.")
838+
e.lc.IncrementCounter(ctx, fmt.Sprintf("%s_enabled", feature), 1)
839+
fmt.Fprintln(os.Stdout, "Success.")
834840
return nil
835841
}
836842
}

cmd/tailscale/cli/serve_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,11 @@ func (lc *fakeLocalServeClient) QueryFeature(ctx context.Context, feature string
893893
}
894894

895895
func (lc *fakeLocalServeClient) WatchIPNBus(ctx context.Context, mask ipn.NotifyWatchOpt) (*tailscale.IPNBusWatcher, error) {
896-
return nil, nil
896+
return nil, nil // unused in tests
897+
}
898+
899+
func (lc *fakeLocalServeClient) IncrementCounter(ctx context.Context, name string, delta int) error {
900+
return nil // unused in tests
897901
}
898902

899903
// exactError returns an error checker that wants exactly the provided want error.

0 commit comments

Comments
 (0)