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

Update infrastructure #31

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.15', '1.14' ]
go: [ '1.23', '1.22', '1.21' ]
name: Go ${{ matrix.go }} test
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Go stable version
if: matrix.go != 'tip'
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Install Go tip
if: matrix.go == 'tip'
run: |
git clone --depth=1 https://go.googlesource.com/go $HOME/gotip
cd $HOME/gotip/src
./make.bash
echo "::set-env name=GOROOT::$HOME/gotip"
echo "::add-path::$HOME/gotip/bin"
echo "::add-path::$(go env GOPATH)/bin"
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
- name: Test
run: go test -v -race ./...
- name: Upload code coverage to codecov
if: matrix.go == '1.15'
uses: codecov/codecov-action@v1
with:
file: ./coverage.out

16 changes: 11 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
name: lint
on: [push, pull_request]
on:
push:

jobs:
golangci:
name: lint
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
version: v1.34.1
go-version-file: "go.mod"
- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
args: "--timeout 5m0s"
53 changes: 48 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
run:
skip-dirs: internal

linters-settings:
govet:
enable-all: true
disable:
- shadow
- fieldalignment

linters:
enable-all: true
disable:
- cyclop
- depguard
- dupl
- exhaustive
- exhaustivestruct
- errorlint
- err113
- funlen
- gci
- gochecknoglobals
Expand All @@ -23,30 +25,71 @@ linters:
- gocyclo
- godot
- godox
- goerr113
- gofumpt
- gomnd
- gosec
- govet
- inamedparam # oh, sod off
- ireturn # No, I _LIKE_ returning interfaces
- lll
- maintidx # Do this in code review
- makezero
- mnd
- nakedret
- nestif
- nlreturn
- nonamedreturns # visit this back later
- paralleltest
- perfsprint
- tagliatelle
- testifylint # TODO: revisit when we have the chance
- testpackage
- thelper
- unconvert
- thelper # Tests are fine
- varnamelen # Short names are ok
- wrapcheck
- wsl

