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

Add govet linter with fieldalignment #1994

Closed

Conversation

pellared
Copy link
Member

@pellared pellared commented Jun 11, 2021

Why

govet's fieldalignment analyzer helps to reduce the memory footprint

Slack thread

Here is what the analyzer detected for the production code:

golangci-lint in .
attribute/iterator.go:33:18: fieldalignment: struct with 88 pointer bytes could be 72 (govet)
type oneIterator struct {
                 ^
attribute/kv.go:24:15: fieldalignment: struct with 64 pointer bytes could be 56 (govet)
type KeyValue struct {
              ^
attribute/value.go:32:12: fieldalignment: struct with 48 pointer bytes could be 24 (govet)
type Value struct {
           ^
attribute/value.go:197:14: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
        var jsonVal struct {
                    ^
internal/global/propagator.go:27:24: fieldalignment: struct with 56 pointer bytes could be 32 (govet)
type textMapPropagator struct {
                       ^
internal/global/trace.go:48:21: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
type tracerProvider struct {
                    ^
internal/global/trace.go:120:13: fieldalignment: struct with 56 pointer bytes could be 40 (govet)
type tracer struct {
            ^
golangci-lint in ./bridge/opencensus
aggregation.go:150:23: fieldalignment: struct with 88 pointer bytes could be 56 (govet)
type ocDistAggregator struct {
                      ^
exporter.go:56:20: fieldalignment: struct with 32 pointer bytes could be 8 (govet)
type checkpointSet struct {
                   ^
golangci-lint in ./bridge/opentracing
bridge.go:82:17: fieldalignment: struct with 48 pointer bytes could be 40 (govet)
type bridgeSpan struct {
                ^
bridge.go:280:22: fieldalignment: struct of size 48 could be 40 (govet)
type bridgeSetTracer struct {
                     ^
bridge.go:304:19: fieldalignment: struct with 88 pointer bytes could be 56 (govet)
type BridgeTracer struct {
                  ^
golangci-lint in ./exporters/metric/prometheus
prometheus.go:41:15: fieldalignment: struct with 88 pointer bytes could be 64 (govet)
type Exporter struct {
              ^
golangci-lint in ./exporters/otlp
otlphttp/driver.go:66:13: fieldalignment: struct with 1088 pointer bytes could be 1040 (govet)
type driver struct {
            ^
otlphttp/driver.go:74:19: fieldalignment: struct with 400 pointer bytes could be 352 (govet)
type signalDriver struct {
                  ^
internal/transform/metric.go:62:13: fieldalignment: struct with 80 pointer bytes could be 72 (govet)
type result struct {
            ^
otlpgrpc/connection.go:40:17: fieldalignment: struct with 440 pointer bytes could be 384 (govet)
type connection struct {
                ^
otlpgrpc/driver.go:42:20: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
type metricsDriver struct {
                   ^
otlpgrpc/driver.go:49:19: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
type tracesDriver struct {
                  ^
internal/otlpconfig/options.go:58:15: fieldalignment: struct with 88 pointer bytes could be 56 (govet)
        SignalConfig struct {
                     ^
internal/otlpconfig/options.go:71:9: fieldalignment: struct with 232 pointer bytes could be 200 (govet)
        Config struct {
               ^
golangci-lint in ./exporters/otlp/otlptrace
internal/connection/connection.go:39:17: fieldalignment: struct with 344 pointer bytes could be 288 (govet)
type Connection struct {
                ^
internal/otlpconfig/options.go:53:15: fieldalignment: struct with 88 pointer bytes could be 56 (govet)
        SignalConfig struct {
                     ^
internal/otlpconfig/options.go:66:9: fieldalignment: struct with 136 pointer bytes could be 112 (govet)
        Config struct {
               ^
golangci-lint in ./exporters/otlp/otlptrace/otlptracegrpc
client.go:34:13: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
type client struct {
            ^
golangci-lint in ./exporters/otlp/otlptrace/otlptracehttp
client.go:61:13: fieldalignment: struct with 304 pointer bytes could be 256 (govet)
type client struct {
            ^
golangci-lint in ./exporters/stdout
config.go:34:13: fieldalignment: struct of size 48 could be 40 (govet)
type config struct {
            ^
exporter.go:22:15: fieldalignment: struct with 120 pointer bytes could be 88 (govet)
type Exporter struct {
              ^
metric.go:36:11: fieldalignment: struct with 104 pointer bytes could be 96 (govet)
type line struct {
          ^
golangci-lint in ./exporters/trace/jaeger
agent.go:36:21: fieldalignment: struct with 88 pointer bytes could be 80 (govet)
type agentClientUDP struct {
                    ^
agent.go:53:27: fieldalignment: struct with 48 pointer bytes could be 32 (govet)
type agentClientUDPParams struct {
                          ^
jaeger.go:72:15: fieldalignment: struct with 48 pointer bytes could be 32 (govet)
type Exporter struct {
              ^
reconnecting_udp_client.go:28:26: fieldalignment: struct with 96 pointer bytes could be 56 (govet)
type reconnectingUDPConn struct {
                         ^
uploader.go:176:30: fieldalignment: struct with 56 pointer bytes could be 48 (govet)
type collectorEndpointConfig struct {
                             ^
uploader.go:264:24: fieldalignment: struct with 56 pointer bytes could be 48 (govet)
type collectorUploader struct {
                       ^
golangci-lint in ./exporters/trace/zipkin
zipkin_test.go:78:26: fieldalignment: struct with 80 pointer bytes could be 48 (govet)
type mockZipkinCollector struct {
                         ^
golangci-lint in ./internal/metric
async.go:42:27: fieldalignment: struct with 64 pointer bytes could be 40 (govet)
type AsyncInstrumentState struct {
                          ^
global/meter.go:54:20: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
type meterProvider struct {
                   ^
global/meter.go:65:16: fieldalignment: struct with 48 pointer bytes could be 40 (govet)
type meterImpl struct {
               ^
global/meter.go:88:16: fieldalignment: struct with 112 pointer bytes could be 104 (govet)
type asyncImpl struct {
               ^
golangci-lint in ./metric
registry/registry.go:36:32: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
type uniqueInstrumentMeterImpl struct {
                               ^
metric.go:522:17: fieldalignment: struct with 80 pointer bytes could be 72 (govet)
type Descriptor struct {
                ^
metric_instrument.go:96:18: fieldalignment: struct with 24 pointer bytes could be 16 (govet)
type Observation struct {
                 ^
metric_instrument.go:280:20: fieldalignment: struct with 64 pointer bytes could be 56 (govet)
type BatchObserver struct {
                   ^
metric_instrument.go:390:18: fieldalignment: struct with 24 pointer bytes could be 16 (govet)
type Measurement struct {
                 ^
metrictest/meter.go:35:8: fieldalignment: struct with 72 pointer bytes could be 64 (govet)
        Batch struct {
              ^
metrictest/meter.go:44:12: fieldalignment: struct with 40 pointer bytes could be 16 (govet)
        MeterImpl struct {
                  ^
metrictest/meter.go:52:14: fieldalignment: struct with 24 pointer bytes could be 16 (govet)
        Measurement struct {
                    ^
metrictest/meter.go:63:8: fieldalignment: struct with 112 pointer bytes could be 104 (govet)
        Async struct {
              ^
metrictest/meter.go:198:15: fieldalignment: struct with 56 pointer bytes could be 48 (govet)
type Measured struct {
              ^
golangci-lint in ./oteltest
config.go:99:19: fieldalignment: struct with 80 pointer bytes could be 32 (govet)
type SpanRecorder struct {
                  ^
event.go:24:12: fieldalignment: struct with 48 pointer bytes could be 40 (govet)
type Event struct {
           ^
provider.go:27:21: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
type TracerProvider struct {
                    ^
span.go:32:11: fieldalignment: struct of size 264 could be 256 (govet)
type Span struct {
          ^
text_map_propagator.go:32:21: fieldalignment: struct with 64 pointer bytes could be 40 (govet)
type TextMapCarrier struct {
                    ^
tracer.go:28:13: fieldalignment: struct with 40 pointer bytes could be 32 (govet)
type Tracer struct {
            ^
golangci-lint in ./sdk
trace/batch_span_processor.go:68:25: fieldalignment: struct with 144 pointer bytes could be 48 (govet)
type batchSpanProcessor struct {
                        ^
trace/event.go:24:12: fieldalignment: struct with 72 pointer bytes could be 48 (govet)
type Event struct {
           ^
trace/id_generator.go:33:24: fieldalignment: struct with 16 pointer bytes could be 8 (govet)
type randomIDGenerator struct {
                       ^
trace/provider.go:35:27: fieldalignment: struct with 104 pointer bytes could be 48 (govet)
type tracerProviderConfig struct {
                          ^
trace/provider.go:56:21: fieldalignment: struct with 112 pointer bytes could be 64 (govet)
type TracerProvider struct {
                    ^
trace/sampling.go:33:25: fieldalignment: struct with 88 pointer bytes could be 64 (govet)
type SamplingParameters struct {
                        ^
trace/sampling.go:60:21: fieldalignment: struct with 40 pointer bytes could be 32 (govet)
type SamplingResult struct {
                    ^
trace/sampling.go:66:26: fieldalignment: struct with 16 pointer bytes could be 8 (govet)
type traceIDRatioSampler struct {
                         ^
trace/simple_span_processor.go:26:26: fieldalignment: struct with 40 pointer bytes could be 16 (govet)
type simpleSpanProcessor struct {
                         ^
trace/snapshot.go:28:15: fieldalignment: struct with 376 pointer bytes could be 320 (govet)
type snapshot struct {
              ^
trace/span.go:98:11: fieldalignment: struct with 336 pointer bytes could be 288 (govet)
type span struct {
          ^
trace/span.go:625:13: fieldalignment: struct with 16 pointer bytes could be 8 (govet)
type Status struct {
            ^
trace/trace_test.go:163:18: fieldalignment: struct with 32 pointer bytes could be 16 (govet)
type testSampler struct {
                 ^
trace/tracetest/span.go:57:15: fieldalignment: struct with 376 pointer bytes could be 320 (govet)
type SpanStub struct {
              ^
trace/tracetest/span.go:124:19: fieldalignment: struct with 392 pointer bytes could be 336 (govet)
type spanSnapshot struct {
                  ^
resource/builtin.go:43:17: fieldalignment: struct with 40 pointer bytes could be 32 (govet)
        stringDetector struct {
                       ^
resource/config.go:24:13: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
type config struct {
            ^
golangci-lint in ./sdk/export/metric
metrictest/test.go:39:20: fieldalignment: struct with 64 pointer bytes could be 24 (govet)
type CheckpointSet struct {
                   ^
aggregation/aggregation.go:78:8: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
        Point struct {
              ^
golangci-lint in ./sdk/metric
controller/basic/config.go:26:13: fieldalignment: struct with 40 pointer bytes could be 24 (govet)
type config struct {
            ^
controller/basic/controller.go:57:17: fieldalignment: struct with 160 pointer bytes could be 112 (govet)
type Controller struct {
                ^
sdk.go:44:14: fieldalignment: struct with 120 pointer bytes could be 80 (govet)
        Accumulator struct {
                    ^
sdk.go:87:9: fieldalignment: struct with 112 pointer bytes could be 72 (govet)
        record struct {
               ^
sdk.go:130:18: fieldalignment: struct with 104 pointer bytes could be 96 (govet)
        asyncInstrument struct {
                        ^
sdk.go:137:18: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
        labeledRecorder struct {
                        ^
processor/basic/basic.go:55:13: fieldalignment: struct with 80 pointer bytes could be 64 (govet)
        stateValue struct {
                   ^
processor/basic/basic.go:95:8: fieldalignment: struct with 112 pointer bytes could be 80 (govet)
        state struct {
              ^
aggregator/exact/exact.go:32:13: fieldalignment: struct with 16 pointer bytes could be 8 (govet)
        Aggregator struct {
                   ^
aggregator/lastvalue/lastvalue.go:40:16: fieldalignment: struct with 32 pointer bytes could be 24 (govet)
        lastValueData struct {
                      ^
aggregator/histogram/histogram.go:37:13: fieldalignment: struct with 48 pointer bytes could be 16 (govet)
        Aggregator struct {
                   ^
golangci-lint in ./trace
config.go:139:18: fieldalignment: struct with 48 pointer bytes could be 32 (govet)
type EventConfig struct {
                 ^
trace.go:184:24: fieldalignment: struct of size 64 could be 56 (govet)
type SpanContextConfig struct {
                       ^
trace.go:205:18: fieldalignment: struct of size 64 could be 56 (govet)
type SpanContext struct {
                 ^
trace.go:393:11: fieldalignment: struct with 72 pointer bytes could be 64 (govet)
type Link struct {
          ^

What

  • Add govet to golangci-lint configuration
  • Change the lint target to ALWAYS run golangci-lint for all modules (instead of fail-fast)
  • Fix or ignore issues reported in test code

TODO

  • Fix issues reported in production code

@pellared
Copy link
Member Author

The fieldalignment analyzer is very annoying.
Better explained here: atc0005/go-ci#302
I spend hours trying to satisfy the analyzer but I think it is not worth the effort...

@pellared pellared closed this Jun 16, 2021
@pellared pellared deleted the govet-with-fieldalignment branch November 17, 2023 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant