Skip to content

Commit fe2f529

Browse files
[chore] apply unkeyed literal initialization prevention
1 parent 0658f77 commit fe2f529

File tree

70 files changed

+387
-21
lines changed

Some content is hidden

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

70 files changed

+387
-21
lines changed

.checkapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ ignored_functions:
6767
- ^Test.*
6868
- ^Benchmark.*
6969
- ^Fuzz.*
70+
71+
unkeyed_literal_initialization:
72+
enabled: true
73+
limit: 1 # this limit will increase over time to 5.

connector/datadogconnector/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var _ component.Config = (*Config)(nil)
1515
type Config struct {
1616
// Traces defines the Traces specific configuration
1717
Traces datadogconfig.TracesConnectorConfig `mapstructure:"traces"`
18+
// prevent unkeyed literal initialization
19+
_ struct{}
1820
}
1921

2022
// Validate checks if the configuration is valid

connector/exceptionsconnector/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import (
1313
type Dimension struct {
1414
Name string `mapstructure:"name"`
1515
Default *string `mapstructure:"default"`
16+
// prevent unkeyed literal initialization
17+
_ struct{}
1618
}
1719

1820
type Exemplars struct {
1921
Enabled bool `mapstructure:"enabled"`
22+
// prevent unkeyed literal initialization
23+
_ struct{}
2024
}
2125

2226
// Config defines the configuration options for exceptionsconnector

connector/exceptionsconnector/connector_metrics_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,21 @@ func newTestMetricsConnector(mcon consumer.Metrics, defaultNullValue *string, lo
124124
cfg := &Config{
125125
Dimensions: []Dimension{
126126
// Set nil defaults to force a lookup for the attribute in the span.
127-
{stringAttrName, nil},
128-
{intAttrName, nil},
129-
{doubleAttrName, nil},
130-
{boolAttrName, nil},
131-
{mapAttrName, nil},
132-
{arrayAttrName, nil},
133-
{nullAttrName, defaultNullValue},
127+
{Name:stringAttrName, Default: nil},
128+
{Name: intAttrName},
129+
{Name: doubleAttrName},
130+
{Name: boolAttrName},
131+
{Name: mapAttrName},
132+
{Name: arrayAttrName},
133+
{Name: nullAttrName, Default: defaultNullValue},
134134
// Add a default value for an attribute that doesn't exist in a span
135-
{notInSpanAttrName0, stringp("defaultNotInSpanAttrVal")},
135+
{Name: notInSpanAttrName0, Default: stringp("defaultNotInSpanAttrVal")},
136136
// Leave the default value unset to test that this dimension should not be added to the metric.
137-
{notInSpanAttrName1, nil},
137+
{Name: notInSpanAttrName1},
138138

139139
// Exception specific dimensions
140-
{exceptionTypeKey, nil},
141-
{exceptionMessageKey, nil},
140+
{Name: exceptionTypeKey},
141+
{Name: exceptionMessageKey},
142142
},
143143
Exemplars: Exemplars{
144144
Enabled: true,

connector/servicegraphconnector/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ type StoreConfig struct {
6262
MaxItems int `mapstructure:"max_items"`
6363
// TTL is the time to live for items in the store.
6464
TTL time.Duration `mapstructure:"ttl"`
65+
66+
// prevent unkeyed literal initialization
67+
_ struct{}
6568
}

connector/spanmetricsconnector/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,30 @@ type HistogramConfig struct {
107107
type ExemplarsConfig struct {
108108
Enabled bool `mapstructure:"enabled"`
109109
MaxPerDataPoint *int `mapstructure:"max_per_data_point"`
110+
// prevent unkeyed literal initialization
111+
_ struct{}
110112
}
111113

112114
type ExponentialHistogramConfig struct {
113115
MaxSize int32 `mapstructure:"max_size"`
116+
// prevent unkeyed literal initialization
117+
_ struct{}
114118
}
115119

116120
type ExplicitHistogramConfig struct {
117121
// Buckets is the list of durations representing explicit histogram buckets.
118122
Buckets []time.Duration `mapstructure:"buckets"`
123+
// prevent unkeyed literal initialization
124+
_ struct{}
119125
}
120126

121127
type EventsConfig struct {
122128
// Enabled is a flag to enable events.
123129
Enabled bool `mapstructure:"enabled"`
124130
// Dimensions defines the list of dimensions to add to the events metric.
125131
Dimensions []Dimension `mapstructure:"dimensions"`
132+
// prevent unkeyed literal initialization
133+
_ struct{}
126134
}
127135

128136
var _ xconfmap.Validator = (*Config)(nil)

exporter/awss3exporter/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const (
7373
type ResourceAttrsToS3 struct {
7474
// S3Prefix indicates the mapping of the key (directory) prefix used for writing into the bucket to a specific resource attribute value.
7575
S3Prefix string `mapstructure:"s3_prefix"`
76+
// prevent unkeyed literal initialization
77+
_ struct{}
7678
}
7779

7880
// Config contains the main configuration options for the s3 exporter

exporter/cassandraexporter/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ type Config struct {
2323
type Replication struct {
2424
Class string `mapstructure:"class"`
2525
ReplicationFactor int `mapstructure:"replication_factor"`
26+
// prevent unkeyed literal initialization
27+
_ struct{}
2628
}
2729

2830
type Compression struct {
2931
Algorithm string `mapstructure:"algorithm"`
32+
// prevent unkeyed literal initialization
33+
_ struct{}
3034
}
3135

3236
type Auth struct {
3337
UserName string `mapstructure:"username"`
3438
Password configopaque.String `mapstructure:"password"`
39+
// prevent unkeyed literal initialization
40+
_ struct{}
3541
}

exporter/elasticsearchexporter/config.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,27 +129,42 @@ type TelemetrySettings struct {
129129

130130
LogFailedDocsInput bool `mapstructure:"log_failed_docs_input"`
131131
LogFailedDocsInputRateLimit time.Duration `mapstructure:"log_failed_docs_input_rate_limit"`
132+
133+
// prevent unkeyed literal initialization
134+
_ struct{}
132135
}
133136

134137
type LogstashFormatSettings struct {
135138
Enabled bool `mapstructure:"enabled"`
136139
PrefixSeparator string `mapstructure:"prefix_separator"`
137140
DateFormat string `mapstructure:"date_format"`
141+
142+
// prevent unkeyed literal initialization
143+
_ struct{}
138144
}
139145

140146
type DynamicIndexSetting struct {
141147
// Enabled enables dynamic index routing.
142148
//
143149
// Deprecated: [v0.122.0] This config is now ignored. Dynamic index routing is always done by default.
144150
Enabled bool `mapstructure:"enabled"`
151+
152+
// prevent unkeyed literal initialization
153+
_ struct{}
145154
}
146155

147156
type DynamicIDSettings struct {
148157
Enabled bool `mapstructure:"enabled"`
158+
159+
// prevent unkeyed literal initialization
160+
_ struct{}
149161
}
150162

151163
type DynamicPipelineSettings struct {
152164
Enabled bool `mapstructure:"enabled"`
165+
166+
// prevent unkeyed literal initialization
167+
_ struct{}
153168
}
154169

155170
// AuthenticationSettings defines user authentication related settings.
@@ -164,6 +179,9 @@ type AuthenticationSettings struct {
164179
//
165180
// https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html
166181
APIKey configopaque.String `mapstructure:"api_key"`
182+
183+
// prevent unkeyed literal initialization
184+
_ struct{}
167185
}
168186

169187
// DiscoverySettings defines Elasticsearch node discovery related settings.
@@ -183,6 +201,9 @@ type DiscoverySettings struct {
183201
// Interval instructs the exporter to renew the list of Elasticsearch URLs
184202
// with the given interval. URLs will not be updated if Interval is <=0.
185203
Interval time.Duration `mapstructure:"interval"`
204+
205+
// prevent unkeyed literal initialization
206+
_ struct{}
186207
}
187208

188209
// FlushSettings defines settings for configuring the write buffer flushing
@@ -194,6 +215,9 @@ type FlushSettings struct {
194215

195216
// Interval configures the max age of a document in the send buffer.
196217
Interval time.Duration `mapstructure:"interval"`
218+
219+
// prevent unkeyed literal initialization
220+
_ struct{}
197221
}
198222

199223
// RetrySettings defines settings for the HTTP request retries in the Elasticsearch exporter.
@@ -235,6 +259,9 @@ type MappingsSettings struct {
235259
//
236260
// If unspecified, all mapping modes are allowed.
237261
AllowedModes []string `mapstructure:"allowed_modes"`
262+
263+
// prevent unkeyed literal initialization
264+
_ struct{}
238265
}
239266

240267
type MappingMode int

exporter/honeycombmarkerexporter/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ type Marker struct {
5656
type Rules struct {
5757
// LogConditions is the list of ottllog conditions that determine a match
5858
LogConditions []string `mapstructure:"log_conditions"`
59+
60+
// prevent unkeyed literal initialization
61+
_ struct{}
5962
}
6063

6164
var _ component.Config = (*Config)(nil)

0 commit comments

Comments
 (0)