issues:
exclude-rules:
# not needed
- path: /*.go
text: "ST1003: should not use underscores in package names"
linters:
- stylecheck
- path: /*.go
text: "don't use an underscore in package name"
linters:
- revive
- path: /*.go
linters:
- contextcheck
- exhaustruct
- path: /main.go
linters:
- errcheck
- path: internal/codegen/codegen.go
linters:
- errcheck
- path: internal/jwxtest/jwxtest.go
linters:
- errcheck
- errchkjson
- forcetypeassert
- path: /*_test.go
linters:
- errcheck
- errchkjson
- forcetypeassert
- path: /*_example_test.go
linters:
- forbidigo
- path: cmd/jwx/jwx.go
linters:
- forbidigo
- path: /*_test.go
text: "var-naming: "
litners:
- revive

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
Expand Down
38 changes: 21 additions & 17 deletions buffered.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
// NewBuffered creates a new Buffered client.
// Options may be one of the following:
//
// * fluent.WithAddress
// * fluent.WithBufferLimit
// * fluent.WithDialTimeout
// * fluent.WithJSONMarshaler
// * fluent.WithMaxConnAttempts
// * fluent.WithMsgpackMarshaler
// * fluent.WithNetwork
// * fluent.WithTagPrefix
// * fluent.WithWriteThreshold
// * fluent.WithWriteQueueSize
// - fluent.WithAddress
// - fluent.WithBufferLimit
// - fluent.WithDialTimeout
// - fluent.WithJSONMarshaler
// - fluent.WithMaxConnAttempts
// - fluent.WithMsgpackMarshaler
// - fluent.WithNetwork
// - fluent.WithTagPrefix
// - fluent.WithWriteThreshold
// - fluent.WithWriteQueueSize
//
// Please see their respective documentation for details.
func NewBuffered(options ...Option) (client *Buffered, err error) {
Expand All @@ -37,6 +37,7 @@ func NewBuffered(options ...Option) (client *Buffered, err error) {
ctx, cancel := context.WithCancel(context.Background())

var subsecond bool
//nolint:forcetypeassert
for _, opt := range options {
switch opt.Ident() {
case identSubSecond{}:
Expand All @@ -62,17 +63,16 @@ func NewBuffered(options ...Option) (client *Buffered, err error) {
// If you would like to specify options to `Post()`, you may pass them at the end of
// the method. Currently you can use the following:
//
// fluent.WithContext: specify context.Context to use
// fluent.WithTimestamp: allows you to set arbitrary timestamp values
// fluent.WithSyncAppend: allows you to verify if the append was successful
// fluent.WithContext: specify context.Context to use
// fluent.WithTimestamp: allows you to set arbitrary timestamp values
// fluent.WithSyncAppend: allows you to verify if the append was successful
//
// If fluent.WithSyncAppend is provide and is true, the following errors
// may be returned:
//
// 1. If the current underlying pending buffer is is not large enough to
// hold this new data, an error will be returned
// 2. If the marshaling into msgpack/json failed, it is returned
//
// 1. If the current underlying pending buffer is not large enough to
// hold this new data, an error will be returned
// 2. If the marshaling into msgpack/json failed, it is returned
func (c *Buffered) Post(tag string, v interface{}, options ...Option) (err error) {
if pdebug.Enabled {
g := pdebug.Marker("fluent.Buffered.Post").BindError(&err)
Expand All @@ -90,6 +90,7 @@ func (c *Buffered) Post(tag string, v interface{}, options ...Option) (err error
var subsecond = c.subsecond
var t time.Time
var ctx = context.Background()
//nolint:forcetypeassert
for _, opt := range options {
switch opt.Ident() {
case identTimestamp{}:
Expand All @@ -102,6 +103,7 @@ func (c *Buffered) Post(tag string, v interface{}, options ...Option) (err error
if pdebug.Enabled {
pdebug.Printf("client: using user-supplied context")
}
//nolint:fatcontext
ctx = opt.Value().(context.Context)
}
}
Expand Down Expand Up @@ -220,6 +222,7 @@ func (c *Buffered) Ping(tag string, record interface{}, options ...Option) (err
var ctx = context.Background()
var subsecond bool
var t time.Time
//nolint:forcetypeassert
for _, opt := range options {
switch opt.Ident() {
case identSubSecond{}:
Expand All @@ -230,6 +233,7 @@ func (c *Buffered) Ping(tag string, record interface{}, options ...Option) (err
if pdebug.Enabled {
pdebug.Printf("client: using user-supplied context")
}
//nolint:fatcontext
ctx = opt.Value().(context.Context)
}
}
Expand Down
13 changes: 7 additions & 6 deletions errors.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package fluent

type bufferFullErr struct{}
type bufferFuller interface {
//nolint:errname
type errBufferFull struct{}
type errBufferFuller interface {
BufferFull() bool
}
type causer interface {
Cause() error
}

// Just need one instance
var bufferFullErrInstance bufferFullErr
var errBufferFullInstance errBufferFull

// IsBufferFull returns true if the error is a BufferFull error
func IsBufferFull(e error) bool {
for e != nil {
if berr, ok := e.(bufferFuller); ok {
if berr, ok := e.(errBufferFuller); ok {
return berr.BufferFull()
}

Expand All @@ -25,10 +26,10 @@ func IsBufferFull(e error) bool {
return false
}

func (e *bufferFullErr) BufferFull() bool {
func (e *errBufferFull) BufferFull() bool {
return true
}

func (e *bufferFullErr) Error() string {
func (e *errBufferFull) Error() string {
return `buffer full`
}
1 change: 1 addition & 0 deletions fluent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package fluent
// respectively.
func New(options ...Option) (Client, error) {
var buffered = true
//nolint:forcetypeassert
for _, opt := range options {
switch opt.Ident() {
case identBuffered{}:
Expand Down
5 changes: 3 additions & 2 deletions fluent_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ExamplePing() {
return
}

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

// Goroutine to wait for errors
Expand All @@ -75,6 +75,7 @@ func ExamplePing() {
}()

go fluent.Ping(ctx, client, "ping", "hostname", fluent.WithPingResultChan(errorCh))

// Do what you need with your main program...

// OUTPUT:
}
20 changes: 7 additions & 13 deletions fluent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -35,7 +34,7 @@ type server struct {
}

func newServer(useJSON bool) (*server, error) {
dir, err := ioutil.TempDir("", "sock-")
dir, err := os.MkdirTemp("", "sock-")
if err != nil {
return nil, errors.Wrap(err, `failed to create temporary directory`)
}
Expand Down Expand Up @@ -252,12 +251,11 @@ func (s *server) Run(ctx context.Context) {

func TestConnectOnStart(t *testing.T) {
for _, buffered := range []bool{true, false} {
buffered := buffered
t.Run(fmt.Sprintf("failure case, buffered=%t", buffered), func(t *testing.T) {
// find a port that is not available (this may be timing dependent)
var dialer net.Dialer
var port int = 22412
for i := 0; i < 1000; i++ {
port := 22412
for range 1000 {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
conn, err := dialer.DialContext(ctx, `net`, fmt.Sprintf(`127.0.0.1:%d`, port))
cancel()
Expand Down Expand Up @@ -295,7 +293,6 @@ func TestConnectOnStart(t *testing.T) {
<-s.Ready()

for _, buffered := range []bool{true, false} {
buffered := buffered
t.Run(fmt.Sprintf("normal case, buffered=%t", buffered), func(t *testing.T) {
client, err := fluent.New(
fluent.WithNetwork(s.Network),
Expand Down Expand Up @@ -490,7 +487,6 @@ func (msg *badmsgpack) EncodeMsgpack(_ *msgpack.Encoder) error {

func TestPostSync(t *testing.T) {
for _, syncAppend := range []bool{true, false} {
syncAppend := syncAppend
t.Run("sync="+strconv.FormatBool(syncAppend), func(t *testing.T) {
s, err := newServer(false)
if !assert.NoError(t, err, "newServer should succeed") {
Expand Down Expand Up @@ -548,8 +544,8 @@ func TestPostSync(t *testing.T) {
}

type Payload struct {
Foo string `msgpack:"foo" json:"foo"`
Bar string `msgpack:"bar" json:"bar"`
Foo string `json:"foo" msgpack:"foo"`
Bar string `json:"bar" msgpack:"bar"`
}

func TestPostRoundtrip(t *testing.T) {
Expand All @@ -562,7 +558,6 @@ func TestPostRoundtrip(t *testing.T) {
}

for _, buffered := range []bool{true, false} {
buffered := buffered
t.Run(fmt.Sprintf("buffered=%t", buffered), func(t *testing.T) {
var options []fluent.Option
if !buffered {
Expand Down Expand Up @@ -672,13 +667,12 @@ func TestPostRoundtrip(t *testing.T) {

func TestPing(t *testing.T) {
for _, buffered := range []bool{true, false} {
buffered := buffered
t.Run(fmt.Sprintf("buffered=%t", buffered), func(t *testing.T) {
t.Run("Ping with no server", func(t *testing.T) {
// find a port that is not available (this may be timing dependent)
var dialer net.Dialer
var port int = 22412
for i := 0; i < 1000; i++ {
port := 22412
for range 1000 {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
conn, err := dialer.DialContext(ctx, `net`, fmt.Sprintf(`127.0.0.1:%d`, port))
cancel()
Expand Down
Loading