Skip to content

Commit d854fca

Browse files
author
Andrii Kushch
committed
add fmtcheck and importcheck to Makefile
1 parent 21ceb0b commit d854fca

File tree

9 files changed

+74
-53
lines changed

9 files changed

+74
-53
lines changed

.circleci/config.yml

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ jobs:
4848
- go-mod-v4-{{ checksum "go.sum" }}
4949
- run:
5050
command: apt-get --allow-releaseinfo-change-suite update -y && apt-get install ca-certificates libgnutls30 -y || true
51+
- run:
52+
command: go install golang.org/x/tools/cmd/goimports@latest || true
53+
- run:
54+
name: Check fmt
55+
command: make fmtcheck
56+
- run:
57+
name: Check imports
58+
command: make importcheck
5159
- run:
5260
name: Run unit tests
5361
environment:

Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ instrumentation/% :
4242
printf "VERSION_TAG_PREFIX ?= $@/v\nGO_MODULE_NAME ?= github.com/instana/go-sensor/$@\n\ninclude ../../Makefile.release\n" > $@/Makefile
4343
printf '// (c) Copyright IBM Corp. %s\n// (c) Copyright Instana Inc. %s\n\npackage %s\n\nconst Version = "0.0.0"\n' $(shell date +%Y) $(shell date +%Y) $(notdir $@) > $@/version.go
4444

45-
.PHONY: test install legal $(MODULES) $(INTEGRATION_TESTS)
45+
fmtcheck:
46+
@test -z $(shell gofmt -l . && exit 1)
47+
48+
importcheck:
49+
@test -z $(shell goimports -l . && exit 1)
50+
51+
.PHONY: test install legal fmtcheck importcheck $(MODULES) $(INTEGRATION_TESTS)
4652

4753
# Release targets
4854
include Makefile.release

