How can a Format get access to custom fields in a ProtoProducerMessage?

Open
#422 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
24/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
go

Research direction

Start by reading the custom Format interface and ProtoProducerMessage implementation, especially the unexported mapUnknown method mentioned in the issue. Check how the built-in JSON and Text formatters expose custom fields and how YAML maps the NFv9 fields to protobuf fields 901–904. Done means a custom Format can access the needed IN_BYTES and IN_PACKETS values while using the existing NFv9 producer.

Written by the indexing model from the issue text.

Description

Not sure where to ask this, so I filed an issue. Let me know if there is a better channel for questions.

I am trying to migrate netflow2ng to goflow2.

In order to do this, I am using goflow2 to as a library, and I wrote and registered a couple of new Formats (there's a custom JSON format and a another custom binary format), and then a ZMQ Transport. I have the basics of this working.

As part of doing this, I ran into Issue #186, where goflow2 will prefer OUT_BYTES/OUT_PACKETS for the values for the FlowMessage.Bytes/Packets Protobuf. To get around this, I followed the advice in that thread and used a Yaml config to map all four IN/OUT NFv9 fields to custom proto fields (901, 902, 903, 904).

My problem is that from inside my new Formats Format() function, I am passed an interface which is really a ProtoProducerMessage, which is a wrapper around a FlowMessage. I cannot figure out a way to access the custom proto fields (901, 902, 903, 904) in ProtoProducerMessage. I have verified they are there. If I use the built in Json or Text formatters, these fields are there. But looking at the goflow2 code, it tools like doing that relies on ProtoProducerMessage.mapUnknown(), which is not exported.

What's the right way to do this?

TL;DR: I want to write my own Formats that has access to both IN_BYTES and OUT_BYTES from NFv9. I don't think I want my own Producer, I'm happy with all the work the current NFv9 sampling producer is doing, I just need to keep IN_BYTES and OUT_BYTES. Actually I really only need to keep IN_BYTES, IN_PACKETS.

Dominant language
Go
Stars
817
Forks
182
Avg merge
4h 18m
Merged PRs (30d)
6

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from netsampler/goflow2

All issues in netsampler/goflow2

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.