@@ -80,6 +80,8 @@ type Client struct {
8080 retryOption gax.CallOption
8181 executeQueryRetryOption gax.CallOption
8282 enableDirectAccess bool
83+ featureFlagsMD metadata.MD // Pre-computed feature flags metadata to be sent with each request.
84+
8385}
8486
8587// ClientConfig has configurations for the client.
@@ -174,6 +176,9 @@ func NewClientWithConfig(ctx context.Context, project, instance string, config C
174176 executeQueryRetryOption = clientOnlyExecuteQueryRetryOption
175177 }
176178
179+ // Create the feature flags metadata once
180+ ffMD := createFeatureFlagsMD (metricsTracerFactory .enabled , disableRetryInfo , enableDirectAccess )
181+
177182 var connPool gtransport.ConnPool
178183 var connPoolErr error
179184 enableBigtableConnPool := btopt .EnableBigtableConnectionPool ()
@@ -201,6 +206,7 @@ func NewClientWithConfig(ctx context.Context, project, instance string, config C
201206 retryOption : retryOption ,
202207 executeQueryRetryOption : executeQueryRetryOption ,
203208 enableDirectAccess : enableDirectAccess ,
209+ featureFlagsMD : ffMD ,
204210 }, nil
205211}
206212
@@ -414,18 +420,18 @@ type Table struct {
414420 materializedView string
415421}
416422
417- // newFeatureFlags creates the feature flags `bigtable-features` header
418- // to be sent on each request. This includes all features supported and
419- // and enabled on the client
420- func ( c * Client ) newFeatureFlags ( ) metadata.MD {
423+ // createFeatureFlagsMD creates the metadata for the `bigtable-features` header.
424+ // This header is sent on each request and includes all features supported and
425+ // enabled on the client.
426+ func createFeatureFlagsMD ( clientSideMetricsEnabled , disableRetryInfo , enableDirectAccess bool ) metadata.MD {
421427 ff := btpb.FeatureFlags {
422428 RoutingCookie : true ,
423429 ReverseScans : true ,
424430 LastScannedRowResponses : true ,
425- ClientSideMetricsEnabled : c . metricsTracerFactory . enabled ,
426- RetryInfo : ! c . disableRetryInfo ,
427- TrafficDirectorEnabled : c . enableDirectAccess ,
428- DirectAccessRequested : c . enableDirectAccess ,
431+ ClientSideMetricsEnabled : clientSideMetricsEnabled ,
432+ RetryInfo : ! disableRetryInfo ,
433+ TrafficDirectorEnabled : enableDirectAccess ,
434+ DirectAccessRequested : enableDirectAccess ,
429435 }
430436
431437 val := ""
@@ -445,7 +451,7 @@ func (c *Client) Open(table string) *Table {
445451 md : metadata .Join (metadata .Pairs (
446452 resourcePrefixHeader , c .fullTableName (table ),
447453 requestParamsHeader , c .reqParamsHeaderValTable (table ),
448- ), c .newFeatureFlags () ),
454+ ), c .featureFlagsMD ),
449455 }
450456}
451457
@@ -457,7 +463,7 @@ func (c *Client) OpenTable(table string) TableAPI {
457463 md : metadata .Join (metadata .Pairs (
458464 resourcePrefixHeader , c .fullTableName (table ),
459465 requestParamsHeader , c .reqParamsHeaderValTable (table ),
460- ), c .newFeatureFlags () ),
466+ ), c .featureFlagsMD ),
461467 }}
462468}
463469
@@ -469,7 +475,7 @@ func (c *Client) OpenAuthorizedView(table, authorizedView string) TableAPI {
469475 md : metadata .Join (metadata .Pairs (
470476 resourcePrefixHeader , c .fullAuthorizedViewName (table , authorizedView ),
471477 requestParamsHeader , c .reqParamsHeaderValTable (table ),
472- ), c .newFeatureFlags () ),
478+ ), c .featureFlagsMD ),
473479 authorizedView : authorizedView ,
474480 }}
475481}
@@ -481,7 +487,7 @@ func (c *Client) OpenMaterializedView(materializedView string) TableAPI {
481487 md : metadata .Join (metadata .Pairs (
482488 resourcePrefixHeader , c .fullMaterializedViewName (materializedView ),
483489 requestParamsHeader , c .reqParamsHeaderValTable (materializedView ),
484- ), c .newFeatureFlags () ),
490+ ), c .featureFlagsMD ),
485491 materializedView : materializedView ,
486492 }}
487493}
@@ -540,7 +546,7 @@ func (c *Client) PrepareStatement(ctx context.Context, query string, paramTypes
540546 md := metadata .Join (metadata .Pairs (
541547 resourcePrefixHeader , c .fullInstanceName (),
542548 requestParamsHeader , c .reqParamsHeaderValInstance (),
543- ), c .newFeatureFlags () )
549+ ), c .featureFlagsMD )
544550
545551 ctx = mergeOutgoingMetadata (ctx , md )
546552 return c .prepareStatementWithMetadata (ctx , query , paramTypes , opts ... )
@@ -724,7 +730,7 @@ func (bs *BoundStatement) Execute(ctx context.Context, f func(ResultRow) bool, o
724730 md := metadata .Join (metadata .Pairs (
725731 resourcePrefixHeader , bs .ps .c .fullInstanceName (),
726732 requestParamsHeader , bs .ps .c .reqParamsHeaderValInstance (),
727- ), bs .ps .c .newFeatureFlags () )
733+ ), bs .ps .c .featureFlagsMD )
728734 ctx = mergeOutgoingMetadata (ctx , md )
729735
730736 ctx = trace .StartSpan (ctx , "cloud.google.com/go/bigtable.ExecuteQuery" )
@@ -955,7 +961,7 @@ func (c *Client) PingAndWarm(ctx context.Context) (err error) {
955961 md := metadata .Join (metadata .Pairs (
956962 resourcePrefixHeader , c .fullInstanceName (),
957963 requestParamsHeader , c .reqParamsHeaderValInstance (),
958- ), c .newFeatureFlags () )
964+ ), c .featureFlagsMD )
959965
960966 ctx = mergeOutgoingMetadata (ctx , md )
961967 ctx = trace .StartSpan (ctx , "cloud.google.com/go/bigtable/PingAndWarm" )
0 commit comments