Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix revive identified linter issues: exported #7553

Closed
wants to merge 10 commits into from
2 changes: 2 additions & 0 deletions balancer/endpointsharding/endpointsharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ func (bw *balancerWrapper) UpdateState(state balancer.State) {
bw.es.updateState()
}

// ParseConfig parses the JSON configuration for the endpointsharding balancer.
// It uses the configuration format defined for the gracefulswitch balancer.
func ParseConfig(cfg json.RawMessage) (serviceconfig.LoadBalancingConfig, error) {
return gracefulswitch.ParseConfig(cfg)
}
Expand Down
7 changes: 7 additions & 0 deletions balancer/pickfirst/pickfirst.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,17 @@ func (b *pickfirstBalancer) ResolverError(err error) {
})
}

// Shuffler defines an interface for shuffling a list of addresses.
// This interface is used to control the order in which addresses
// are handled by the load balancer.
type Shuffler interface {
ShuffleAddressListForTesting(n int, swap func(i, j int))
}

// ShuffleAddressListForTesting shuffles the order of a list of addresses
// using the provided swap function. This function is intended for testing
// purposes to simulate different address orders and observe how the load
// balancer behaves under those conditions.
func ShuffleAddressListForTesting(n int, swap func(i, j int)) { rand.Shuffle(n, swap) }

