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

Add ingest_stdin #488

Merged
merged 3 commits into from
Sep 27, 2023
Merged

Add ingest_stdin #488

merged 3 commits into from
Sep 27, 2023

Conversation

ronensc
Copy link
Collaborator

@ronensc ronensc commented Sep 11, 2023

This PR adds a standard input ingester.
Currently it supports only json formats and assumes each line corresponds to a flowlog.
Closes #486.

Simple configuration to test it:

cat << EOF > ./conf.yaml
log-level: trace
metricsSettings:
  prefix: flp_operational_
pipeline:
  - name: ingest_stdin
  - name: write_stdout
    follows: ingest_stdin
parameters:
  - name: ingest_stdin
    ingest:
      type: stdin
      stdin:
  - name: write_stdout
    write:
      type: stdout
      stdout:
        format: fields
EOF

Run FLP:

./flowlogs-pipeline --config conf.yaml

and type:

{"SrcIP":"0.0.0.0"}

This also allows Unix pipeline:

echo -e '{"SrcIP":"0.0.0.0"}\n{"DstIP":"1.2.3.4"}'  | ./flowlogs-pipeline --config conf.yaml

cc @aslom

@ronensc ronensc requested review from jotak and KalmanMeth September 11, 2023 12:51
@codecov
Copy link

codecov bot commented Sep 11, 2023

Codecov Report

Attention: 60 lines in your changes are missing coverage. Please review.

Comparison is base (914d470) 66.03% compared to head (7525f2d) 67.04%.
Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #488      +/-   ##
==========================================
+ Coverage   66.03%   67.04%   +1.01%     
==========================================
  Files          94       94              
  Lines        6921     6707     -214     
==========================================
- Hits         4570     4497      -73     
+ Misses       2092     1944     -148     
- Partials      259      266       +7     
Flag Coverage Δ
unittests 67.04% <1.63%> (+1.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
pkg/api/encode_prom.go 100.00% <ø> (ø)
pkg/confgen/flowlogs2metrics_config.go 68.83% <100.00%> (ø)
pkg/config/config.go 78.78% <ø> (ø)
cmd/flowlogs-pipeline/main.go 48.93% <0.00%> (-0.71%) ⬇️
pkg/pipeline/pipeline_builder.go 70.15% <0.00%> (-0.45%) ⬇️
pkg/pipeline/ingest/ingest_stdin.go 0.00% <0.00%> (ø)

... and 14 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 98 to 104
if params.Ingest == nil || params.Ingest.Stdin == nil || params.Ingest.Stdin.Decoder.Type == "" {
return nil, fmt.Errorf("stdin decoder not specified")
}
decoderType := params.Ingest.Stdin.Decoder.Type
if decoderType != api.DecoderName("JSON") {
return nil, fmt.Errorf("stdin supports only json decoder. Given decoder type: %v", decoderType)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say, if only JSON is supported, maybe do not make it configurable? Like we're doing with grpc => it assumes protobuf.
Or if you really prefer to make it configurable, maybe it should assume json as a default when unset.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll go with the first option.

func NewIngestStdin(opMetrics *operational.Metrics, params config.StageParam) (Ingester, error) {
slog.Debugf("Entering NewIngestStdin")

in := make(chan string, channelSize)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should channelSize now be moved to a more central location (perhaps ingest.go)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I introduced a new constant stdinChannelSize to decouple the stdin ingester from the other ingester.

@jotak
Copy link
Member

jotak commented Sep 21, 2023

/lgtm
(but I also agree with the remark about channelSize)

@openshift-ci openshift-ci bot removed the lgtm label Sep 26, 2023
@openshift-ci
Copy link

openshift-ci bot commented Sep 26, 2023

New changes are detected. LGTM label has been removed.

@openshift-ci
Copy link

openshift-ci bot commented Sep 26, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from jotak. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jotak jotak self-requested a review September 27, 2023 12:59
@jotak
Copy link
Member

jotak commented Sep 27, 2023

thanks @ronensc !

@jotak jotak merged commit 0341828 into netobserv:main Sep 27, 2023
5 checks passed
@ronensc ronensc deleted the ingest_stdin branch September 27, 2023 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add ingest stdin
3 participants