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

Enable Lint Rules: struct-tag & unexported-return #5533

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 0 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ linters-settings:
# investigate, could be real bugs. But didn't recent Go version changed loop variables semantics?
- name: range-val-address
disabled: true
# enable after cleanup: "tag on not-exported field"
- name: struct-tag
disabled: true
# this is idiocy, promotes less readable code. Don't enable.
- name: var-declaration
disabled: true
Expand All @@ -219,9 +216,6 @@ linters-settings:
# "no nested structs are allowed" - don't enable, doesn't make sense
- name: nested-structs
disabled: true
# enable after cleanup
- name: unexported-return
disabled: true
# looks useful, but requires refactoring: "calls to log.Fatal only in main() or init() functions"
- name: deep-exit
disabled: true
Expand Down
12 changes: 6 additions & 6 deletions pkg/config/tlscfg/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Options struct {
MaxVersion string `mapstructure:"max_version"`
SkipHostVerify bool `mapstructure:"skip_host_verify"`
ReloadInterval time.Duration `mapstructure:"reload_interval"`
certWatcher *certWatcher `mapstructure:"-"`
CertWatcher *certWatcher `mapstructure:"-"`
FlamingSaint marked this conversation as resolved.
Show resolved Hide resolved
}

var systemCertPool = x509.SystemCertPool // to allow overriding in unit test
Expand Down Expand Up @@ -102,18 +102,18 @@ func (o *Options) Config(logger *zap.Logger) (*tls.Config, error) {
if err != nil {
return nil, err
}
o.certWatcher = certWatcher
o.CertWatcher = certWatcher

if (o.CertPath == "" && o.KeyPath != "") || (o.CertPath != "" && o.KeyPath == "") {
return nil, fmt.Errorf("for client auth via TLS, either both client certificate and key must be supplied, or neither")
}
if o.CertPath != "" && o.KeyPath != "" {
tlsCfg.GetCertificate = func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
return o.certWatcher.certificate(), nil
return o.CertWatcher.certificate(), nil
}
// GetClientCertificate is used on the client side when server is configured with tls.RequireAndVerifyClientCert e.g. mTLS
tlsCfg.GetClientCertificate = func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
return o.certWatcher.certificate(), nil
return o.CertWatcher.certificate(), nil
}
}

Expand Down Expand Up @@ -169,8 +169,8 @@ var _ io.Closer = (*Options)(nil)

