Skip to content

Commit 5000d89

Browse files
committed
chore: Fix linter findings for revive:exported in plugins/inputs/o*
1 parent eb2afad commit 5000d89

23 files changed

+407
-424
lines changed

plugins/inputs/opcua/opcua.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,24 @@ import (
1616
var sampleConfig string
1717

1818
type OpcUA struct {
19-
ReadClientConfig
19+
readClientConfig
2020
Log telegraf.Logger `toml:"-"`
2121

22-
client *ReadClient
22+
client *readClient
2323
}
2424

2525
func (*OpcUA) SampleConfig() string {
2626
return sampleConfig
2727
}
2828

29-
// Init Initialise all required objects
3029
func (o *OpcUA) Init() (err error) {
31-
o.client, err = o.ReadClientConfig.CreateReadClient(o.Log)
30+
o.client, err = o.readClientConfig.createReadClient(o.Log)
3231
return err
3332
}
3433

35-
// Gather defines what data the plugin will gather.
3634
func (o *OpcUA) Gather(acc telegraf.Accumulator) error {
3735
// Will (re)connect if the client is disconnected
38-
metrics, err := o.client.CurrentValues()
36+
metrics, err := o.client.currentValues()
3937
if err != nil {
4038
return err
4139
}
@@ -51,7 +49,7 @@ func (o *OpcUA) Gather(acc telegraf.Accumulator) error {
5149
func init() {
5250
inputs.Add("opcua", func() telegraf.Input {
5351
return &OpcUA{
54-
ReadClientConfig: ReadClientConfig{
52+
readClientConfig: readClientConfig{
5553
InputClientConfig: input.InputClientConfig{
5654
OpcUAClientConfig: opcua.OpcUAClientConfig{
5755
Endpoint: "opc.tcp://localhost:4840",

plugins/inputs/opcua/opcua_test.go

+53-53
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ import (
1919

2020
const servicePort = "4840"
2121

22-
type OPCTags struct {
23-
Name string
24-
Namespace string
25-
IdentifierType string
26-
Identifier string
27-
Want interface{}
22+
type opcTags struct {
23+
name string
24+
namespace string
25+
identifierType string
26+
identifier string
27+
want interface{}
2828
}
2929

30-
func MapOPCTag(tags OPCTags) (out input.NodeSettings) {
31-
out.FieldName = tags.Name
32-
out.Namespace = tags.Namespace
33-
out.IdentifierType = tags.IdentifierType
34-
out.Identifier = tags.Identifier
30+
func mapOPCTag(tags opcTags) (out input.NodeSettings) {
31+
out.FieldName = tags.name
32+
out.Namespace = tags.namespace
33+
out.IdentifierType = tags.identifierType
34+
out.Identifier = tags.identifier
3535
return out
3636
}
3737

@@ -52,13 +52,13 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) {
5252
require.NoError(t, err, "failed to start container")
5353
defer container.Terminate()
5454

55-
testopctags := []OPCTags{
55+
testopctags := []opcTags{
5656
{"ProductName", "1", "i", "2261", "open62541 OPC UA Server"},
5757
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
5858
{"ManufacturerName", "0", "i", "2263", "open62541"},
5959
}
6060

61-
readConfig := ReadClientConfig{
61+
readConfig := readClientConfig{
6262
InputClientConfig: input.InputClientConfig{
6363
OpcUAClientConfig: opcua.OpcUAClientConfig{
6464
Endpoint: fmt.Sprintf("opc.tcp://%s:%s", container.Address, container.Ports[servicePort]),
@@ -83,14 +83,14 @@ func TestGetDataBadNodeContainerIntegration(t *testing.T) {
8383
}
8484

8585
for _, tags := range testopctags {
86-
g.Nodes = append(g.Nodes, MapOPCTag(tags))
86+
g.Nodes = append(g.Nodes, mapOPCTag(tags))
8787
}
8888
readConfig.Groups = append(readConfig.Groups, g)
8989

9090
logger := &testutil.CaptureLogger{}
91-
readClient, err := readConfig.CreateReadClient(logger)
91+
readClient, err := readConfig.createReadClient(logger)
9292
require.NoError(t, err)
93-
err = readClient.Connect()
93+
err = readClient.connect()
9494
require.NoError(t, err)
9595
}
9696

@@ -111,7 +111,7 @@ func TestReadClientIntegration(t *testing.T) {
111111
require.NoError(t, err, "failed to start container")
112112
defer container.Terminate()
113113

114-
testopctags := []OPCTags{
114+
testopctags := []opcTags{
115115
{"ProductName", "0", "i", "2261", "open62541 OPC UA Server"},
116116
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
117117
{"ManufacturerName", "0", "i", "2263", "open62541"},
@@ -120,7 +120,7 @@ func TestReadClientIntegration(t *testing.T) {
120120
{"DateTime", "1", "i", "51037", "0001-01-01T00:00:00Z"},
121121
}
122122

123-
readConfig := ReadClientConfig{
123+
readConfig := readClientConfig{
124124
InputClientConfig: input.InputClientConfig{
125125
OpcUAClientConfig: opcua.OpcUAClientConfig{
126126
Endpoint: fmt.Sprintf("opc.tcp://%s:%s", container.Address, container.Ports[servicePort]),
@@ -138,17 +138,17 @@ func TestReadClientIntegration(t *testing.T) {
138138
}
139139

140140
for _, tags := range testopctags {
141-
readConfig.RootNodes = append(readConfig.RootNodes, MapOPCTag(tags))
141+
readConfig.RootNodes = append(readConfig.RootNodes, mapOPCTag(tags))
142142
}
143143

144-
client, err := readConfig.CreateReadClient(testutil.Logger{})
144+
client, err := readConfig.createReadClient(testutil.Logger{})
145145
require.NoError(t, err)
146146

147-
err = client.Connect()
148-
require.NoError(t, err, "Connect")
147+
err = client.connect()
148+
require.NoError(t, err)
149149

150150
for i, v := range client.LastReceivedData {
151-
require.Equal(t, testopctags[i].Want, v.Value)
151+
require.Equal(t, testopctags[i].want, v.Value)
152152
}
153153
}
154154

@@ -168,7 +168,7 @@ func TestReadClientIntegrationAdditionalFields(t *testing.T) {
168168
require.NoError(t, container.Start(), "failed to start container")
169169
defer container.Terminate()
170170

171-
testopctags := []OPCTags{
171+
testopctags := []opcTags{
172172
{"ProductName", "0", "i", "2261", "open62541 OPC UA Server"},
173173
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
174174
{"ManufacturerName", "0", "i", "2263", "open62541"},
@@ -196,17 +196,17 @@ func TestReadClientIntegrationAdditionalFields(t *testing.T) {
196196
for i, x := range testopctags {
197197
now := time.Now()
198198
tags := map[string]string{
199-
"id": fmt.Sprintf("ns=%s;%s=%s", x.Namespace, x.IdentifierType, x.Identifier),
199+
"id": fmt.Sprintf("ns=%s;%s=%s", x.namespace, x.identifierType, x.identifier),
200200
}
201201
fields := map[string]interface{}{
202-
x.Name: x.Want,
202+
x.name: x.want,
203203
"Quality": testopcquality[i],
204204
"DataType": testopctypes[i],
205205
}
206206
expectedopcmetrics = append(expectedopcmetrics, metric.New("testing", tags, fields, now))
207207
}
208208

209-
readConfig := ReadClientConfig{
209+
readConfig := readClientConfig{
210210
InputClientConfig: input.InputClientConfig{
211211
OpcUAClientConfig: opcua.OpcUAClientConfig{
212212
Endpoint: fmt.Sprintf("opc.tcp://%s:%s", container.Address, container.Ports[servicePort]),
@@ -225,13 +225,13 @@ func TestReadClientIntegrationAdditionalFields(t *testing.T) {
225225
}
226226

227227
for _, tags := range testopctags {
228-
readConfig.RootNodes = append(readConfig.RootNodes, MapOPCTag(tags))
228+
readConfig.RootNodes = append(readConfig.RootNodes, mapOPCTag(tags))
229229
}
230230

231-
client, err := readConfig.CreateReadClient(testutil.Logger{})
231+
client, err := readConfig.createReadClient(testutil.Logger{})
232232
require.NoError(t, err)
233233

234-
require.NoError(t, client.Connect())
234+
require.NoError(t, client.connect())
235235

236236
actualopcmetrics := make([]telegraf.Metric, 0, len(client.LastReceivedData))
237237
for i := range client.LastReceivedData {
@@ -258,13 +258,13 @@ func TestReadClientIntegrationWithPasswordAuth(t *testing.T) {
258258
require.NoError(t, err, "failed to start container")
259259
defer container.Terminate()
260260

261-
testopctags := []OPCTags{
261+
testopctags := []opcTags{
262262
{"ProductName", "0", "i", "2261", "open62541 OPC UA Server"},
263263
{"ProductUri", "0", "i", "2262", "http://open62541.org"},
264264
{"ManufacturerName", "0", "i", "2263", "open62541"},
265265
}
266266

267-
readConfig := ReadClientConfig{
267+
readConfig := readClientConfig{
268268
InputClientConfig: input.InputClientConfig{
269269
OpcUAClientConfig: opcua.OpcUAClientConfig{
270270
Endpoint: fmt.Sprintf("opc.tcp://%s:%s", container.Address, container.Ports[servicePort]),
@@ -284,17 +284,17 @@ func TestReadClientIntegrationWithPasswordAuth(t *testing.T) {
284284
}
285285

286286
for _, tags := range testopctags {
287-
readConfig.RootNodes = append(readConfig.RootNodes, MapOPCTag(tags))
287+
readConfig.RootNodes = append(readConfig.RootNodes, mapOPCTag(tags))
288288
}
289289

290-
client, err := readConfig.CreateReadClient(testutil.Logger{})
290+
client, err := readConfig.createReadClient(testutil.Logger{})
291291
require.NoError(t, err)
292292

293-
err = client.Connect()
294-
require.NoError(t, err, "Connect")
293+
err = client.connect()
294+
require.NoError(t, err)
295295

296296
for i, v := range client.LastReceivedData {
297-
require.Equal(t, testopctags[i].Want, v.Value)
297+
require.Equal(t, testopctags[i].want, v.Value)
298298
}
299299
}
300300

@@ -369,17 +369,17 @@ use_unregistered_reads = true
369369
o, ok := c.Inputs[0].Input.(*OpcUA)
370370
require.True(t, ok)
371371

372-
require.Equal(t, "localhost", o.ReadClientConfig.MetricName)
373-
require.Equal(t, "opc.tcp://localhost:4840", o.ReadClientConfig.Endpoint)
374-
require.Equal(t, config.Duration(10*time.Second), o.ReadClientConfig.ConnectTimeout)
375-
require.Equal(t, config.Duration(5*time.Second), o.ReadClientConfig.RequestTimeout)
376-
require.Equal(t, "auto", o.ReadClientConfig.SecurityPolicy)
377-
require.Equal(t, "auto", o.ReadClientConfig.SecurityMode)
378-
require.Equal(t, "/etc/telegraf/cert.pem", o.ReadClientConfig.Certificate)
379-
require.Equal(t, "/etc/telegraf/key.pem", o.ReadClientConfig.PrivateKey)
380-
require.Equal(t, "Anonymous", o.ReadClientConfig.AuthMethod)
381-
require.True(t, o.ReadClientConfig.Username.Empty())
382-
require.True(t, o.ReadClientConfig.Password.Empty())
372+
require.Equal(t, "localhost", o.readClientConfig.MetricName)
373+
require.Equal(t, "opc.tcp://localhost:4840", o.readClientConfig.Endpoint)
374+
require.Equal(t, config.Duration(10*time.Second), o.readClientConfig.ConnectTimeout)
375+
require.Equal(t, config.Duration(5*time.Second), o.readClientConfig.RequestTimeout)
376+
require.Equal(t, "auto", o.readClientConfig.SecurityPolicy)
377+
require.Equal(t, "auto", o.readClientConfig.SecurityMode)
378+
require.Equal(t, "/etc/telegraf/cert.pem", o.readClientConfig.Certificate)
379+
require.Equal(t, "/etc/telegraf/key.pem", o.readClientConfig.PrivateKey)
380+
require.Equal(t, "Anonymous", o.readClientConfig.AuthMethod)
381+
require.True(t, o.readClientConfig.Username.Empty())
382+
require.True(t, o.readClientConfig.Password.Empty())
383383
require.Equal(t, []input.NodeSettings{
384384
{
385385
FieldName: "name",
@@ -396,7 +396,7 @@ use_unregistered_reads = true
396396
TagsSlice: [][]string{{"tag0", "val0"}, {"tag00", "val00"}},
397397
DefaultTags: map[string]string{"tag6": "val6"},
398398
},
399-
}, o.ReadClientConfig.RootNodes)
399+
}, o.readClientConfig.RootNodes)
400400
require.Equal(t, []input.NodeGroupSettings{
401401
{
402402
MetricName: "foo",
@@ -424,10 +424,10 @@ use_unregistered_reads = true
424424
Identifier: "4001",
425425
}},
426426
},
427-
}, o.ReadClientConfig.Groups)
428-
require.Equal(t, opcua.OpcUAWorkarounds{AdditionalValidStatusCodes: []string{"0xC0"}}, o.ReadClientConfig.Workarounds)
429-
require.Equal(t, ReadClientWorkarounds{UseUnregisteredReads: true}, o.ReadClientConfig.ReadClientWorkarounds)
430-
require.Equal(t, []string{"DataType"}, o.ReadClientConfig.OptionalFields)
427+
}, o.readClientConfig.Groups)
428+
require.Equal(t, opcua.OpcUAWorkarounds{AdditionalValidStatusCodes: []string{"0xC0"}}, o.readClientConfig.Workarounds)
429+
require.Equal(t, readClientWorkarounds{UseUnregisteredReads: true}, o.readClientConfig.ReadClientWorkarounds)
430+
require.Equal(t, []string{"DataType"}, o.readClientConfig.OptionalFields)
431431
err = o.Init()
432432
require.NoError(t, err)
433433
require.Len(t, o.client.NodeMetricMapping, 5, "incorrect number of nodes")

plugins/inputs/opcua/read_client.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,33 @@ import (
1515
"github.com/influxdata/telegraf/selfstat"
1616
)
1717

18-
type ReadClientWorkarounds struct {
18+
type readClientWorkarounds struct {
1919
UseUnregisteredReads bool `toml:"use_unregistered_reads"`
2020
}
2121

22-
type ReadClientConfig struct {
22+
type readClientConfig struct {
2323
ReadRetryTimeout config.Duration `toml:"read_retry_timeout"`
2424
ReadRetries uint64 `toml:"read_retry_count"`
25-
ReadClientWorkarounds ReadClientWorkarounds `toml:"request_workarounds"`
25+
ReadClientWorkarounds readClientWorkarounds `toml:"request_workarounds"`
2626
input.InputClientConfig
2727
}
2828

29-
// ReadClient Requests the current values from the required nodes when gather is called.
30-
type ReadClient struct {
29+
// readClient Requests the current values from the required nodes when gather is called.
30+
type readClient struct {
3131
*input.OpcUAInputClient
3232

3333
ReadRetryTimeout time.Duration
3434
ReadRetries uint64
3535
ReadSuccess selfstat.Stat
3636
ReadError selfstat.Stat
37-
Workarounds ReadClientWorkarounds
37+
Workarounds readClientWorkarounds
3838

3939
// internal values
4040
reqIDs []*ua.ReadValueID
4141
ctx context.Context
4242
}
4343

44-
func (rc *ReadClientConfig) CreateReadClient(log telegraf.Logger) (*ReadClient, error) {
44+
func (rc *readClientConfig) createReadClient(log telegraf.Logger) (*readClient, error) {
4545
inputClient, err := rc.InputClientConfig.CreateInputClient(log)
4646
if err != nil {
4747
return nil, err
@@ -55,7 +55,7 @@ func (rc *ReadClientConfig) CreateReadClient(log telegraf.Logger) (*ReadClient,
5555
rc.ReadRetryTimeout = config.Duration(100 * time.Millisecond)
5656
}
5757

58-
return &ReadClient{
58+
return &readClient{
5959
OpcUAInputClient: inputClient,
6060
ReadRetryTimeout: time.Duration(rc.ReadRetryTimeout),
6161
ReadRetries: rc.ReadRetries,
@@ -65,7 +65,7 @@ func (rc *ReadClientConfig) CreateReadClient(log telegraf.Logger) (*ReadClient,
6565
}, nil
6666
}
6767

68-
func (o *ReadClient) Connect() error {
68+
func (o *readClient) connect() error {
6969
o.ctx = context.Background()
7070

7171
if err := o.OpcUAClient.Connect(o.ctx); err != nil {
@@ -103,14 +103,14 @@ func (o *ReadClient) Connect() error {
103103
return nil
104104
}
105105

106-
func (o *ReadClient) ensureConnected() error {
106+
func (o *readClient) ensureConnected() error {
107107
if o.State() == opcua.Disconnected || o.State() == opcua.Closed {
108-
return o.Connect()
108+
return o.connect()
109109
}
110110
return nil
111111
}
112112

113-
func (o *ReadClient) CurrentValues() ([]telegraf.Metric, error) {
113+
func (o *readClient) currentValues() ([]telegraf.Metric, error) {
114114
if err := o.ensureConnected(); err != nil {
115115
return nil, err
116116
}
@@ -142,7 +142,7 @@ func (o *ReadClient) CurrentValues() ([]telegraf.Metric, error) {
142142
return metrics, nil
143143
}
144144

145-
func (o *ReadClient) read() error {
145+
func (o *readClient) read() error {
146146
req := &ua.ReadRequest{
147147
MaxAge: 2000,
148148
TimestampsToReturn: ua.TimestampsToReturnBoth,

0 commit comments

Comments
 (0)