-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Properly handle grpc dial errors in the throttler metric aggregation #18073
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,15 @@ import ( | |
| "github.com/stretchr/testify/require" | ||
| "golang.org/x/exp/maps" | ||
|
|
||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/credentials/insecure" | ||
|
|
||
| "vitess.io/vitess/go/protoutil" | ||
|
|
||
| "vitess.io/vitess/go/vt/grpcclient" | ||
| "vitess.io/vitess/go/vt/topo" | ||
| "vitess.io/vitess/go/vt/vtenv" | ||
| "vitess.io/vitess/go/vt/vttablet/grpctmclient" | ||
| "vitess.io/vitess/go/vt/vttablet/tabletserver/connpool" | ||
| "vitess.io/vitess/go/vt/vttablet/tabletserver/tabletenv" | ||
| "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base" | ||
|
|
@@ -837,6 +843,110 @@ func TestApplyThrottlerConfigAppCheckedMetrics(t *testing.T) { | |
| }) | ||
| } | ||
|
|
||
| func TestIsDialTCPError(t *testing.T) { | ||
| // Verify that IsDialTCPError actually recognizes grpc dial errors | ||
| cc, err := grpcclient.DialContext(t.Context(), ":0", true, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
| require.NoError(t, err) | ||
| defer cc.Close() | ||
|
|
||
| err = cc.Invoke(context.Background(), "/Fail", nil, nil) | ||
|
|
||
| require.True(t, base.IsDialTCPError(err)) | ||
| require.True(t, base.IsDialTCPError(fmt.Errorf("wrapped: %w", err))) | ||
| } | ||
|
Member
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. We should add a
Collaborator
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. Added in a259112
Member
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. hi! can you sign your commit please, the DCO check is failing
Collaborator
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. Done! |
||
|
|
||
| func TestProbeWithUnavailableHost(t *testing.T) { | ||
| throttler := Throttler{ | ||
| throttledApps: cache.New(cache.NoExpiration, 0), | ||
| heartbeatWriter: &FakeHeartbeatWriter{}, | ||
| } | ||
|
|
||
| alias := &topodatapb.TabletAlias{ | ||
| Cell: "cell1", | ||
| Uid: 100, | ||
| } | ||
|
|
||
| // The hostname used here is not routable, so the connection will fail. | ||
| tablet := &topo.TabletInfo{ | ||
| Tablet: &topodatapb.Tablet{ | ||
| Alias: alias, | ||
| Hostname: "192.0.2.0", | ||
| MysqlHostname: "192.0.2.0", | ||
| MysqlPort: 3306, | ||
| PortMap: map[string]int32{"grpc": 5000}, | ||
| Type: topodatapb.TabletType_PRIMARY, | ||
| }, | ||
| } | ||
|
|
||
| probe := &base.Probe{ | ||
| Alias: "cell1-100", | ||
| Tablet: tablet.Tablet, | ||
| CacheMillis: 100, | ||
| } | ||
|
|
||
| tmClient := grpctmclient.NewClient() | ||
|
|
||
| probeFunc := throttler.generateTabletProbeFunction(base.ShardScope, probe) | ||
|
|
||
| metrics := probeFunc(t.Context(), tmClient) | ||
| require.True(t, base.IsDialTCPError(metrics["custom"].Err)) | ||
|
|
||
| tabletResultsMap := base.TabletResultMap{ | ||
| "cell1-100": base.MetricResultMap{ | ||
| "custom": metrics["custom"], | ||
| }, | ||
| } | ||
|
|
||
| worstMetric := base.AggregateTabletMetricResults("custom", tabletResultsMap, 0, true, 0.0) | ||
| require.Equal(t, base.NoHostsMetricResult, worstMetric) | ||
| } | ||
|
|
||
| func TestProbeWithEmptyHostAndPort(t *testing.T) { | ||
| throttler := Throttler{ | ||
| throttledApps: cache.New(cache.NoExpiration, 0), | ||
| heartbeatWriter: &FakeHeartbeatWriter{}, | ||
| } | ||
|
|
||
| alias := &topodatapb.TabletAlias{ | ||
| Cell: "cell1", | ||
| Uid: 100, | ||
| } | ||
|
|
||
| // The hostname used here is not routable, so the connection will fail. | ||
| tablet := &topo.TabletInfo{ | ||
| Tablet: &topodatapb.Tablet{ | ||
| Alias: alias, | ||
| Hostname: "", | ||
| MysqlHostname: "192.0.2.0", | ||
| MysqlPort: 3306, | ||
| PortMap: map[string]int32{"grpc": 0}, | ||
| Type: topodatapb.TabletType_PRIMARY, | ||
| }, | ||
| } | ||
|
|
||
| probe := &base.Probe{ | ||
| Alias: "cell1-100", | ||
| Tablet: tablet.Tablet, | ||
| CacheMillis: 100, | ||
| } | ||
|
|
||
| tmClient := grpctmclient.NewClient() | ||
|
|
||
| probeFunc := throttler.generateTabletProbeFunction(base.ShardScope, probe) | ||
|
|
||
| metrics := probeFunc(t.Context(), tmClient) | ||
| require.True(t, base.IsDialTCPError(metrics["custom"].Err)) | ||
|
|
||
| tabletResultsMap := base.TabletResultMap{ | ||
| "cell1-100": base.MetricResultMap{ | ||
| "custom": metrics["custom"], | ||
| }, | ||
| } | ||
|
|
||
| worstMetric := base.AggregateTabletMetricResults("custom", tabletResultsMap, 0, true, 0.0) | ||
| require.Equal(t, base.NoHostsMetricResult, worstMetric) | ||
| } | ||
|
|
||
| func TestIsAppThrottled(t *testing.T) { | ||
| plusOneHour := time.Now().Add(time.Hour) | ||
| throttler := Throttler{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the logic down here makes any sense, because we never have or had access to a
net.OpErrorhere. I left this in place, but I think this should be removed to be less confusing.