Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse API data structures in confgen #254

Closed
ronensc opened this issue Jul 13, 2022 · 0 comments · Fixed by #267, #251 or #262
Closed

Reuse API data structures in confgen #254

ronensc opened this issue Jul 13, 2022 · 0 comments · Fixed by #267, #251 or #262
Assignees

Comments

@ronensc
Copy link
Collaborator

ronensc commented Jul 13, 2022

The config created by confgen is generated from nested map[string]interface{} rather than reusing the structs defined in api and config

func (cg *ConfGen) generateFlowlogs2PipelineConfig() map[string]interface{} {
config := map[string]interface{}{
"log-level": "error",
"pipeline": []map[string]string{
{"name": "ingest_collector"},
{"name": "transform_generic",
"follows": "ingest_collector",
},
{"name": "transform_network",
"follows": "transform_generic",
},
{"name": "extract_aggregate",
"follows": "transform_network",
},
{"name": "encode_prom",
"follows": "extract_aggregate",
},
{"name": "write_loki",
"follows": "transform_network",
},
},
"parameters": []map[string]interface{}{
{"name": "ingest_collector",
"ingest": map[string]interface{}{
"type": "collector",
"collector": map[string]interface{}{
"port": cg.config.Ingest.Collector.Port,
"portLegacy": cg.config.Ingest.Collector.PortLegacy,
"hostname": cg.config.Ingest.Collector.HostName,
},
},
},
{"name": "transform_generic",
"transform": map[string]interface{}{
"type": "generic",
"generic": map[string]interface{}{
"policy": "replace_keys",
"rules": cg.config.Transform.Generic.Rules,
},
},
},
{"name": "transform_network",
"transform": map[string]interface{}{
"type": "network",
"network": map[string]interface{}{
"rules": cg.transformRules,
},
},
},
{"name": "extract_aggregate",
"extract": map[string]interface{}{
"type": "aggregates",
"aggregates": cg.aggregateDefinitions,
},
},
{"name": "encode_prom",
"encode": map[string]interface{}{
"type": "prom",
"prom": map[string]interface{}{
"port": cg.config.Encode.Prom.Port,
"prefix": cg.config.Encode.Prom.Prefix,
"metrics": cg.promMetrics,
},
},
},
{"name": "write_loki",
"write": map[string]interface{}{
"type": cg.config.Write.Type,
"loki": cg.config.Write.Loki,
},
},
},
}
return config
}
func (cg *ConfGen) generateTruncatedConfig(stages []string) map[string]interface{} {
parameters := make([]map[string]interface{}, len(stages))
for i, stage := range stages {
switch stage {
case "ingest":
parameters[i] = map[string]interface{}{
"name": "ingest_collector",
"ingest": map[string]interface{}{
"type": "collector",
"collector": map[string]interface{}{
"port": cg.config.Ingest.Collector.Port,
"portLegacy": cg.config.Ingest.Collector.PortLegacy,
"hostname": cg.config.Ingest.Collector.HostName,
},
},
}
case "transform_generic":
parameters[i] = map[string]interface{}{
"name": "transform_generic",
"transform": map[string]interface{}{
"type": "generic",
"generic": map[string]interface{}{
"policy": "replace_keys",
"rules": cg.config.Transform.Generic.Rules,
},
},
}
case "transform_network":
parameters[i] = map[string]interface{}{
"name": "transform_network",
"transform": map[string]interface{}{
"type": "network",
"network": map[string]interface{}{
"rules": cg.transformRules,
},
},
}
case "extract_aggregate":
parameters[i] = map[string]interface{}{
"name": "extract_aggregate",
"extract": map[string]interface{}{
"type": "aggregates",
"aggregates": cg.aggregateDefinitions,
},
}
case "encode_prom":
parameters[i] = map[string]interface{}{
"name": "encode_prom",
"encode": map[string]interface{}{
"type": "prom",
"prom": map[string]interface{}{
"port": cg.config.Encode.Prom.Port,
"prefix": cg.config.Encode.Prom.Prefix,
"metrics": cg.promMetrics,
},
},
}
case "write_loki":
parameters[i] = map[string]interface{}{
"name": "write_loki",
"write": map[string]interface{}{
"type": cg.config.Write.Type,
"loki": cg.config.Write.Loki,
},
}
}
}
log.Debugf("parameters = %v \n", parameters)
config := map[string]interface{}{
"parameters": parameters,
}
return config
}

