Skip to content

Commit 53c54d3

Browse files
committed
upd: struct layout + go1.17
1 parent 8839d9b commit 53c54d3

File tree

190 files changed

+507
-478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+507
-478
lines changed

agent/accumulator_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ func TestAccAddError(t *testing.T) {
7171

7272
func TestSetPrecision(t *testing.T) {
7373
tests := []struct {
74-
name string
75-
unset bool
76-
precision time.Duration
7774
timestamp time.Time
7875
expected time.Time
76+
name string
77+
precision time.Duration
78+
unset bool
7979
}{
8080
{
8181
name: "default precision is nanosecond",

agent/agent_posix.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package agent

agent/agent_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ func TestWindow(t *testing.T) {
118118
}
119119

120120
tests := []struct {
121-
name string
122121
start time.Time
123-
roundInterval bool
124-
period time.Duration
125122
since time.Time
126123
until time.Time
124+
name string
125+
period time.Duration
126+
roundInterval bool
127127
}{
128128
{
129129
name: "round with exact alignment",

agent/agent_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
package agent

agent/tick.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ type Ticker interface {
3131
// no maximum sleep, when using large intervals alignment is not corrected
3232
// until the next tick.
3333
type AlignedTicker struct {
34+
wg sync.WaitGroup
35+
ch chan time.Time
36+
cancel context.CancelFunc
3437
interval time.Duration
3538
jitter time.Duration
3639
minInterval time.Duration
37-
ch chan time.Time
38-
cancel context.CancelFunc
39-
wg sync.WaitGroup
4040
}
4141

4242
func NewAlignedTicker(now time.Time, interval, jitter time.Duration) *AlignedTicker {
@@ -118,11 +118,11 @@ func (t *AlignedTicker) Stop() {
118118
//
119119
// Ticks are dropped for slow consumers.
120120
type UnalignedTicker struct {
121-
interval time.Duration
122-
jitter time.Duration
121+
wg sync.WaitGroup
123122
ch chan time.Time
124123
cancel context.CancelFunc
125-
wg sync.WaitGroup
124+
interval time.Duration
125+
jitter time.Duration
126126
}
127127

128128
func NewUnalignedTicker(interval, jitter time.Duration) *UnalignedTicker {
@@ -211,11 +211,11 @@ func (t *UnalignedTicker) Stop() {
211211
//
212212
// Ticks are dropped for slow consumers.
213213
type RollingTicker struct {
214-
interval time.Duration
215-
jitter time.Duration
214+
wg sync.WaitGroup
216215
ch chan time.Time
217216
cancel context.CancelFunc
218-
wg sync.WaitGroup
217+
interval time.Duration
218+
jitter time.Duration
219219
}
220220

221221
func NewRollingTicker(interval, jitter time.Duration) *RollingTicker {

cmd/circonus-unified-agent/circonus-unified-agent.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// +build go1.16
1+
//go:build go1.17
2+
// +build go1.17
23

34
package main
45

@@ -140,6 +141,7 @@ func runAgent(ctx context.Context,
140141
if err != nil {
141142
return fmt.Errorf("loaddir (%s): %w", *fConfigDirectory, err)
142143
}
144+
log.Printf("I! Completed loading configs from %s", *fConfigDirectory)
143145
}
144146

145147
// mgm: add default plugins and agent plugins

cmd/circonus-unified-agent/circonus-unified-agent_posix.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package main

cmd/circonus-unified-agent/circonus-unified-agent_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
package main

cua/metric.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ type Tag struct {
2626

2727
// Field represents a single field key and value.
2828
type Field struct {
29-
Key string
3029
Value interface{}
30+
Key string
3131
}
3232

3333
// Metric is the type of data that is processed by the agent. Input plugins,

internal/exec_unix.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package internal

internal/exec_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
package internal

internal/goplugin/noplugin.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !goplugin
12
// +build !goplugin
23

34
package goplugin

internal/goplugin/plugin.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build goplugin
12
// +build goplugin
23

34
package goplugin

internal/process/process.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@ import (
1515

1616
// Process is a long-running process manager that will restart processes if they stop.
1717
type Process struct {
18-
Cmd *exec.Cmd
18+
mainLoopWg sync.WaitGroup
1919
Stdin io.WriteCloser
2020
Stdout io.ReadCloser
2121
Stderr io.ReadCloser
22-
ReadStdoutFn func(io.Reader)
22+
Log cua.Logger
23+
Cmd *exec.Cmd
2324
ReadStderrFn func(io.Reader)
25+
ReadStdoutFn func(io.Reader)
26+
cancel context.CancelFunc
27+
name string
28+
args []string
2429
RestartDelay time.Duration
25-
Log cua.Logger
26-
27-
name string
28-
args []string
29-
pid int32
30-
cancel context.CancelFunc
31-
mainLoopWg sync.WaitGroup
30+
pid int32
3231
}
3332

3433
// New creates a new process wrapper

internal/process/process_posix.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package process

internal/process/process_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package process

internal/process/process_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
package process

internal/usage.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !windows
12
// +build !windows
23

34
package internal

internal/usage_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build windows
12
// +build windows
23

34
package internal

logger/event_logger_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//+build windows
1+
//go:build windows
2+
// +build windows
23

34
package logger
45

logger/logger.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ const (
2222

2323
// LogConfig contains the log configuration settings
2424
type LogConfig struct {
25-
// will set the log level to DEBUG
26-
Debug bool
27-
// will set the log level to ERROR
28-
Quiet bool
2925
// stderr, stdout, file or eventlog (Windows only)
3026
LogTarget string
3127
// will direct the logging output to a file. Empty string is
3228
// interpreted as stderr. If there is an error opening the file the
3329
// logger will fallback to stderr
3430
Logfile string
31+
// maximum rotated files to keep (older ones will be deleted)
32+
RotationMaxArchives int
3533
// will rotate when current file at the specified time interval
3634
RotationInterval internal.Duration
3735
// will rotate when current file size exceeds this parameter.
3836
RotationMaxSize internal.Size
39-
// maximum rotated files to keep (older ones will be deleted)
40-
RotationMaxArchives int
37+
// will set the log level to ERROR
38+
Quiet bool
39+
// will set the log level to DEBUG
40+
Debug bool
4141
}
4242

4343
type Creator interface {

metric/metric.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
)
1111

1212
type metric struct {
13+
tm time.Time
1314
name string
14-
tags []*cua.Tag
15+
originInstance string
16+
origin string
1517
fields []*cua.Field
16-
tm time.Time
18+
tags []*cua.Tag
1719
tp cua.ValueType
1820
aggregate bool
19-
origin string
20-
originInstance string
2121
}
2222

2323
func New(

metric/tracking.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ func debugFinalizer(d *trackingData) {
4545
}
4646

4747
type trackingData struct {
48+
notifyFunc NotifyFunc
4849
id cua.TrackingID
4950
rc int32
5051
acceptCount int32
5152
rejectCount int32
52-
notifyFunc NotifyFunc
5353
}
5454

5555
func (d *trackingData) incr() {

metric/tracking_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ func TestNewTrackingID(t *testing.T) {
7070

7171
func TestTracking(t *testing.T) {
7272
tests := []struct {
73-
name string
7473
metric cua.Metric
7574
actions func(metric cua.Metric)
75+
name string
7676
delivered bool
7777
}{
7878
{
@@ -174,9 +174,9 @@ func TestTracking(t *testing.T) {
174174

175175
func TestGroupTracking(t *testing.T) {
176176
tests := []struct {
177+
actions func(metrics []cua.Metric)
177178
name string
178179
metrics []cua.Metric
179-
actions func(metrics []cua.Metric)
180180
delivered bool
181181
}{
182182
{

models/buffer.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ var (
1515
// Buffer stores metrics in a circular buffer.
1616
type Buffer struct {
1717
sync.Mutex
18-
buf []cua.Metric
19-
first int // index of the first/oldest metric
20-
last int // one after the index of the last/newest metric
21-
size int // number of metrics currently in the buffer
22-
cap int // the capacity of the buffer
23-
24-
batchFirst int // index of the first metric in the batch
25-
batchSize int // number of metrics currently in the batch
26-
27-
MetricsAdded selfstat.Stat
28-
MetricsWritten selfstat.Stat
29-
MetricsDropped selfstat.Stat
3018
BufferSize selfstat.Stat
19+
MetricsDropped selfstat.Stat
20+
MetricsWritten selfstat.Stat
21+
MetricsAdded selfstat.Stat
3122
BufferLimit selfstat.Stat
23+
buf []cua.Metric
24+
cap int // the capacity of the buffer
25+
batchSize int // number of metrics currently in the batch
26+
size int // number of metrics currently in the buffer
27+
last int // one after the index of the last/newest metric
28+
first int // index of the first/oldest metric
29+
batchFirst int // index of the first metric in the batch
3230
}
3331

3432
// NewBuffer returns a new empty Buffer with the given capacity.

models/filter.go

+14-18
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,28 @@ import (
99

1010
// TagFilter is the name of a tag, and the values on which to filter
1111
type TagFilter struct {
12+
filter filter.Filter
1213
Name string
1314
Filter []string
14-
filter filter.Filter
1515
}
1616

1717
// Filter containing drop/pass and tagdrop/tagpass rules
1818
type Filter struct {
19-
NameDrop []string
20-
nameDrop filter.Filter
21-
NamePass []string
22-
namePass filter.Filter
23-
24-
FieldDrop []string
25-
fieldDrop filter.Filter
26-
FieldPass []string
27-
fieldPass filter.Filter
28-
29-
TagDrop []TagFilter
30-
TagPass []TagFilter
31-
32-
TagExclude []string
19+
fieldPass filter.Filter
20+
nameDrop filter.Filter
21+
tagInclude filter.Filter
22+
namePass filter.Filter
3323
tagExclude filter.Filter
24+
fieldDrop filter.Filter
25+
NameDrop []string
26+
FieldPass []string
27+
TagDrop []TagFilter
28+
TagPass []TagFilter
29+
TagExclude []string
30+
FieldDrop []string
3431
TagInclude []string
35-
tagInclude filter.Filter
36-
37-
isActive bool
32+
NamePass []string
33+
isActive bool
3834
}
3935

4036
// Compile all Filter lists into filter.Filter objects.

models/filter_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ func TestFilter_FilterTagsPassAndDrop(t *testing.T) {
484484

485485
func BenchmarkFilter(b *testing.B) {
486486
tests := []struct {
487+
metric cua.Metric
487488
name string
488489
filter Filter
489-
metric cua.Metric
490490
}{
491491
{
492492
name: "empty filter",

models/log.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
// Logger defines a logging structure for plugins.
1111
type Logger struct {
12-
OnErrs []func()
1312
Name string // Name is the plugin name, will be printed in the `[]`.
13+
OnErrs []func()
1414
}
1515

1616
// NewLogger creates a new logger instance

0 commit comments

Comments
 (0)