Skip to content

Commit

Permalink
chore: Fix linter findings for revive:max-public-structs in `plugin…
Browse files Browse the repository at this point in the history
…s/inputs/[a-n]*` (#15858)
  • Loading branch information
zak-pawel authored Sep 12, 2024
1 parent 5d996ac commit 46c056f
Show file tree
Hide file tree
Showing 26 changed files with 902 additions and 914 deletions.
38 changes: 19 additions & 19 deletions plugins/inputs/activemq/activemq.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,45 @@ type ActiveMQ struct {
baseURL *url.URL
}

type Topics struct {
type topics struct {
XMLName xml.Name `xml:"topics"`
TopicItems []Topic `xml:"topic"`
TopicItems []topic `xml:"topic"`
}

type Topic struct {
type topic struct {
XMLName xml.Name `xml:"topic"`
Name string `xml:"name,attr"`
Stats Stats `xml:"stats"`
Stats stats `xml:"stats"`
}

type Subscribers struct {
type subscribers struct {
XMLName xml.Name `xml:"subscribers"`
SubscriberItems []Subscriber `xml:"subscriber"`
SubscriberItems []subscriber `xml:"subscriber"`
}

type Subscriber struct {
type subscriber struct {
XMLName xml.Name `xml:"subscriber"`
ClientID string `xml:"clientId,attr"`
SubscriptionName string `xml:"subscriptionName,attr"`
ConnectionID string `xml:"connectionId,attr"`
DestinationName string `xml:"destinationName,attr"`
Selector string `xml:"selector,attr"`
Active string `xml:"active,attr"`
Stats Stats `xml:"stats"`
Stats stats `xml:"stats"`
}

type Queues struct {
type queues struct {
XMLName xml.Name `xml:"queues"`
QueueItems []Queue `xml:"queue"`
QueueItems []queue `xml:"queue"`
}

type Queue struct {
type queue struct {
XMLName xml.Name `xml:"queue"`
Name string `xml:"name,attr"`
Stats Stats `xml:"stats"`
Stats stats `xml:"stats"`
}

type Stats struct {
type stats struct {
XMLName xml.Name `xml:"stats"`
Size int `xml:"size,attr"`
ConsumerCount int `xml:"consumerCount,attr"`
Expand Down Expand Up @@ -161,7 +161,7 @@ func (a *ActiveMQ) GetMetrics(u string) ([]byte, error) {
return io.ReadAll(resp.Body)
}

func (a *ActiveMQ) GatherQueuesMetrics(acc telegraf.Accumulator, queues Queues) {
func (a *ActiveMQ) GatherQueuesMetrics(acc telegraf.Accumulator, queues queues) {
for _, queue := range queues.QueueItems {
records := make(map[string]interface{})
tags := make(map[string]string)
Expand All @@ -179,7 +179,7 @@ func (a *ActiveMQ) GatherQueuesMetrics(acc telegraf.Accumulator, queues Queues)
}
}

func (a *ActiveMQ) GatherTopicsMetrics(acc telegraf.Accumulator, topics Topics) {
func (a *ActiveMQ) GatherTopicsMetrics(acc telegraf.Accumulator, topics topics) {
for _, topic := range topics.TopicItems {
records := make(map[string]interface{})
tags := make(map[string]string)
Expand All @@ -197,7 +197,7 @@ func (a *ActiveMQ) GatherTopicsMetrics(acc telegraf.Accumulator, topics Topics)
}
}

func (a *ActiveMQ) GatherSubscribersMetrics(acc telegraf.Accumulator, subscribers Subscribers) {
func (a *ActiveMQ) GatherSubscribersMetrics(acc telegraf.Accumulator, subscribers subscribers) {
for _, subscriber := range subscribers.SubscriberItems {
records := make(map[string]interface{})
tags := make(map[string]string)
Expand Down Expand Up @@ -226,7 +226,7 @@ func (a *ActiveMQ) Gather(acc telegraf.Accumulator) error {
if err != nil {
return err
}
queues := Queues{}
queues := queues{}
err = xml.Unmarshal(dataQueues, &queues)
if err != nil {
return fmt.Errorf("queues XML unmarshal error: %w", err)
Expand All @@ -236,7 +236,7 @@ func (a *ActiveMQ) Gather(acc telegraf.Accumulator) error {
if err != nil {
return err
}
topics := Topics{}
topics := topics{}
err = xml.Unmarshal(dataTopics, &topics)
if err != nil {
return fmt.Errorf("topics XML unmarshal error: %w", err)
Expand All @@ -246,7 +246,7 @@ func (a *ActiveMQ) Gather(acc telegraf.Accumulator) error {
if err != nil {
return err
}
subscribers := Subscribers{}
subscribers := subscribers{}
err = xml.Unmarshal(dataSubscribers, &subscribers)
if err != nil {
return fmt.Errorf("subscribers XML unmarshal error: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/activemq/activemq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestGatherQueuesMetrics(t *testing.T) {
</queue>
</queues>`

queues := Queues{}
queues := queues{}

require.NoError(t, xml.Unmarshal([]byte(s), &queues))

Expand Down Expand Up @@ -75,7 +75,7 @@ func TestGatherTopicsMetrics(t *testing.T) {
</topic>
</topics>`

topics := Topics{}
topics := topics{}

require.NoError(t, xml.Unmarshal([]byte(s), &topics))

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestGatherSubscribersMetrics(t *testing.T) {
</subscriber>
</subscribers>`

subscribers := Subscribers{}
subscribers := subscribers{}
require.NoError(t, xml.Unmarshal([]byte(s), &subscribers))

records := make(map[string]interface{})
Expand Down
12 changes: 6 additions & 6 deletions plugins/inputs/ctrlx_datalayer/ctrlx_datalayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type CtrlXDataLayer struct {
Password config.Secret `toml:"password"`

Log telegraf.Logger `toml:"-"`
Subscription []Subscription
Subscription []subscription

url string
wg sync.WaitGroup
Expand All @@ -68,7 +68,7 @@ func convertTimestamp2UnixTime(t int64) time.Time {
}

// createSubscription uses the official 'ctrlX Data Layer API' to create the sse subscription.
func (c *CtrlXDataLayer) createSubscription(sub *Subscription) (string, error) {
func (c *CtrlXDataLayer) createSubscription(sub *subscription) (string, error) {
sseURL := c.url + subscriptionPath

id := "telegraf_" + uuid.New().String()
Expand Down Expand Up @@ -101,7 +101,7 @@ func (c *CtrlXDataLayer) createSubscription(sub *Subscription) (string, error) {

// createSubscriptionAndSseClient creates a sse subscription on the server and
// initializes a sse client to receive sse events from the server.
func (c *CtrlXDataLayer) createSubscriptionAndSseClient(sub *Subscription) (*sseclient.SseClient, error) {
func (c *CtrlXDataLayer) createSubscriptionAndSseClient(sub *subscription) (*sseclient.SseClient, error) {
t, err := c.tokenManager.RequestAuthToken()
if err != nil {
return nil, err
Expand All @@ -118,7 +118,7 @@ func (c *CtrlXDataLayer) createSubscriptionAndSseClient(sub *Subscription) (*sse
}

// addMetric writes sse metric into accumulator.
func (c *CtrlXDataLayer) addMetric(se *sseclient.SseEvent, sub *Subscription) {
func (c *CtrlXDataLayer) addMetric(se *sseclient.SseEvent, sub *subscription) {
switch se.Event {
case "update":
// Received an updated value, that we translate into a metric
Expand Down Expand Up @@ -152,7 +152,7 @@ func (c *CtrlXDataLayer) addMetric(se *sseclient.SseEvent, sub *Subscription) {
}

// createMetric - create metric depending on flag 'output_json' and data type
func (c *CtrlXDataLayer) createMetric(em *sseEventData, sub *Subscription) (telegraf.Metric, error) {
func (c *CtrlXDataLayer) createMetric(em *sseEventData, sub *subscription) (telegraf.Metric, error) {
t := convertTimestamp2UnixTime(em.Timestamp)
node := sub.node(em.Node)
if node == nil {
Expand Down Expand Up @@ -314,7 +314,7 @@ func (c *CtrlXDataLayer) Start(acc telegraf.Accumulator) error {
func (c *CtrlXDataLayer) gatherLoop(ctx context.Context) {
for _, sub := range c.Subscription {
c.wg.Add(1)
go func(sub Subscription) {
go func(sub subscription) {
defer c.wg.Done()
for {
select {
Expand Down
66 changes: 33 additions & 33 deletions plugins/inputs/ctrlx_datalayer/ctrlx_datalayer_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ const (
subscriptionPath = "/automation/api/v2/events"
)

// Node contains all properties of a node configuration
type Node struct {
// node contains all properties of a node configuration
type node struct {
Name string `toml:"name"`
Address string `toml:"address"`
Tags map[string]string `toml:"tags"`
}

// Subscription contains all properties of a subscription configuration
type Subscription struct {
// subscription contains all properties of a subscription configuration
type subscription struct {
index int
Nodes []Node `toml:"nodes"`
Nodes []node `toml:"nodes"`
Tags map[string]string `toml:"tags"`
Measurement string `toml:"measurement"`
PublishInterval config.Duration `toml:"publish_interval"`
Expand All @@ -56,52 +56,52 @@ type Subscription struct {
OutputJSONString bool `toml:"output_json_string"`
}

// Rule can be used to override default rule settings.
type Rule struct {
// rule can be used to override default rule settings.
type rule struct {
RuleType string `json:"rule_type"`
Rule interface{} `json:"rule"`
}

// Sampling can be used to override default sampling settings.
type Sampling struct {
// sampling can be used to override default sampling settings.
type sampling struct {
SamplingInterval uint64 `json:"samplingInterval"`
}

// Queueing can be used to override default queuing settings.
type Queueing struct {
// queueing can be used to override default queuing settings.
type queueing struct {
QueueSize uint `json:"queueSize"`
Behaviour string `json:"behaviour"`
}

// DataChangeFilter can be used to override default data change filter settings.
type DataChangeFilter struct {
// dataChangeFilter can be used to override default data change filter settings.
type dataChangeFilter struct {
DeadBandValue float64 `json:"deadBandValue"`
}

// ChangeEvents can be used to override default change events settings.
type ChangeEvents struct {
// changeEvents can be used to override default change events settings.
type changeEvents struct {
ValueChange string `json:"valueChange"`
BrowselistChange bool `json:"browselistChange"`
MetadataChange bool `json:"metadataChange"`
}

// SubscriptionProperties can be used to override default subscription settings.
type SubscriptionProperties struct {
// subscriptionProperties can be used to override default subscription settings.
type subscriptionProperties struct {
KeepaliveInterval int64 `json:"keepaliveInterval"`
Rules []Rule `json:"rules"`
Rules []rule `json:"rules"`
ID string `json:"id"`
PublishInterval int64 `json:"publishInterval"`
ErrorInterval int64 `json:"errorInterval"`
}

// SubscriptionRequest can be used to to create a sse subscription at the ctrlX Data Layer.
type SubscriptionRequest struct {
Properties SubscriptionProperties `json:"properties"`
// subscriptionRequest can be used to create a sse subscription at the ctrlX Data Layer.
type subscriptionRequest struct {
Properties subscriptionProperties `json:"properties"`
Nodes []string `json:"nodes"`
}

// applyDefaultSettings applies the default settings if they are not configured in the config file.
func (s *Subscription) applyDefaultSettings() {
func (s *subscription) applyDefaultSettings() {
if s.Measurement == "" {
s.Measurement = defaultMeasurementName
}
Expand Down Expand Up @@ -130,14 +130,14 @@ func (s *Subscription) applyDefaultSettings() {

// createRequestBody builds the request body for the sse subscription, based on the subscription configuration.
// The request body can be send to the server to create a new subscription.
func (s *Subscription) createRequest(id string) SubscriptionRequest {
pl := SubscriptionRequest{
Properties: SubscriptionProperties{
Rules: []Rule{
{"Sampling", Sampling{uint64(time.Duration(s.SamplingInterval).Microseconds())}},
{"Queueing", Queueing{s.QueueSize, s.QueueBehaviour}},
{"DataChangeFilter", DataChangeFilter{s.DeadBandValue}},
{"ChangeEvents", ChangeEvents{s.ValueChange, false, false}},
func (s *subscription) createRequest(id string) subscriptionRequest {
pl := subscriptionRequest{
Properties: subscriptionProperties{
Rules: []rule{
{"Sampling", sampling{uint64(time.Duration(s.SamplingInterval).Microseconds())}},
{"Queueing", queueing{s.QueueSize, s.QueueBehaviour}},
{"DataChangeFilter", dataChangeFilter{s.DeadBandValue}},
{"ChangeEvents", changeEvents{s.ValueChange, false, false}},
},
ID: id,
KeepaliveInterval: time.Duration(s.KeepaliveInterval).Milliseconds(),
Expand All @@ -151,7 +151,7 @@ func (s *Subscription) createRequest(id string) SubscriptionRequest {
}

// addressList lists all configured node addresses
func (s *Subscription) addressList() []string {
func (s *subscription) addressList() []string {
addressList := []string{}
for _, node := range s.Nodes {
addressList = append(addressList, node.Address)
Expand All @@ -160,7 +160,7 @@ func (s *Subscription) addressList() []string {
}

// node finds the node according the node address
func (s *Subscription) node(address string) *Node {
func (s *subscription) node(address string) *node {
for _, node := range s.Nodes {
if address == node.Address {
return &node
Expand All @@ -170,7 +170,7 @@ func (s *Subscription) node(address string) *Node {
}

// fieldKey determines the field key out of node name or address
func (n *Node) fieldKey() string {
func (n *node) fieldKey() string {
if n.Name != "" {
// return user defined node name as field key
return n.Name
Expand Down
Loading

0 comments on commit 46c056f

Please sign in to comment.