autoprofile/internal/pprof/profile/legacy_profile.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,12 @@ func addTracebackSample(l []*Location, s []string, p *Profile) {
335335
//
336336
// The general format for profilez samples is a sequence of words in
337337
// binary format. The first words are a header with the following data:
338-
// 1st word -- 0
339-
// 2nd word -- 3
340-
// 3rd word -- 0 if a c++ application, 1 if a java application.
341-
// 4th word -- Sampling period (in microseconds).
342-
// 5th word -- Padding.
338+
//
339+
// 1st word -- 0
340+
// 2nd word -- 3
341+
// 3rd word -- 0 if a c++ application, 1 if a java application.
342+
// 4th word -- Sampling period (in microseconds).
343+
// 5th word -- Padding.
343344
func parseCPU(b []byte) (*Profile, error) {
344345
var parse func([]byte) (uint64, []byte)
345346
var n1, n2, n3, n4, n5 uint64
@@ -410,15 +411,18 @@ func cpuProfile(b []byte, period int64, parse func(b []byte) (uint64, []byte)) (
410411
//
411412
// profilez samples are a repeated sequence of stack frames of the
412413
// form:
413-
// 1st word -- The number of times this stack was encountered.
414-
// 2nd word -- The size of the stack (StackSize).
415-
// 3rd word -- The first address on the stack.
416-
// ...
417-
// StackSize + 2 -- The last address on the stack
414+
//
415+
// 1st word -- The number of times this stack was encountered.
416+
// 2nd word -- The size of the stack (StackSize).
417+
// 3rd word -- The first address on the stack.
418+
// ...
419+
// StackSize + 2 -- The last address on the stack
420+
//
418421
// The last stack trace is of the form:
419-
// 1st word -- 0
420-
// 2nd word -- 1
421-
// 3rd word -- 0
422+
//
423+
// 1st word -- 0
424+
// 2nd word -- 1
425+
// 3rd word -- 0
422426
//
423427
// Addresses from stack traces may point to the next instruction after
424428
// each call. Optionally adjust by -1 to land somewhere on the actual

env_config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// parseInstanaTags parses the tags string passed via INSTANA_TAGS.
1515
// The tag string is a comma-separated list of keys optionally followed by an '=' character and a string value:
1616
//
17-
// INSTANA_TAGS := key1[=value1][,key2[=value2],...]
17+
// INSTANA_TAGS := key1[=value1][,key2[=value2],...]
1818
//
1919
// The leading and trailing space is truncated from key names, values are used as-is. If a key does not have
2020
// value associated, it's considered to be nil.
@@ -47,7 +47,7 @@ func parseInstanaTags(s string) map[string]interface{} {
4747
// parseInstanaSecrets parses the tags string passed via INSTANA_SECRETS.
4848
// The secrets matcher configuration string is expected to have the following format:
4949
//
50-
// INSTANA_SECRETS := <matcher>:<secret>[,<secret>]
50+
// INSTANA_SECRETS := <matcher>:<secret>[,<secret>]
5151
//
5252
// Where `matcher` is one of:
5353
// * `equals` - matches a string if it's contained in the secrets list
@@ -75,7 +75,7 @@ func parseInstanaSecrets(s string) (Matcher, error) {
7575
// parseInstanaExtraHTTPHeaders parses the tags string passed via INSTANA_EXTRA_HTTP_HEADERS.
7676
// The header names are expected to come in a semicolon-separated list:
7777
//
78-
// INSTANA_EXTRA_HTTP_HEADERS := header1[;header2;...]
78+
// INSTANA_EXTRA_HTTP_HEADERS := header1[;header2;...]
7979
//
8080
// Any leading and trailing whitespace characters will be trimmed from header names.
8181
func parseInstanaExtraHTTPHeaders(s string) []string {

instrumentation/instagrpc/server.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
// This interceptor is responsible for extracting the Instana OpenTracing headers from incoming requests
1919
// and staring a new span that can later be accessed inside the handler:
2020
//
21-
// if parent, ok := instana.SpanFromContext(ctx); ok {
22-
// sp := parent.Tracer().StartSpan("child-span")
23-
// defer sp.Finish()
24-
// }
21+
// if parent, ok := instana.SpanFromContext(ctx); ok {
22+
// sp := parent.Tracer().StartSpan("child-span")
23+
// defer sp.Finish()
24+
// }
2525
//
2626
// If the handler returns an error or panics, the error message is then attached to the span logs.
2727
func UnaryServerInterceptor(sensor *instana.Sensor) grpc.UnaryServerInterceptor {
@@ -51,10 +51,10 @@ func UnaryServerInterceptor(sensor *instana.Sensor) grpc.UnaryServerInterceptor
5151
// This interceptor is responsible for extracting the Instana OpenTracing headers from incoming streaming
5252
// requests and starting a new span that can later be accessed inside the handler:
5353
//
54-
// if parent, ok := instana.SpanFromContext(srv.Context()); ok {
55-
// sp := parent.Tracer().StartSpan("child-span")
56-
// defer sp.Finish()
57-
// }
54+
// if parent, ok := instana.SpanFromContext(srv.Context()); ok {
55+
// sp := parent.Tracer().StartSpan("child-span")
56+
// defer sp.Finish()
57+
// }
5858
//
5959
// If the handler returns an error or panics, the error message is then attached to the span logs.
6060
func StreamServerInterceptor(sensor *instana.Sensor) grpc.StreamServerInterceptor {

instrumentation/instasarama/sync_producer.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,27 @@ func (p *SyncProducer) SendMessage(msg *sarama.ProducerMessage) (int32, int64, e
9292
// In case you want your batch publish operation to be a part of a specific trace, make sure that
9393
// you inject the parent span of this trace explicitly before calling `SendMessages()`, i.e.
9494
//
95-
// type MessageCollector struct {
96-
// CollectedMessages []*sarama.ProducerMessage
97-
// producer *instasarama.SyncProducer
98-
// // ...
99-
// }
95+
// type MessageCollector struct {
96+
// CollectedMessages []*sarama.ProducerMessage
97+
// producer *instasarama.SyncProducer
98+
// // ...
99+
// }
100100
//
101-
// func (c MessageCollector) Flush(ctx context.Context) error {
102-
// // extract the parent span from context and use it to continue the trace
103-
// if parentSpan, ok := instana.SpanFromContext(ctx); ok {
104-
// // start a new span for the batch send job
105-
// sp := parentSpan.Tracer().StartSpan("batch-send", ot.ChilfOf(parentSpan.Context()))
106-
// defer sp.Finish()
101+
// func (c MessageCollector) Flush(ctx context.Context) error {
102+
// // extract the parent span from context and use it to continue the trace
103+
// if parentSpan, ok := instana.SpanFromContext(ctx); ok {
104+
// // start a new span for the batch send job
105+
// sp := parentSpan.Tracer().StartSpan("batch-send", ot.ChilfOf(parentSpan.Context()))
106+
// defer sp.Finish()
107107
//
108-
// // inject the trace context into every collected message, overriding the existing one
109-
// for i, msg := range c.CollectedMessages {
110-
// c.CollectedMessages = instasarama.ProducerMessageWithSpan(msg, sp)
111-
// }
112-
// }
108+
// // inject the trace context into every collected message, overriding the existing one
109+
// for i, msg := range c.CollectedMessages {
110+
// c.CollectedMessages = instasarama.ProducerMessageWithSpan(msg, sp)
111+
// }
112+
// }
113113
//
114-
// return c.producer.SendMessages(c.CollectedMessages)
115-
// }
114+
// return c.producer.SendMessages(c.CollectedMessages)
115+
// }
116116
func (p *SyncProducer) SendMessages(msgs []*sarama.ProducerMessage) error {
117117
if len(msgs) == 0 {
118118
return nil

recorder.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ func (r *Recorder) RecordSpan(span *spanS) {
8181
}
8282

8383
// QueuedSpansCount returns the number of queued spans
84-
// Used only in tests currently.
84+
//
85+
// Used only in tests currently.
8586
func (r *Recorder) QueuedSpansCount() int {
8687
r.RLock()
8788
defer r.RUnlock()
@@ -124,10 +125,11 @@ func (r *Recorder) Flush(ctx context.Context) error {
124125
}
125126

126127
// clearQueuedSpans brings the span queue to empty/0/nada
127-
// This function doesn't take the Lock so make sure to have
128-
// the write lock before calling.
129-
// This is meant to be called from GetQueuedSpans which handles
130-
// locking.
128+
//
129+
// This function doesn't take the Lock so make sure to have
130+
// the write lock before calling.
131+
// This is meant to be called from GetQueuedSpans which handles
132+
// locking.
131133
func (r *Recorder) clearQueuedSpans() {
132134
r.spans = r.spans[:0]
133135
}

secrets/matchers.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ func NewRegexpMatcher(terms ...*regexp.Regexp) (RegexpMatcher, error) {
149149
// Match returns true if a string fully matches any of matcher's regular expessions. If an expression matches only
150150
// a part of string, this method returns false:
151151
//
152-
// m := NewRegexpMatcher(regexp.MustCompile(`aaa`), regexp.MustCompile(`bbb`))
153-
// m.Match("aaa") // returns true
154-
// m.Match("bbb") // returns true
155-
// m.Match("aaabbb") // returns false, as both regular expressions match only a part of the string
152+
// m := NewRegexpMatcher(regexp.MustCompile(`aaa`), regexp.MustCompile(`bbb`))
153+
// m.Match("aaa") // returns true
154+
// m.Match("bbb") // returns true
155+
// m.Match("aaabbb") // returns false, as both regular expressions match only a part of the string
156156
func (m RegexpMatcher) Match(s string) bool {
157157
return m.re.MatchString(s)
158158
}

sensor.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
"sync"
1414
"time"
1515

16+
"github.com/instana/go-sensor/logger"
17+
1618
"github.com/instana/go-sensor/acceptor"
1719
"github.com/instana/go-sensor/autoprofile"
1820
"github.com/instana/go-sensor/aws"
19-
"github.com/instana/go-sensor/logger"
2021
)
2122

2223
const (

0 commit comments

Comments
 (0)