Skip to content

Commit c1cdf8c

Browse files
authored
fluentd: Fix gocyclo warnings (#1723)
Signed-off-by: Y.Horie <[email protected]>
1 parent bc28f3c commit c1cdf8c

File tree

4 files changed

+163
-445
lines changed

4 files changed

+163
-445
lines changed

apis/fluentd/v1alpha1/plugins/common/buffer_types.go

Lines changed: 33 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -155,27 +155,19 @@ func (b *Buffer) Name() string {
155155

156156
func (b *Buffer) Params(_ plugins.SecretLoader) (*params.PluginStore, error) {
157157
ps := params.NewPluginStore(b.Name())
158-
if b.Id != nil {
159-
ps.InsertPairs("@id", fmt.Sprint(*b.Id))
160-
}
158+
params.InsertPairs(ps, "@id", b.Id)
161159
if b.Type != nil {
162160
ps.InsertType(fmt.Sprint(*b.Type))
163161
}
164-
if b.LogLevel != nil {
165-
ps.InsertPairs("@log_level", fmt.Sprint(*b.LogLevel))
166-
}
162+
params.InsertPairs(ps, "@log_level", b.LogLevel)
167163

168164
if b.FileBuffer != nil && b.PathSuffix != nil {
169165
ps.InsertPairs("path_suffix", *b.PathSuffix)
170166
}
171167

172168
if b.FileSingleBuffer != nil {
173-
if b.CalcNumRecords != nil {
174-
ps.InsertPairs("calc_num_records", *b.CalcNumRecords)
175-
}
176-
if b.ChunkFormat != nil {
177-
ps.InsertPairs("chunk_format", *b.ChunkFormat)
178-
}
169+
params.InsertPairs(ps, "calc_num_records", b.CalcNumRecords)
170+
params.InsertPairs(ps, "chunk_format", b.ChunkFormat)
179171
}
180172

181173
if b.Path != nil {
@@ -193,123 +185,45 @@ func (b *Buffer) Params(_ plugins.SecretLoader) (*params.PluginStore, error) {
193185
}
194186
}
195187

196-
if b.TimeKey != nil {
197-
ps.InsertPairs("timekey", fmt.Sprint(*b.TimeKey))
198-
}
199-
200-
if b.TimeKeyWait != nil {
201-
ps.InsertPairs("timekey_wait", fmt.Sprint(*b.TimeKeyWait))
202-
}
188+
params.InsertPairs(ps, "timekey", b.TimeKey)
189+
params.InsertPairs(ps, "timekey_wait", b.TimeKeyWait)
203190

204191
ps.InsertPairs("tag", b.Tag)
205192

206-
if b.ChunkLimitSize != nil {
207-
ps.InsertPairs("chunk_limit_size", *b.ChunkLimitSize)
208-
}
209-
210-
if b.ChunkLimitRecords != nil {
211-
ps.InsertPairs("chunk_limit_records", *b.ChunkLimitRecords)
212-
}
213-
214-
if b.TotalLimitSize != nil {
215-
ps.InsertPairs("total_limit_size", *b.TotalLimitSize)
216-
}
217-
218-
if b.QueueLimitLength != nil {
219-
ps.InsertPairs("queue_limit_length", *b.QueueLimitLength)
220-
}
221-
222-
if b.QueuedChunksLimitSize != nil {
223-
ps.InsertPairs("queued_chunks_limit_size", fmt.Sprint(*b.QueuedChunksLimitSize))
224-
}
225-
226-
if b.Compress != nil {
227-
ps.InsertPairs("compress", fmt.Sprint(*b.Compress))
228-
}
193+
params.InsertPairs(ps, "chunk_limit_size", b.ChunkLimitSize)
194+
params.InsertPairs(ps, "chunk_limit_records", b.ChunkLimitRecords)
195+
params.InsertPairs(ps, "total_limit_size", b.TotalLimitSize)
196+
params.InsertPairs(ps, "queue_limit_length", b.QueueLimitLength)
197+
params.InsertPairs(ps, "queued_chunks_limit_size", b.QueuedChunksLimitSize)
198+
params.InsertPairs(ps, "compress", b.Compress)
229199

230200
if b.FlushAtShutdown != nil && *b.FlushAtShutdown {
231201
ps.InsertPairs("flush_at_shutdown", fmt.Sprint(*b.FlushAtShutdown))
232202
}
233203

234-
if b.FlushMode != nil {
235-
ps.InsertPairs("flush_mode", fmt.Sprint(*b.FlushMode))
236-
}
237-
238-
if b.FlushInterval != nil {
239-
ps.InsertPairs("flush_interval", fmt.Sprint(*b.FlushInterval))
240-
}
241-
242-
if b.FlushThreadCount != nil {
243-
ps.InsertPairs("flush_thread_count", fmt.Sprint(*b.FlushThreadCount))
244-
}
245-
246-
if b.DelayedCommitTimeout != nil {
247-
ps.InsertPairs("delayed_commit_timeout", fmt.Sprint(*b.DelayedCommitTimeout))
248-
}
249-
250-
if b.OverflowAction != nil {
251-
ps.InsertPairs("overflow_action", fmt.Sprint(*b.OverflowAction))
252-
}
253-
254-
if b.RetryTimeout != nil {
255-
ps.InsertPairs("retry_timeout", fmt.Sprint(*b.RetryTimeout))
256-
}
257-
258-
if b.RetrySecondaryThreshold != nil {
259-
ps.InsertPairs("retry_secondary_threshold", fmt.Sprint(*b.RetrySecondaryThreshold))
260-
}
261-
262-
if b.RetryType != nil {
263-
ps.InsertPairs("retry_type", fmt.Sprint(*b.RetryType))
264-
}
265-
266-
if b.RetryMaxTimes != nil {
267-
ps.InsertPairs("retry_max_times", fmt.Sprint(*b.RetryMaxTimes))
268-
}
269-
270-
if b.RetryForever != nil {
271-
ps.InsertPairs("retry_forever", fmt.Sprint(*b.RetryForever))
272-
}
273-
274-
if b.RetryWait != nil {
275-
ps.InsertPairs("retry_wait", fmt.Sprint(*b.RetryWait))
276-
}
277-
278-
if b.RetryExponentialBackoffBase != nil {
279-
ps.InsertPairs("retry_exponential_backoff_base", fmt.Sprint(*b.RetryExponentialBackoffBase))
280-
}
281-
282-
if b.RetryMaxInterval != nil {
283-
ps.InsertPairs("retry_max_interval", fmt.Sprint(*b.RetryMaxInterval))
284-
}
285-
286-
if b.RetryRandomize != nil {
287-
ps.InsertPairs("retry_randomize", fmt.Sprint(*b.RetryRandomize))
288-
}
289-
290-
if b.DisableChunkBackup != nil {
291-
ps.InsertPairs("disable_chunk_backup", fmt.Sprint(*b.DisableChunkBackup))
292-
}
204+
params.InsertPairs(ps, "flush_mode", b.FlushMode)
205+
params.InsertPairs(ps, "flush_interval", b.FlushInterval)
206+
params.InsertPairs(ps, "flush_thread_count", b.FlushThreadCount)
207+
params.InsertPairs(ps, "delayed_commit_timeout", b.DelayedCommitTimeout)
208+
params.InsertPairs(ps, "overflow_action", b.OverflowAction)
209+
params.InsertPairs(ps, "retry_timeout", b.RetryTimeout)
210+
params.InsertPairs(ps, "retry_secondary_threshold", b.RetrySecondaryThreshold)
211+
params.InsertPairs(ps, "retry_type", b.RetryType)
212+
params.InsertPairs(ps, "retry_max_times", b.RetryMaxTimes)
213+
params.InsertPairs(ps, "retry_forever", b.RetryForever)
214+
params.InsertPairs(ps, "retry_wait", b.RetryWait)
215+
params.InsertPairs(ps, "retry_exponential_backoff_base", b.RetryExponentialBackoffBase)
216+
params.InsertPairs(ps, "retry_max_interval", b.RetryMaxInterval)
217+
params.InsertPairs(ps, "retry_randomize", b.RetryRandomize)
218+
params.InsertPairs(ps, "disable_chunk_backup", b.DisableChunkBackup)
293219

294220
if b.Time != nil {
295-
if b.Time.TimeType != nil {
296-
ps.InsertPairs("time_type", fmt.Sprint(*b.Time.TimeType))
297-
}
298-
if b.Time.TimeFormat != nil {
299-
ps.InsertPairs("time_format", fmt.Sprint(*b.Time.TimeFormat))
300-
}
301-
if b.Time.Localtime != nil {
302-
ps.InsertPairs("localtime", fmt.Sprint(*b.Time.Localtime))
303-
}
304-
if b.Time.UTC != nil {
305-
ps.InsertPairs("utc", fmt.Sprint(*b.Time.UTC))
306-
}
307-
if b.Time.Timezone != nil {
308-
ps.InsertPairs("timezone", fmt.Sprint(*b.Time.Timezone))
309-
}
310-
if b.Time.TimeFormatFallbacks != nil {
311-
ps.InsertPairs("time_format_fallbacks", fmt.Sprint(*b.Time.TimeFormatFallbacks))
312-
}
221+
params.InsertPairs(ps, "time_type", b.Time.TimeType)
222+
params.InsertPairs(ps, "time_format", b.Time.TimeFormat)
223+
params.InsertPairs(ps, "localtime", b.Time.Localtime)
224+
params.InsertPairs(ps, "utc", b.Time.UTC)
225+
params.InsertPairs(ps, "timezone", b.Time.Timezone)
226+
params.InsertPairs(ps, "time_format_fallbacks", b.Time.TimeFormatFallbacks)
313227
}
314228

315229
return ps, nil

apis/fluentd/v1alpha1/plugins/filter/types.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,30 @@ func (f *Filter) Params(loader plugins.SecretLoader) (*params.PluginStore, error
9191

9292
}
9393

94-
func (f *Filter) grepPlugin(parent *params.PluginStore, loader plugins.SecretLoader) *params.PluginStore {
95-
childs := make([]*params.PluginStore, 0)
96-
if len(f.Grep.Regexps) > 0 {
97-
for _, r := range f.Grep.Regexps {
94+
func appendChild(childs []*params.PluginStore, loader plugins.SecretLoader, grep *Grep) []*params.PluginStore {
95+
if len(grep.Regexps) > 0 {
96+
for _, r := range grep.Regexps {
9897
if r != nil && r.Key != nil && r.Pattern != nil {
9998
child, _ := r.Params(loader)
10099
childs = append(childs, child)
101100
}
102101
}
103102
}
104103

105-
if len(f.Grep.Excludes) > 0 {
106-
for _, e := range f.Grep.Excludes {
104+
if len(grep.Excludes) > 0 {
105+
for _, e := range grep.Excludes {
107106
if e != nil && e.Key != nil && e.Pattern != nil {
108107
child, _ := e.Params(loader)
109108
childs = append(childs, child)
110109
}
111110
}
112111
}
112+
return childs
113+
}
113114

115+
func (f *Filter) grepPlugin(parent *params.PluginStore, loader plugins.SecretLoader) *params.PluginStore {
116+
childs := make([]*params.PluginStore, 0)
117+
childs = appendChild(childs, loader, f.Grep)
114118
if len(f.Grep.Ands) > 0 {
115119
for _, e := range f.Grep.Ands {
116120
if e != nil && (e.Regexp != nil || e.Exclude != nil) {

0 commit comments

Comments
 (0)