MCPcopy Index your code
hub / github.com/IBM/fluent-forward-go

github.com/IBM/fluent-forward-go @v0.4.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.0 ↗ · + Follow
753 symbols 1,840 edges 47 files 148 documented · 20% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

fluent-forward-go

fluent-forward-go is a fast, memory-efficient implementation of the Fluent Forward v1 specification. It allows you to send events to Fluentd, Fluent Bit, and other endpoints supporting the Fluent protocol. It also includes a websocket client for high-speed proxying of Fluent events over ports such as 80 and 443.

Features include:

  • TCP, TLS, mTLS, and unix socket transport
  • shared-key authentication
  • support for all Fluent message modes
  • gzip compression
  • ability to send byte-encoded messages
  • ack support
  • a websocket client for proxying Fluent messages

Installation

go get github.com/IBM/fluent-forward-go

Examples

Create a TCP client

c := client.New(client.ConnectionOptions{
  Factory: &client.ConnFactory{
    Address: "localhost:24224",
  },
})
if err := c.Connect(); err != nil {
  // ...
}
defer c.Disconnect()

Create a TLS client

c := client.New(client.ConnectionOptions{
  Factory: &client.ConnFactory{
    Address: "localhost:24224",
    TLSConfig: &tls.Config{InsecureSkipVerify: true},
  },
})
if err := c.Connect(); err != nil {
  // ...
}
defer c.Disconnect()

Send a new log message

The record object must be a map or struct. Objects that implement the msgp.Encodable interface will the be most performant.

record := map[string]interface{}{
  "Hello": "World",
}
err := c.SendMessage("tag", record)

Send a byte-encoded message

err := c.SendRaw(myMessageBytes)

Message confirmation

The client supports ack confirmations as specified by the Fluent protocol. When enabled, Send returns once the acknowledgement is received or the timeout is reached.

Note: For types other than RawMessage, the Send function sets the "chunk" option before sending. A RawMessage is immutable and must already contain a "chunk" value. The behavior is otherwise identical.

c := client.New(client.ConnectionOptions{
  RequireAck: true,
})
//...
err := c.Send(myMsg)

Performance

tl;dr fluent-forward-go is fast and memory efficient.

You can read more about the benchmarks here.

Send

Run on localhost. Does not include message creation.

Benchmark_Fluent_Forward_Go_SendOnly-16      10000      10847 ns/op      0 B/op      0 allocs/op

Comparisons with fluent-logger-golang

The benchmarks below compare fluent-forward-go with the official package, fluent-logger-golang. The message is a simple map with twelve keys.

The differences in execution times can vary from one test run to another. The differences in memory allocations, however, are constant.

Send a single message

Benchmark_Fluent_Forward_Go_SingleMessage-16         10000       11355 ns/op          48 B/op          1 allocs/op
Benchmark_Fluent_Logger_Golang_SingleMessage-16      10000       19687 ns/op        2169 B/op         33 allocs/op

Send a single message with confirmation

Benchmark_Fluent_Forward_Go_SingleMessageAck-16       10000     768743 ns/op         185 B/op          6 allocs/op
Benchmark_Fluent_Logger_Golang_SingleMessageAck-16    10000     793360 ns/op        6015 B/op         47 allocs/op

Developing

Installation instructions

Before running the generate tool, you must have msgp installed. To install run:

go get github.com/tinylib/msgp

Afterwards, generate the msgp packets with:

go generate ./...

Testing

To test against fluent-bit, start up fluent-bit in a docker container with:

docker pull fluent/fluent-bit:1.8.2
docker run -p 127.0.0.1:24224:24224/tcp -v `pwd`:`pwd` -w `pwd` \
  -ti fluent/fluent-bit:1.8.2 /fluent-bit/bin/fluent-bit \
  -c $(pwd)/fixtures/fluent.conf

You can then build and run with:

go run ./cmd/forward -t foo.bar

This will send two regular Messages, one with the timestamp as seconds since the epoch, the other with the timestamp as seconds.nanoseconds. Those will then be written to a file with the same name as the tag supplied as the argument to the -t flag (foo.bar in the above example).

It will also send a ForwardMessage containing a pair of events - these will be written to the same file.

It will then send a PackedForwardMessage containing a pair of events - these will be written to $TAG.packed.

Last, it will send a CompressedPackedForwardMessage with the same pair of events, which should then be written to $TAG.compressed.

Extension points exported contracts — how you extend this code

ConnectionFactory (Interface)
ConnectionFactory implementations create new connections counterfeiter:generate . ConnectionFactory [5 implementers]
fluent/client/client.go
ChunkEncoder (Interface)
ChunkEncoder wraps methods to encode a message and generate "chunk" IDs for use with Fluent's chunk-ack protocol. See ht [4 …
fluent/protocol/chunk.go
WSConnectionFactory (Interface)
counterfeiter:generate . WSConnectionFactory [3 implementers]
fluent/client/ws_client.go
MessageClient (Interface)
MessageClient implementations send MessagePack messages to a peer counterfeiter:generate . MessageClient [2 implementers]
fluent/client/client.go
Connection (Interface)
counterfeiter:generate . Connection [2 implementers]
fluent/client/ws/connection.go
Conn (Interface)
go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate Conn is an interface for websocket.Conn. Generated [2 …
fluent/client/ws/ext/conn.go

Core symbols most depended-on inside this repo

Error
called by 70
fluent/client/errors.go
Len
called by 43
fluent/protocol/transport.go
Connect
called by 32
fluent/client/client.go
Close
called by 30
fluent/client/ws/ext/conn.go
recordInvocation
called by 29
fluent/client/ws/wsfakes/fake_connection.go
New
called by 28
fluent/client/client.go
Println
called by 25
fluent/client/ws/connection.go
Equal
called by 24
fluent/protocol/transport.go

Shape

Method 561
Function 142
Struct 39
Interface 7
TypeAlias 3
FuncType 1

Languages

Go100%

Modules by API surface

fluent/client/ws/wsfakes/fake_connection.go151 symbols
fluent/client/ws/ext/extfakes/fake_conn.go115 symbols
fluent/client/clientfakes/fake_message_client.go72 symbols
fluent/protocol/transport_gen_test.go42 symbols
fluent/client/client.go37 symbols
fluent/client/ws/connection.go36 symbols
fluent/protocol/transport_gen.go32 symbols
fluent/protocol/handshake_gen_test.go28 symbols
fluent/client/ws_client.go23 symbols
fluent/client/ws/ext/conn.go23 symbols
fluent/protocol/transport.go20 symbols
fluent/protocol/handshake_gen.go20 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add fluent-forward-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page