package lrsclient

import "google.golang.org/grpc/xds/internal/clients/lrsclient"

Package lrsclient provides an LRS (Load Reporting Service) client.

See: https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/load_stats/v3/lrs.proto

Index

Types

type Config

type Config struct {
	// Node is the identity of the client application reporting load to the
	// LRS server.
	Node clients.Node

	// TransportBuilder is used to connect to the LRS server.
	TransportBuilder clients.TransportBuilder
}

Config is used to configure an LRS client. After one has been passed to the LRS client's New function, no part of it may modified. A Config may be reused; the lrsclient package will also not modify it.

type LRSClient

type LRSClient struct {
	// contains filtered or unexported fields
}

LRSClient is an LRS (Load Reporting Service) client.

func New

func New(config Config) (*LRSClient, error)

New returns a new LRS Client configured with the provided config.

func (*LRSClient) ReportLoad

func (c *LRSClient) ReportLoad(si clients.ServerIdentifier) (*LoadStore, error)

ReportLoad creates and returns a LoadStore for the caller to report loads using a LoadReportingStream.

Caller must call Stop on the returned LoadStore when they are done reporting load to this server.

type LoadStore

type LoadStore struct {
	// contains filtered or unexported fields
}

A LoadStore aggregates loads for multiple clusters and services that are intended to be reported via LRS.

LoadStore stores loads reported to a single LRS server. Use multiple stores for multiple servers.

It is safe for concurrent use.

func (*LoadStore) ReporterForCluster

func (ls *LoadStore) ReporterForCluster(clusterName, serviceName string) *PerClusterReporter

ReporterForCluster returns the PerClusterReporter for the given cluster and service.

func (*LoadStore) Stop

func (ls *LoadStore) Stop(ctx context.Context)

Stop signals the LoadStore to stop reporting.

Before closing the underlying LRS stream, this method may block until a final load report send attempt completes or the provided context `ctx` expires.

The provided context must have a deadline or timeout set to prevent Stop from blocking indefinitely if the final send attempt fails to complete.

type PerClusterReporter

type PerClusterReporter struct {
	// contains filtered or unexported fields
}

PerClusterReporter records load data pertaining to a single cluster. It provides methods to record call starts, finishes, server-reported loads, and dropped calls.

It is safe for concurrent use.

TODO(purnesh42h): Use regular maps with mutexes instead of sync.Map here. The latter is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex. Neither of these conditions are met here, and we should transition to a regular map with a mutex for better type safety.

func (*PerClusterReporter) CallDropped

func (p *PerClusterReporter) CallDropped(category string)

CallDropped records a call dropped in the LoadStore.

func (*PerClusterReporter) CallFinished

func (p *PerClusterReporter) CallFinished(locality string, err error)

CallFinished records a call finished in the LoadStore.

func (*PerClusterReporter) CallServerLoad

func (p *PerClusterReporter) CallServerLoad(locality, name string, val float64)

CallServerLoad records the server load in the LoadStore.

func (*PerClusterReporter) CallStarted

func (p *PerClusterReporter) CallStarted(locality string)

CallStarted records a call started in the LoadStore.

Source Files

load_store.go logging.go lrs_stream.go lrsclient.go lrsconfig.go

Version
v1.74.0-dev
Published
May 15, 2025
Platform
darwin/amd64
Imports
20 packages
Last checked
1 hour ago

Tools for package owners.