Skip to content

Commit

Permalink
rename file so git tracking is better
Browse files Browse the repository at this point in the history
  • Loading branch information
davemarco committed Aug 13, 2024
1 parent c9a93c3 commit 15cef30
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions internal/irzstd/writer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Package implements writer that converts log events to Zstd compressed IR. Effectively chaining
// together [ir.Writer] and [zstd.Encoder] in series.

package irzstd

import (
"fmt"
"io"

"github.com/klauspost/compress/zstd"

"github.com/y-scope/clp-ffi-go/ffi"
"github.com/y-scope/clp-ffi-go/ir"
)

type Writer interface {

Check failure on line 16 in internal/irzstd/writer.go

View workflow job for this annotation

GitHub Actions / go-lint (1.22, macos-latest)

Writer redeclared in this block

Check failure on line 16 in internal/irzstd/writer.go

View workflow job for this annotation

GitHub Actions / go-lint (1.22, macos-latest)

Writer redeclared in this block
// Converts log events to Zstd compressed IR and outputs to the Zstd buffer.
//
// Parameters:
// - logEvents: A slice of log events to be encoded
//
// Returns:
// - err
WriteIrZstd([]ffi.LogEvent) error

// Closes IR stream and Zstd frame. After calling close, Writer must be Reset() prior to calling
// write.
//
// Returns:
// - err
CloseStreams() error

// Closes Writer.
//
// Returns:
// - err
Close() error

// Reinitialize Writer after calling CloseStreams().
//
// Returns:
// - err
Reset() error

// Getter for useDiskBuffer.
//
// Returns:
// - useDiskBuffer: On/off for disk buffering
GetUseDiskBuffer() bool

// Getter for Zstd Output.
//
// Returns:
// - zstdOutput: Reader for Zstd output
GetZstdOutput() io.Reader

// Get size of Zstd output.
//
// Returns:
// - size: Bytes written
// - err
GetZstdOutputSize() (int, error)
}

// Writes log events to a IR Writer.
//
// Parameters:
// - irWriter: CLP IR writer to write each log event with
// - logEvents: A slice of log events to be encoded
//
// Returns:
// - err: error if an event could not be written
func writeIr(irWriter *ir.Writer, logEvents []ffi.LogEvent) error {

Check failure on line 73 in internal/irzstd/writer.go

View workflow job for this annotation

GitHub Actions / go-lint (1.22, macos-latest)

writeIr redeclared in this block

Check failure on line 73 in internal/irzstd/writer.go

View workflow job for this annotation

GitHub Actions / go-lint (1.22, macos-latest)

writeIr redeclared in this block
for _, event := range logEvents {
_, err := irWriter.Write(event)
if err != nil {
err = fmt.Errorf("failed to encode event %v into ir: %w", event, err)
return err
}
}
return nil
}

// Opens a new [ir.Writer] and [zstd.Encoder].
//
// Parameters:
// - zstdOutput: Output location for Zstd
// - timezone: Time zone of the log source
// - size: Byte length
//
// Returns:
// - irWriter: Writer for CLP IR
// - ZstdWriter: Writer for Zstd
// - err: Error opening IR/Zstd writer
func newIrZstdWriters(

Check failure on line 95 in internal/irzstd/writer.go

View workflow job for this annotation

GitHub Actions / go-lint (1.22, macos-latest)

newIrZstdWriters redeclared in this block
zstdOutput io.Writer,
timezone string,
size int,
) (*ir.Writer, *zstd.Encoder, error) {
// IR buffer using bytes.Buffer internally, so it will dynamically grow if undersized. Using
// FourByteEncoding as default encoding.
irWriter, err := ir.NewWriterSize[ir.FourByteEncoding](size, timezone)
if err != nil {
return nil, nil, fmt.Errorf("error opening IR writer: %w", err)
}

zstdWriter, err := zstd.NewWriter(zstdOutput)
if err != nil {
return nil, nil, fmt.Errorf("error opening Zstd writer: %w", err)
}
return irWriter, zstdWriter, err
}

0 comments on commit 15cef30

Please sign in to comment.