Skip to content
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

[chore] apply fieldalignment linter #9133

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ linters-settings:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf

enable-all: true
# TODO: Enable this and fix the alignment issues.
disable:
- fieldalignment

revive:
# minimal confidence for issues, default is 0.8
Expand Down
6 changes: 3 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

func TestNewContext(t *testing.T) {
testCases := []struct {
desc string
cl Info
desc string
}{
{
desc: "valid client",
Expand All @@ -41,9 +41,9 @@ func TestNewContext(t *testing.T) {

func TestFromContext(t *testing.T) {
testCases := []struct {
desc string
input context.Context
expected Info
input context.Context
desc string
}{
{
desc: "context with client",
Expand Down
29 changes: 14 additions & 15 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@ var ErrInvalidGoMod = errors.New("invalid gomod specification for module")
// Config holds the builder's configuration
type Config struct {
Logger *zap.Logger
SkipGenerate bool `mapstructure:"-"`
SkipCompilation bool `mapstructure:"-"`
SkipGetModules bool `mapstructure:"-"`
LDFlags string `mapstructure:"-"`
Verbose bool `mapstructure:"-"`

Distribution Distribution `mapstructure:"dist"`
Exporters []Module `mapstructure:"exporters"`
Extensions []Module `mapstructure:"extensions"`
Receivers []Module `mapstructure:"receivers"`
Processors []Module `mapstructure:"processors"`
Connectors []Module `mapstructure:"connectors"`
Replaces []string `mapstructure:"replaces"`
Excludes []string `mapstructure:"excludes"`
LDFlags string `mapstructure:"-"`
Distribution Distribution `mapstructure:"dist"`
Receivers []Module `mapstructure:"receivers"`
Exporters []Module `mapstructure:"exporters"`
Extensions []Module `mapstructure:"extensions"`
Processors []Module `mapstructure:"processors"`
Connectors []Module `mapstructure:"connectors"`
Replaces []string `mapstructure:"replaces"`
Excludes []string `mapstructure:"excludes"`
SkipGetModules bool `mapstructure:"-"`
Verbose bool `mapstructure:"-"`
SkipCompilation bool `mapstructure:"-"`
SkipGenerate bool `mapstructure:"-"`
}

// Distribution holds the parameters for the final binary
Expand All @@ -47,10 +46,10 @@ type Distribution struct {
Go string `mapstructure:"go"`
Description string `mapstructure:"description"`
OtelColVersion string `mapstructure:"otelcol_version"`
RequireOtelColModule bool `mapstructure:"-"` // required for backwards-compatibility with builds older than 0.86.0
OutputPath string `mapstructure:"output_path"`
Version string `mapstructure:"version"`
BuildTags string `mapstructure:"build_tags"`
RequireOtelColModule bool `mapstructure:"-"` // required for backwards-compatibility with builds older than 0.86.0
DebugCompilation bool `mapstructure:"debug_compilation"`
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/builder/internal/builder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func TestModuleFromCore(t *testing.T) {

func TestInvalidModule(t *testing.T) {
type invalidModuleTest struct {
cfg Config
err error
cfg Config
}
// prepare
configurations := []invalidModuleTest{
Expand Down
2 changes: 1 addition & 1 deletion cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func TestGenerateAndCompile(t *testing.T) {
}

testCases := []struct {
testCase string
cfgBuilder func(t *testing.T) Config
testCase string
}{
{
testCase: "Default Configuration Compilation",
Expand Down
4 changes: 2 additions & 2 deletions cmd/builder/internal/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

func TestCommand(t *testing.T) {
tests := []struct {
name string
want *cobra.Command
name string
wantErr bool
}{
{
Expand Down Expand Up @@ -242,8 +242,8 @@ func Test_initConfig(t *testing.T) {
flags *flag.FlagSet
}
tests := []struct {
name string
args args
name string
wantErr bool
}{
{
Expand Down
2 changes: 1 addition & 1 deletion component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (f CreateDefaultConfigFunc) CreateDefaultConfig() Config {

// InstanceID uniquely identifies a component instance
type InstanceID struct {
PipelineIDs map[ID]struct{}
ID ID
Kind Kind
PipelineIDs map[ID]struct{}
}
4 changes: 2 additions & 2 deletions component/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type configChildMapKey struct {
}

type configChildTypeDef struct {
Child errType
ChildPtr *errType
Child errType
}

type errConfig struct {
Expand Down Expand Up @@ -71,9 +71,9 @@ func newErrMapType() *errMapType {

func TestValidateConfig(t *testing.T) {
var tests = []struct {
name string
cfg any
expected error
name string
}{
{
name: "struct",
Expand Down
2 changes: 1 addition & 1 deletion component/identifiable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func TestMarshalText(t *testing.T) {

func TestUnmarshalText(t *testing.T) {
var testCases = []struct {
expectedID ID
idStr string
expectedErr bool
expectedID ID
}{
{
idStr: "valid_type",
Expand Down
4 changes: 2 additions & 2 deletions component/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func (s Status) String() string {

// StatusEvent contains a status and timestamp, and can contain an error
type StatusEvent struct {
status Status
err error
timestamp time.Time
err error
status Status
}

// Status returns the Status (enum) associated with the StatusEvent
Expand Down
4 changes: 2 additions & 2 deletions component/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestStatusEventsWithError(t *testing.T) {

func TestAggregateStatus(t *testing.T) {
for _, tc := range []struct {
name string
statusMap map[*InstanceID]*StatusEvent
name string
expectedStatus Status
}{
{
Expand Down Expand Up @@ -188,9 +188,9 @@ func TestAggregateStatusEvent(t *testing.T) {
}

for _, tc := range []struct {
name string
statusMap map[*InstanceID]*StatusEvent
expectedStatus *StatusEvent
name string
}{
{
name: "FatalError - existing event",
Expand Down
42 changes: 15 additions & 27 deletions component/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,20 @@ import (
// this struct with the exception of ReportComponentStatus. When adding or removing anything from
// this struct consider whether or not the same should be done for the service version.
type TelemetrySettings struct {
// Logger that the factory can use during creation and can pass to the created
// component to be used later as well.
Logger *zap.Logger

// TracerProvider that the factory can pass to other instrumented third-party libraries.
TracerProvider trace.TracerProvider

// MeterProvider that the factory can pass to other instrumented third-party libraries.
MeterProvider metric.MeterProvider

// MetricsLevel controls the level of detail for metrics emitted by the collector.
// Experimental: *NOTE* this field is experimental and may be changed or removed.
MetricsLevel configtelemetry.Level

// Resource contains the resource attributes for the collector's telemetry.
Resource pcommon.Resource

// ReportComponentStatus allows a component to report runtime changes in status. The service
// will automatically report status for a component during startup and shutdown. Components can
// use this method to report status after start and before shutdown. ReportComponentStatus
// will only return errors if the API used incorrectly. The two scenarios where an error will
// be returned are:
//
// - An illegal state transition
// - Calling this method before component startup
//
// If the API is being used properly, these errors are safe to ignore.
TracerProvider trace.TracerProvider
MeterProvider metric.MeterProvider
Resource pcommon.Resource
Logger *zap.Logger
ReportComponentStatus StatusFunc
MetricsLevel configtelemetry.Level
}

// Deprecated: [0.91.0] Use TelemetrySettings directly
type TelemetrySettingsBase[T any] struct {
TracerProvider trace.TracerProvider
MeterProvider metric.MeterProvider
Resource pcommon.Resource
ReportComponentStatus T
Logger *zap.Logger
MetricsLevel configtelemetry.Level
}
4 changes: 2 additions & 2 deletions config/configauth/configauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

func TestGetServer(t *testing.T) {
testCases := []struct {
desc string
authenticator extension.Extension
expected error
desc string
}{
{
desc: "obtain server authenticator",
Expand Down Expand Up @@ -66,9 +66,9 @@ func TestGetServerFails(t *testing.T) {

func TestGetClient(t *testing.T) {
testCases := []struct {
desc string
authenticator extension.Extension
expected error
desc string
}{
{
desc: "obtain client authenticator",
Expand Down
62 changes: 22 additions & 40 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,36 @@ type KeepaliveClientConfig struct {

// GRPCClientSettings defines common settings for a gRPC client configuration.
type GRPCClientSettings struct {
// The keepalive parameters for gRPC client. See grpc.WithKeepaliveParams.
// (https://godoc.org/google.golang.org/grpc#WithKeepaliveParams).
Keepalive *KeepaliveClientConfig `mapstructure:"keepalive"`
// The headers associated with gRPC requests.
Headers map[string]configopaque.String `mapstructure:"headers"`
// Auth configuration for outgoing RPCs.
Auth *configauth.Authentication `mapstructure:"auth"`
// The target to which the exporter is going to send traces or metrics,
// using the gRPC protocol. The valid syntax is described at
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
Endpoint string `mapstructure:"endpoint"`

// The compression key for supported compression types within collector.
Compression configcompression.CompressionType `mapstructure:"compression"`

// Sets the balancer in grpclb_policy to discover the servers. Default is pick_first.
// https://github.com/grpc/grpc-go/blob/master/examples/features/load_balancing/README.md
BalancerName string `mapstructure:"balancer_name"`
// WithAuthority parameter configures client to rewrite ":authority" header
// (godoc.org/google.golang.org/grpc#WithAuthority)
Authority string `mapstructure:"authority"`
// TLSSetting struct exposes TLS client configuration.
TLSSetting configtls.TLSClientSetting `mapstructure:"tls"`

// The keepalive parameters for gRPC client. See grpc.WithKeepaliveParams.
// (https://godoc.org/google.golang.org/grpc#WithKeepaliveParams).
Keepalive *KeepaliveClientConfig `mapstructure:"keepalive"`

// ReadBufferSize for gRPC client. See grpc.WithReadBufferSize.
// (https://godoc.org/google.golang.org/grpc#WithReadBufferSize).
ReadBufferSize int `mapstructure:"read_buffer_size"`

// WriteBufferSize for gRPC gRPC. See grpc.WithWriteBufferSize.
// (https://godoc.org/google.golang.org/grpc#WithWriteBufferSize).
WriteBufferSize int `mapstructure:"write_buffer_size"`

// WaitForReady parameter configures client to wait for ready state before sending data.
// (https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md)
WaitForReady bool `mapstructure:"wait_for_ready"`

// The headers associated with gRPC requests.
Headers map[string]configopaque.String `mapstructure:"headers"`

// Sets the balancer in grpclb_policy to discover the servers. Default is pick_first.
// https://github.com/grpc/grpc-go/blob/master/examples/features/load_balancing/README.md
BalancerName string `mapstructure:"balancer_name"`

// WithAuthority parameter configures client to rewrite ":authority" header
// (godoc.org/google.golang.org/grpc#WithAuthority)
Authority string `mapstructure:"authority"`

// Auth configuration for outgoing RPCs.
Auth *configauth.Authentication `mapstructure:"auth"`
}

// KeepaliveServerConfig is the configuration for keepalive.
Expand Down Expand Up @@ -118,34 +108,26 @@ type KeepaliveEnforcementPolicy struct {

// GRPCServerSettings defines common settings for a gRPC server configuration.
type GRPCServerSettings struct {
// Server net.Addr config. For transport only "tcp" and "unix" are valid options.
NetAddr confignet.NetAddr `mapstructure:",squash"`

// Configures the protocol to use TLS.
// The default value is nil, which will cause the protocol to not use TLS.
TLSSetting *configtls.TLSServerSetting `mapstructure:"tls"`

// Keepalive anchor for all the settings related to keepalive.
Keepalive *KeepaliveServerConfig `mapstructure:"keepalive"`
// Auth for this receiver
Auth *configauth.Authentication `mapstructure:"auth"`
// Server net.Addr config. For transport only "tcp" and "unix" are valid options.
NetAddr confignet.NetAddr `mapstructure:",squash"`
// MaxRecvMsgSizeMiB sets the maximum size (in MiB) of messages accepted by the server.
MaxRecvMsgSizeMiB uint64 `mapstructure:"max_recv_msg_size_mib"`

// MaxConcurrentStreams sets the limit on the number of concurrent streams to each ServerTransport.
// It has effect only for streaming RPCs.
MaxConcurrentStreams uint32 `mapstructure:"max_concurrent_streams"`

// ReadBufferSize for gRPC server. See grpc.ReadBufferSize.
// (https://godoc.org/google.golang.org/grpc#ReadBufferSize).
ReadBufferSize int `mapstructure:"read_buffer_size"`

// WriteBufferSize for gRPC server. See grpc.WriteBufferSize.
// (https://godoc.org/google.golang.org/grpc#WriteBufferSize).
WriteBufferSize int `mapstructure:"write_buffer_size"`

// Keepalive anchor for all the settings related to keepalive.
Keepalive *KeepaliveServerConfig `mapstructure:"keepalive"`

// Auth for this receiver
Auth *configauth.Authentication `mapstructure:"auth"`

// MaxConcurrentStreams sets the limit on the number of concurrent streams to each ServerTransport.
// It has effect only for streaming RPCs.
MaxConcurrentStreams uint32 `mapstructure:"max_concurrent_streams"`
// Include propagates the incoming connection's metadata to downstream consumers.
// Experimental: *NOTE* this option is subject to change or removal in the future.
IncludeMetadata bool `mapstructure:"include_metadata"`
Expand Down
2 changes: 1 addition & 1 deletion config/configgrpc/configgrpc_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func compress(compressor encoding.Compressor, in []byte) ([]byte, error) {
}

type testPayload struct {
name string
message any
marshaler marshaler
name string
}

type marshaler interface {
Expand Down
Loading
Loading