Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 9 additions & 0 deletions xds/internal/xdsclient/clientimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ func newClientImpl(config *bootstrap.Config, metricsRecorder estats.MetricsRecor
return nil, err
}
c := &clientImpl{XDSClient: client, xdsClientConfig: gConfig, bootstrapConfig: config, target: target, refCount: 1}
lrsC, err := lrsclient.New(lrsclient.Config{
Node: c.xdsClientConfig.Node,
TransportBuilder: c.xdsClientConfig.TransportBuilder,
})
if err != nil {
c.logger.Warningf("Failed to create an lrs client to the management server to report load: %v", err)
return nil, err
Copy link
Contributor

@purnesh42H purnesh42H Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have moved it out of report load, we might have think a bit more here. Should error in lrs client creation be fatal? because not everyone is going to use internal xdsclient for load reporting.

Copy link
Contributor

@arjan-bal arjan-bal Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, we should keep the same behaviour as before the xDS client migration changes. If there are certain users who need to ignore LRS client creation failures, we can create a new issue to discuss if the bahviour changes makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to retain the behavior of making LRS client creation failures be fatal. But we might want to change one minor thing in lrsclient.New. Currently it fails if node ID is empty in the configuration. We recently removed that check for the xDS client creation. I'm guessing other languages might not treat this as fatal for LRS creation.

@eshitachandwani : Could you please check what the other languages do and if required remove the check for empty node ID in lrsclient.New. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly , Java is checking for not null here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That check is for the whole node proto or struct. Not just the node ID field.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a private constructor. It's being called from the builder below which sets the id to an empty string by default. In Java empty and null strings are different.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh! Okay! Got it!

}
c.lrsClient = lrsC
c.logger = prefixLogger(c)
return c, nil
}
Expand Down
11 changes: 2 additions & 9 deletions xds/internal/xdsclient/clientimpl_loadreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,8 @@ import (
// It returns a lrsclient.LoadStore for the user to report loads.
func (c *clientImpl) ReportLoad(server *bootstrap.ServerConfig) (*lrsclient.LoadStore, func(context.Context)) {
if c.lrsClient == nil {
lrsC, err := lrsclient.New(lrsclient.Config{
Node: c.xdsClientConfig.Node,
TransportBuilder: c.xdsClientConfig.TransportBuilder,
})
if err != nil {
c.logger.Warningf("Failed to create an lrs client to the management server to report load: %v", server, err)
return nil, func(context.Context) {}
}
c.lrsClient = lrsC
c.logger.Warningf("lrs Client not found")
return nil, func(context.Context) {}
}

load, err := c.lrsClient.ReportLoad(clients.ServerIdentifier{
Expand Down
37 changes: 37 additions & 0 deletions xds/internal/xdsclient/tests/loadreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"fmt"
"net"
"sync"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -437,3 +438,39 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
defer sCancel3()
cancel3(sCtx3)
}

// TestConcurrentReportLoad verifies that the client can safely handle concurrent
// requests to initiate load reporting streams. It launches multiple goroutines
// that all call client.ReportLoad simultaneously.
func (s) TestConcurrentReportLoad(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()

// Create a management server that serves LRS.
mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{SupportLoadReportingService: true})

// Create an xDS client with bootstrap pointing to the above server.
nodeID := uuid.New().String()
bc := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address)
client := createXDSClient(t, bc)

serverConfig, err := bootstrap.ServerConfigForTesting(bootstrap.ServerConfigTestingOptions{URI: mgmtServer.Address})
if err != nil {
t.Fatalf("Failed to create server config for testing: %v", err)
}
// Call ReportLoad() concurrently from multiple go routines.
var wg sync.WaitGroup
const numGoroutines = 10
wg.Add(numGoroutines)
for i := 0; i < numGoroutines; i++ {
go func() {
defer wg.Done()
store, cancelStore := client.ReportLoad(serverConfig)
if store == nil {
t.Errorf("ReportLoad() got nil store, want non-nil")
}
defer cancelStore(ctx)
}()
}
wg.Wait()
}