func (b *pickfirstBalancer) UpdateClientConnState(state balancer.ClientConnState) error {
Expand Down
3 changes: 3 additions & 0 deletions credentials/tls/certprovider/pemfile/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import (
)

const (
// PluginName defines the name of the plugin used for file watching
// in the certificate provider configuration. This name is used to
// identify the plugin when registering or parsing configurations.
PluginName = "file_watcher"
defaultRefreshInterval = 10 * time.Minute
)
Expand Down
3 changes: 3 additions & 0 deletions internal/balancer/gracefulswitch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type lbConfig struct {
childConfig serviceconfig.LoadBalancingConfig
}

// ChildName extracts and returns the name of the child balancer from the
// provided LoadBalancingConfig. This function is typically used to identify
// which child balancer is configured within a larger load balancing setup.
func ChildName(l serviceconfig.LoadBalancingConfig) string {
return l.(*lbConfig).childBuilder.Name()
}
Expand Down
14 changes: 14 additions & 0 deletions internal/channelz/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,34 @@ func (c *Channel) id() int64 {
return c.ID
}

// SubChans method returns a copy of the map containing subchannels associated
// with the channel, providing a snapshot of the current subchannels. It ensures
// thread safety by acquiring a read lock before accessing the map.
func (c *Channel) SubChans() map[int64]string {
db.mu.RLock()
defer db.mu.RUnlock()
return copyMap(c.subChans)
}

// NestedChans returns a copy of the map containing nested channels associated
// with the channel, providing a snapshot of the current nested channels.
// It ensures thread safety by acquiring a read lock before accessing the map.
func (c *Channel) NestedChans() map[int64]string {
db.mu.RLock()
defer db.mu.RUnlock()
return copyMap(c.nestedChans)
}

// Trace returns a copy of the ChannelTrace associated with this channel.
// It ensures thread safety by acquiring a read lock before accessing the trace.
func (c *Channel) Trace() *ChannelTrace {
db.mu.RLock()
defer db.mu.RUnlock()
return c.trace.copy()
}

// ChannelMetrics holds various metrics related to the channel, such as its
// current connectivity state, target, and call statistics.
type ChannelMetrics struct {
// The current connectivity state of the channel.
State atomic.Pointer[connectivity.State]
Expand Down Expand Up @@ -142,6 +152,10 @@ func (c *ChannelMetrics) String() string {
)
}

// NewChannelMetricForTesting function is designed to create and initialize a
// ChannelMetrics instance with specified values. This helps in monitoring and
// understanding the channel's behavior and performance, including its
// connectivity state, target address, call statistics, and timestamps.
func NewChannelMetricForTesting(state connectivity.State, target string, started, succeeded, failed, timestamp int64) *ChannelMetrics {
c := &ChannelMetrics{}
c.State.Store(&state)
Expand Down
4 changes: 4 additions & 0 deletions internal/channelz/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func NewServerMetricsForTesting(started, succeeded, failed, timestamp int64) *Se
return sm
}

// CopyFrom copies the atomic values from another ServerMetrics instance into
// the current ServerMetrics instance. It updates the metrics fields to match
// those of the provided instance. This ensures that the current instance
// reflects the same metrics as the source instance.
func (sm *ServerMetrics) CopyFrom(o *ServerMetrics) {
sm.CallsStarted.Store(o.CallsStarted.Load())
sm.CallsSucceeded.Store(o.CallsSucceeded.Load())
Expand Down
10 changes: 10 additions & 0 deletions internal/channelz/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,23 @@ type EphemeralSocketMetrics struct {
RemoteFlowControlWindow int64
}

// SocketType represents the type of a socket, indicating whether it is a normal
// socket or a listening socket.
type SocketType string

const (
// SocketTypeNormal represents a normal socket used for communication.
SocketTypeNormal = "NormalSocket"
// SocketTypeListen represents a listening socket used for accepting
// incoming connections.
SocketTypeListen = "ListenSocket"
)

// Socket represents a network socket and contains various metrics and
// information related to it. It tracks details such as local and remote
// addresses, socket type, metrics, and security settings. The Socket type
// is used for monitoring and managing network connections within the gRPC
// system.
type Socket struct {
Entity
SocketType SocketType
Expand Down
6 changes: 6 additions & 0 deletions internal/channelz/subchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ func (sc *SubChannel) id() int64 {
return sc.ID
}

// Sockets returns a map of socket IDs to their reference names for the
// subchannel. This map includes all sockets currently associated with the
// subchannel.
func (sc *SubChannel) Sockets() map[int64]string {
db.mu.RLock()
defer db.mu.RUnlock()
return copyMap(sc.sockets)
}

// Trace returns a copy of the ChannelTrace for the subchannel. It provides
// insights into the trace events of the subchannel for monitoring and
// debugging purposes.
func (sc *SubChannel) Trace() *ChannelTrace {
db.mu.RLock()
defer db.mu.RUnlock()
Expand Down
5 changes: 5 additions & 0 deletions internal/channelz/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ type TraceEvent struct {
Parent *TraceEvent
}

// ChannelTrace manages a history of trace events for a channel or entity,
// including details like event descriptions, severity, and timestamps.
// It supports adding new events, copying its state, and clearing old entries,
// while maintaining a maximum number of trace entries.

type ChannelTrace struct {
cm *channelMap
clearCalled bool
Expand Down
6 changes: 6 additions & 0 deletions internal/idle/idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ func (m *Manager) tryEnterIdleMode() bool {
return true
}

// EnterIdleModeForTesting forces the Manager into idle mode. This bypasses
// normal idle transition checks and is used to verify idle behavior without
// waiting for timeouts or other conditions.
func (m *Manager) EnterIdleModeForTesting() {
m.tryEnterIdleMode()
}
Expand Down Expand Up @@ -266,6 +269,9 @@ func (m *Manager) isClosed() bool {
return atomic.LoadInt32(&m.closed) == 1
}

// Close stops the idle timer and marks the Manager as closed. It ensures
// that no further activity is processed and cleans up any resources used
// by the Manager. After calling Close, the Manager should not be used.
func (m *Manager) Close() {
atomic.StoreInt32(&m.closed, 1)

Expand Down
2 changes: 2 additions & 0 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ var (
// ExitIdleModeForTesting gets the ClientConn to exit IDLE mode.
ExitIdleModeForTesting any // func(*grpc.ClientConn) error

// ChannelzTurnOffForTesting disables Channelz functionality by setting the
// current state to 0.
ChannelzTurnOffForTesting func()

// TriggerXDSResourceNotFoundForTesting causes the provided xDS Client to
Expand Down
25 changes: 25 additions & 0 deletions internal/stats/metrics_recorder_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func verifyLabels(desc *estats.MetricDescriptor, labelsRecv ...string) {
}
}

// RecordInt64Count records a measurement for an int64 count across all
// metric recorders in the MetricsRecorderList. It increments the count
// associated with the provided handle by the given amount and uses the
// provided labels for the measurement. The labels must match the expected
// labels defined in the handle's descriptor.
func (l *MetricsRecorderList) RecordInt64Count(handle *estats.Int64CountHandle, incr int64, labels ...string) {
verifyLabels(handle.Descriptor(), labels...)

Expand All @@ -62,6 +67,11 @@ func (l *MetricsRecorderList) RecordInt64Count(handle *estats.Int64CountHandle,
}
}

// RecordFloat64Count records a measurement for a float64 count across all
// metric recorders in the MetricsRecorderList. It increments the count
// associated with the provided handle by the given amount and uses the
// provided labels for the measurement. The labels must match the expected
// labels defined in the handle's descriptor.
func (l *MetricsRecorderList) RecordFloat64Count(handle *estats.Float64CountHandle, incr float64, labels ...string) {
verifyLabels(handle.Descriptor(), labels...)

Expand All @@ -70,6 +80,11 @@ func (l *MetricsRecorderList) RecordFloat64Count(handle *estats.Float64CountHand
}
}

// RecordInt64Histo records a measurement for an int64 histogram across all
// metric recorders in the MetricsRecorderList. It increments the histogram
// associated with the provided handle by the given amount and uses the provided
// labels for the measurement. The labels must match the expected labels
// defined in the handle's descriptor.
func (l *MetricsRecorderList) RecordInt64Histo(handle *estats.Int64HistoHandle, incr int64, labels ...string) {
verifyLabels(handle.Descriptor(), labels...)

Expand All @@ -78,6 +93,11 @@ func (l *MetricsRecorderList) RecordInt64Histo(handle *estats.Int64HistoHandle,
}
}

// RecordFloat64Histo records a measurement for a float64 histogram across all
// metric recorders in the MetricsRecorderList. It increments the histogram
// associated with the provided handle by the given amount and uses the provided
// labels for the measurement. The labels must match the expected labels
// defined in the handle's descriptor.
func (l *MetricsRecorderList) RecordFloat64Histo(handle *estats.Float64HistoHandle, incr float64, labels ...string) {
verifyLabels(handle.Descriptor(), labels...)

Expand All @@ -86,6 +106,11 @@ func (l *MetricsRecorderList) RecordFloat64Histo(handle *estats.Float64HistoHand
}
}

// RecordInt64Gauge records a measurement for an int64 gauge across all
// metric recorders in the MetricsRecorderList. It updates the gauge
// associated with the provided handle by the given amount and uses the
// provided labels for the measurement. The labels must match the expected
// labels defined in the handle's descriptor.
func (l *MetricsRecorderList) RecordInt64Gauge(handle *estats.Int64GaugeHandle, incr int64, labels ...string) {
verifyLabels(handle.Descriptor(), labels...)

Expand Down
6 changes: 6 additions & 0 deletions internal/testutils/stats/test_metrics_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ type TestMetricsRecorder struct {
data map[estats.Metric]float64
}

// NewTestMetricsRecorder creates a new instance of TestMetricsRecorder for use
// in tests. It initializes channels for different types of metrics (int64 counts,
// float64 counts, int64 histograms, float64 histograms, and int64 gauges) to
// record and validate metrics events. The provided `metrics` parameter specifies
// the list of metric names to be used for the recorder.

func NewTestMetricsRecorder(t *testing.T) *TestMetricsRecorder {
tmr := &TestMetricsRecorder{
t: t,
Expand Down
2 changes: 2 additions & 0 deletions security/advancedtls/advancedtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import (
credinternal "google.golang.org/grpc/internal/credentials"
)

// CertificateChains represents a slice of certificate chains.This type is used
// to store the certificate chains received during TLS handshakes.
type CertificateChains [][]*x509.Certificate

// HandshakeVerificationInfo contains information about a handshake needed for
Expand Down
Loading