Skip to content

Commit e19a0e4

Browse files
committed
fix and unify IDs
1 parent cb3b60e commit e19a0e4

32 files changed

+78
-71
lines changed

pkg/resources/model/system.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ func FlowDispatcher(flowCr interface{}) (*CommonFlow, error) {
190190
},
191191
}
192192
}
193-
flow, err := types.NewFlow(matches, f.Name, f.Namespace)
193+
id := fmt.Sprintf("clusterflow" + ":" + f.Namespace + ":" + f.Name)
194+
flow, err := types.NewFlow(matches, id, f.Name, f.Namespace)
194195
if err != nil {
195196
return nil, err
196197
}
@@ -223,7 +224,8 @@ func FlowDispatcher(flowCr interface{}) (*CommonFlow, error) {
223224
},
224225
}
225226
}
226-
flow, err := types.NewFlow(matches, f.Name, f.Namespace)
227+
id := fmt.Sprintf("flow" + ":" + f.Namespace + ":" + f.Name)
228+
flow, err := types.NewFlow(matches, id, f.Name, f.Namespace)
227229
commonFlow.Flow = flow
228230
if err != nil {
229231
return nil, err
@@ -240,15 +242,22 @@ func (l *LoggingResources) CreateFlowFromCustomResource(flowCr interface{}) (*ty
240242
}
241243
flow := commonFlow.Flow
242244
outputs := []types.Output{}
245+
var flowType string
246+
if commonFlow.Scope != "" {
247+
flowType = "flow"
248+
} else {
249+
flowType = "clusterflow"
250+
}
243251
var multierr error
244252
FindOutputForAllRefs:
245253
for _, outputRef := range commonFlow.OutputRefs {
246254
// only namespaced flows should use namespaced outputs
247255
if commonFlow.Scope != "" {
248256
for _, output := range l.Outputs {
249257
// only an output from the same namespace can be used with a matching name
258+
// flow -> output (matching)
250259
if output.Namespace == commonFlow.Scope && outputRef == output.Name {
251-
outputId := commonFlow.Scope + "_" + commonFlow.Name + "_" + output.Name
260+
outputId := fmt.Sprintf("%s:%s:%s:output:%s:%s", flowType, commonFlow.Namespace, commonFlow.Name, output.Namespace, output.Name)
252261
plugin, err := plugins.CreateOutput(output.Spec, outputId, secret.NewSecretLoader(l.client, output.Namespace, fluentd.OutputSecretPath, l.Secrets))
253262
if err != nil {
254263
multierr = errors.Combine(multierr, errors.WrapIff(err, "failed to create configured output %s", outputRef))
@@ -261,7 +270,9 @@ FindOutputForAllRefs:
261270
}
262271
for _, clusterOutput := range l.ClusterOutputs {
263272
if outputRef == clusterOutput.Name {
264-
outputId := commonFlow.Namespace + "_" + commonFlow.Name + "_" + clusterOutput.Name
273+
// flow, clusterflow -> clusterOutput
274+
// diff flow / clusterflow based on scope
275+
outputId := fmt.Sprintf("%s:%s:%s:clusteroutput:%s:%s", flowType, commonFlow.Namespace, commonFlow.Name, clusterOutput.Namespace, clusterOutput.Name)
265276
plugin, err := plugins.CreateOutput(clusterOutput.Spec.OutputSpec, outputId, secret.NewSecretLoader(l.client, clusterOutput.Namespace, fluentd.OutputSecretPath, l.Secrets))
266277
if err != nil {
267278
multierr = errors.Combine(multierr, errors.WrapIff(err, "failed to create configured output %s", outputRef))
@@ -278,7 +289,7 @@ FindOutputForAllRefs:
278289
// Filter
279290
var filters []types.Filter
280291
for i, f := range commonFlow.Filters {
281-
id := fmt.Sprintf("%s_%s_%d", commonFlow.Namespace, commonFlow.Name, i)
292+
id := fmt.Sprintf("%s:%s:%s:%d", flowType, commonFlow.Namespace, commonFlow.Name, i)
282293
filter, err := plugins.CreateFilter(f, id, secret.NewSecretLoader(l.client, commonFlow.Namespace, fluentd.OutputSecretPath, l.Secrets))
283294
if err != nil {
284295
multierr = errors.Combine(multierr, errors.WrapIff(err, "failed to create filter with index %d for flow %s", i, commonFlow.Name))

pkg/sdk/model/filter/concat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (c *Concat) ToDirective(secretLoader secret.SecretLoader, id string) (types
101101
Type: pluginType,
102102
Directive: "filter",
103103
Tag: "**",
104-
Id: id + "_" + pluginType,
104+
Id: id,
105105
},
106106
}
107107
concatConfig := c.DeepCopy()

pkg/sdk/model/filter/dedot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ func (c *DedotFilterConfig) ToDirective(secretLoader secret.SecretLoader, id str
8080
Type: pluginType,
8181
Directive: "filter",
8282
Tag: "**",
83-
Id: id + "_" + pluginType,
83+
Id: id,
8484
}, c, secretLoader)
8585
}

pkg/sdk/model/filter/detect_exceptions.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,12 @@ type _expDetectExceptions interface{}
9696

9797
func (d *DetectExceptions) ToDirective(secretLoader secret.SecretLoader, id string) (types.Directive, error) {
9898
pluginType := "detect_exceptions"
99-
pluginID := id + "_" + pluginType
10099
detector := &types.OutputPlugin{
101100
PluginMeta: types.PluginMeta{
102101
Type: pluginType,
103102
Directive: "match",
104103
Tag: "kubernetes.**",
105-
Id: pluginID,
104+
Id: id,
106105
},
107106
}
108107
detect := d.DeepCopy()

pkg/sdk/model/filter/geoip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (g *GeoIP) ToDirective(secretLoader secret.SecretLoader, id string) (types.
9797
Type: pluginType,
9898
Directive: "filter",
9999
Tag: "**",
100-
Id: id + "_" + pluginType,
100+
Id: id,
101101
},
102102
}
103103
if params, err := types.NewStructToStringMapper(secretLoader).StringsMap(g); err != nil {

pkg/sdk/model/filter/grep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func (g *GrepConfig) ToDirective(secretLoader secret.SecretLoader, id string) (t
298298
Type: pluginType,
299299
Directive: "filter",
300300
Tag: "**",
301-
Id: id + "_" + pluginType,
301+
Id: id,
302302
},
303303
}
304304
if len(g.Regexp) > 0 {

pkg/sdk/model/filter/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (p *ParserConfig) ToDirective(secretLoader secret.SecretLoader, id string)
191191
Type: pluginType,
192192
Directive: "filter",
193193
Tag: "**",
194-
Id: id + "_" + pluginType,
194+
Id: id,
195195
},
196196
}
197197
parserConfig := p.DeepCopy()

pkg/sdk/model/filter/prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (p *PrometheusConfig) ToDirective(secretLoader secret.SecretLoader, id stri
156156
Type: pluginType,
157157
Directive: "filter",
158158
Tag: "**",
159-
Id: id + "_" + pluginType,
159+
Id: id,
160160
},
161161
}
162162

pkg/sdk/model/filter/record_modifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (r *RecordModifier) ToDirective(secretLoader secret.SecretLoader, id string
106106
Type: pluginType,
107107
Directive: "filter",
108108
Tag: "**",
109-
Id: id + "_" + pluginType,
109+
Id: id,
110110
},
111111
}
112112
if params, err := types.NewStructToStringMapper(secretLoader).StringsMap(r); err != nil {

pkg/sdk/model/filter/record_transformer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (r *RecordTransformer) ToDirective(secretLoader secret.SecretLoader, id str
103103
Type: pluginType,
104104
Directive: "filter",
105105
Tag: "**",
106-
Id: id + "_" + pluginType,
106+
Id: id,
107107
},
108108
}
109109
if params, err := types.NewStructToStringMapper(secretLoader).StringsMap(r); err != nil {

0 commit comments

Comments
 (0)