// Close shuts down the embedded certificate watcher.
func (o *Options) Close() error {
if o.certWatcher != nil {
return o.certWatcher.Close()
if o.CertWatcher != nil {
return o.CertWatcher.Close()
}
return nil
}
44 changes: 22 additions & 22 deletions plugin/storage/grpc/shared/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
const BearerTokenKey = "bearer.token"

var (
_ StoragePlugin = (*grpcClient)(nil)
_ ArchiveStoragePlugin = (*grpcClient)(nil)
_ PluginCapabilities = (*grpcClient)(nil)
_ StoragePlugin = (*GRPCClient)(nil)
_ ArchiveStoragePlugin = (*GRPCClient)(nil)
_ PluginCapabilities = (*GRPCClient)(nil)

// upgradeContext composites several steps of upgrading context
upgradeContext = composeContextUpgradeFuncs(upgradeContextWithBearerToken)
)

// grpcClient implements shared.StoragePlugin and reads/writes spans and dependencies
type grpcClient struct {
// GRPCClient implements shared.StoragePlugin and reads/writes spans and dependencies
type GRPCClient struct {
readerClient storage_v1.SpanReaderPluginClient
writerClient storage_v1.SpanWriterPluginClient
archiveReaderClient storage_v1.ArchiveSpanReaderPluginClient
Expand All @@ -57,8 +57,8 @@
streamWriterClient storage_v1.StreamingSpanWriterPluginClient
}

func NewGRPCClient(c *grpc.ClientConn) *grpcClient {
return &grpcClient{
func NewGRPCClient(c *grpc.ClientConn) *GRPCClient {
return &GRPCClient{
readerClient: storage_v1.NewSpanReaderPluginClient(c),
writerClient: storage_v1.NewSpanWriterPluginClient(c),
archiveReaderClient: storage_v1.NewArchiveSpanReaderPluginClient(c),
Expand Down Expand Up @@ -100,34 +100,34 @@
}

// DependencyReader implements shared.StoragePlugin.
func (c *grpcClient) DependencyReader() dependencystore.Reader {
func (c *GRPCClient) DependencyReader() dependencystore.Reader {

Check warning on line 103 in plugin/storage/grpc/shared/grpc_client.go

View check run for this annotation

Codecov / codecov/patch

plugin/storage/grpc/shared/grpc_client.go#L103

Added line #L103 was not covered by tests
return c
}

// SpanReader implements shared.StoragePlugin.
func (c *grpcClient) SpanReader() spanstore.Reader {
func (c *GRPCClient) SpanReader() spanstore.Reader {
return c
}

// SpanWriter implements shared.StoragePlugin.
func (c *grpcClient) SpanWriter() spanstore.Writer {
func (c *GRPCClient) SpanWriter() spanstore.Writer {
return c
}

func (c *grpcClient) StreamingSpanWriter() spanstore.Writer {
func (c *GRPCClient) StreamingSpanWriter() spanstore.Writer {
return newStreamingSpanWriter(c.streamWriterClient)
}

func (c *grpcClient) ArchiveSpanReader() spanstore.Reader {
func (c *GRPCClient) ArchiveSpanReader() spanstore.Reader {
return &archiveReader{client: c.archiveReaderClient}
}

func (c *grpcClient) ArchiveSpanWriter() spanstore.Writer {
func (c *GRPCClient) ArchiveSpanWriter() spanstore.Writer {
return &archiveWriter{client: c.archiveWriterClient}
}

// GetTrace takes a traceID and returns a Trace associated with that traceID
func (c *grpcClient) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
func (c *GRPCClient) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
stream, err := c.readerClient.GetTrace(upgradeContext(ctx), &storage_v1.GetTraceRequest{
TraceID: traceID,
})
Expand All @@ -142,7 +142,7 @@
}

// GetServices returns a list of all known services
func (c *grpcClient) GetServices(ctx context.Context) ([]string, error) {
func (c *GRPCClient) GetServices(ctx context.Context) ([]string, error) {
resp, err := c.readerClient.GetServices(upgradeContext(ctx), &storage_v1.GetServicesRequest{})
if err != nil {
return nil, fmt.Errorf("plugin error: %w", err)
Expand All @@ -152,7 +152,7 @@
}

// GetOperations returns the operations of a given service
func (c *grpcClient) GetOperations(
func (c *GRPCClient) GetOperations(
ctx context.Context,
query spanstore.OperationQueryParameters,
) ([]spanstore.Operation, error) {
Expand Down Expand Up @@ -183,7 +183,7 @@
}

// FindTraces retrieves traces that match the traceQuery
func (c *grpcClient) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
func (c *GRPCClient) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
stream, err := c.readerClient.FindTraces(upgradeContext(ctx), &storage_v1.FindTracesRequest{
Query: &storage_v1.TraceQueryParameters{
ServiceName: query.ServiceName,
Expand Down Expand Up @@ -221,7 +221,7 @@
}

// FindTraceIDs retrieves traceIDs that match the traceQuery
func (c *grpcClient) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
func (c *GRPCClient) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
resp, err := c.readerClient.FindTraceIDs(upgradeContext(ctx), &storage_v1.FindTraceIDsRequest{
Query: &storage_v1.TraceQueryParameters{
ServiceName: query.ServiceName,
Expand All @@ -242,7 +242,7 @@
}

// WriteSpan saves the span
func (c *grpcClient) WriteSpan(ctx context.Context, span *model.Span) error {
func (c *GRPCClient) WriteSpan(ctx context.Context, span *model.Span) error {
_, err := c.writerClient.WriteSpan(ctx, &storage_v1.WriteSpanRequest{
Span: span,
})
Expand All @@ -253,7 +253,7 @@
return nil
}

func (c *grpcClient) Close() error {
func (c *GRPCClient) Close() error {
_, err := c.writerClient.Close(context.Background(), &storage_v1.CloseWriterRequest{})
if err != nil && status.Code(err) != codes.Unimplemented {
return fmt.Errorf("plugin error: %w", err)
Expand All @@ -263,7 +263,7 @@
}

// GetDependencies returns all interservice dependencies
func (c *grpcClient) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
func (c *GRPCClient) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
resp, err := c.depsReaderClient.GetDependencies(ctx, &storage_v1.GetDependenciesRequest{
EndTime: endTs,
StartTime: endTs.Add(-lookback),
Expand All @@ -275,7 +275,7 @@
return resp.Dependencies, nil
}

func (c *grpcClient) Capabilities() (*Capabilities, error) {
func (c *GRPCClient) Capabilities() (*Capabilities, error) {
capabilities, err := c.capabilitiesClient.Capabilities(context.Background(), &storage_v1.CapabilitiesRequest{})
if status.Code(err) == codes.Unimplemented {
return &Capabilities{}, nil
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/grpc/shared/grpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var (
)

type grpcClientTest struct {
client *grpcClient
client *GRPCClient
spanReader *grpcMocks.SpanReaderPluginClient
spanWriter *grpcMocks.SpanWriterPluginClient
archiveReader *grpcMocks.ArchiveSpanReaderPluginClient
Expand All @@ -93,7 +93,7 @@ func withGRPCClient(fn func(r *grpcClientTest)) {
capabilities := new(grpcMocks.PluginCapabilitiesClient)

r := &grpcClientTest{
client: &grpcClient{
client: &GRPCClient{
readerClient: spanReader,
writerClient: spanWriter,
archiveReaderClient: archiveReader,
Expand Down
Loading