The pipeline config builder could also become handy
https://github.com/netobserv/flowlogs-pipeline/blob/main/pkg/config/pipeline_builder.go

@jotak jotak self-assigned this Jul 25, 2022
jotak added a commit to jotak/flowlogs-pipeline that referenced this issue Jul 25, 2022
Fixes netobserv#254

- Removed duplicated confgen model
- Use PipelineBuilder to simplify pipeline generation
- Make confgen easier to consume as a lib (e.g. for NOO)
  - Do not make it necessary to call "Run": parsing definition files
    should be sufficient
  - Do not make it necessary to work with files written on disk: work
    with []byte instead
- SkipWithTags should not result in an error when a file is skipped
- Add confgen tests
jotak added a commit to jotak/flowlogs-pipeline that referenced this issue Jul 26, 2022
Fixes netobserv#254

- Removed duplicated confgen model
- Use PipelineBuilder to simplify pipeline generation
- Make confgen easier to consume as a lib (e.g. for NOO)
  - Do not make it necessary to call "Run": parsing definition files
    should be sufficient
  - Do not make it necessary to work with files written on disk: work
    with []byte instead
- SkipWithTags should not result in an error when a file is skipped
- Add confgen tests
jotak added a commit to jotak/flowlogs-pipeline that referenced this issue Jul 26, 2022
Fixes netobserv#254

- Removed duplicated confgen model
- Use PipelineBuilder to simplify pipeline generation
- Make confgen easier to consume as a lib (e.g. for NOO)
  - Do not make it necessary to call "Run": parsing definition files
    should be sufficient
  - Do not make it necessary to work with files written on disk: work
    with []byte instead
- SkipWithTags should not result in an error when a file is skipped
- Add confgen tests
jotak added a commit to jotak/flowlogs-pipeline that referenced this issue Jul 29, 2022
Fixes netobserv#254

- Removed duplicated confgen model
- Use PipelineBuilder to simplify pipeline generation
- Make confgen easier to consume as a lib (e.g. for NOO)
  - Do not make it necessary to call "Run": parsing definition files
    should be sufficient
  - Do not make it necessary to work with files written on disk: work
    with []byte instead
- SkipWithTags should not result in an error when a file is skipped
- Add confgen tests
jotak added a commit that referenced this issue Jul 29, 2022
* Confgen: init from options (avoid many globals)

* Use main model in confgen, use pipeline builder

Fixes #254

- Removed duplicated confgen model
- Use PipelineBuilder to simplify pipeline generation
- Make confgen easier to consume as a lib (e.g. for NOO)
  - Do not make it necessary to call "Run": parsing definition files
    should be sufficient
  - Do not make it necessary to work with files written on disk: work
    with []byte instead
- SkipWithTags should not result in an error when a file is skipped
- Add confgen tests

* Avoid using globals

A side-effect of removing globals in write_loki is that it changes how
the config is read, and set with defaults. Instead of unmarshaling a
second time to automatically get defaults, we now call an explicit function
that sets the default. Also, now removing loki URL default, it now has
to be set explicitely

* Update ConnTrack builder

* More defer cleanup in tests, and use ioutils / temp dir/files

Also fixed jsonnet dir actually used as filename prefix rather than
directory

* User ConfigFileStruct in confgen

* Update pkg/config/config.go

Co-authored-by: Ronen Schaffer <ronen.schaffer@ibm.com>

* Use config.ConfigFileStruct in tests

Co-authored-by: Ronen Schaffer <ronen.schaffer@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment