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

feat(configio): config encoding #66

Draft
wants to merge 53 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b68492d
refactor(configparse): implement Representation.Unmarshal
GregoryAlbouy Oct 15, 2022
e7745df
feat: remove Config methods that became irrelevant
GregoryAlbouy Oct 15, 2022
b2990be
chore: remove unused IsConfigField
GregoryAlbouy Oct 18, 2022
474dec4
refactor(configparse): rename Representation.Unmarshal
GregoryAlbouy Oct 18, 2022
28b0fc2
deps: remove unused dependencies
GregoryAlbouy Oct 18, 2022
c281221
refactor(runner): use *http.Request for Config.Request
GregoryAlbouy Oct 18, 2022
106281a
refactor(runner): flatten packages runner, config, report
GregoryAlbouy Oct 18, 2022
f7bd599
refactor(configparse): minor param renaming
GregoryAlbouy Oct 19, 2022
74447a6
refactor(runner): nuke Config, flatten Runner fields
GregoryAlbouy Oct 19, 2022
dec31d9
refactor(runner): use httptest in unit tests
GregoryAlbouy Oct 22, 2022
1ebb2f4
chore: remove obsolete env file
GregoryAlbouy Oct 22, 2022
5c6172f
chore: clean up .gitignore
GregoryAlbouy Oct 22, 2022
bc00fb0
chore: remove deprecated linters
GregoryAlbouy Oct 22, 2022
e8a9255
refactor(runner): remove unnecessary constructor
GregoryAlbouy Oct 23, 2022
78e6d8d
docs: update docs
GregoryAlbouy Oct 23, 2022
540d071
refactor(configparse): JSON: use pointer destination param
GregoryAlbouy Oct 23, 2022
680fc0b
refactor: rename module and packages
GregoryAlbouy Oct 23, 2022
5ab6aca
refactor: remove Makefile, use shell scripts
GregoryAlbouy Oct 23, 2022
3de371e
chore(benchttp): remove Runner.Progress method
GregoryAlbouy Oct 23, 2022
50dd455
refactor(benchttp): DefaultRunner
GregoryAlbouy Oct 23, 2022
aa2d658
feat(benchttp): implement request setters for Runner
GregoryAlbouy Oct 23, 2022
5a8f0fb
docs: update README
GregoryAlbouy Oct 23, 2022
998e238
faet(runner): use value rexeivers
GregoryAlbouy Oct 28, 2022
a3b1225
test(runner) write unit tests for setters
GregoryAlbouy Oct 28, 2022
83a2213
feat: create package benchttptest
GregoryAlbouy Nov 6, 2022
dc0f35c
feat(configparse): import and flatten configfile
GregoryAlbouy Oct 28, 2022
e137eb0
refactor: rename package configparse -> configio
GregoryAlbouy Oct 29, 2022
346ef65
refactor(configio): adapt namings to new package name
GregoryAlbouy Oct 29, 2022
6e9e98a
refactor(configio): move FindFile in file.go
GregoryAlbouy Oct 29, 2022
1784b2b
feat(configio): Decoders and Unmarshal funcs
GregoryAlbouy Oct 29, 2022
fcfc433
refactor(configio): error handling
GregoryAlbouy Oct 29, 2022
88eab24
test(configio): refactor TestFindFile, TestUnmarshalFile
GregoryAlbouy Oct 29, 2022
cd83b03
refactor(configio): move testdata to internal
GregoryAlbouy Oct 30, 2022
783aa14
test(configio): add cases for empty paths
GregoryAlbouy Oct 30, 2022
215f028
refactor(configio): refactor UnmarshalFile
GregoryAlbouy Oct 30, 2022
0b90a84
refactor(configio) rename file parse.go -> representation.go
GregoryAlbouy Oct 30, 2022
1dbd54e
refactor(configio): Extension -> Format
GregoryAlbouy Nov 1, 2022
a63a7f8
feat(configio): implement Builder
GregoryAlbouy Nov 5, 2022
5e9268f
doc(configio): write ExampleBuilder example
GregoryAlbouy Nov 6, 2022
731547e
tmp: benchmark pipe vs append implementations for configio.Builder
GregoryAlbouy Nov 6, 2022
ccd5100
Revert "tmp: benchmark pipe vs append implementations for configio.Bu…
GregoryAlbouy Nov 6, 2022
07aa5d2
perf(configio): use an array of modifiers for Builder
GregoryAlbouy Nov 6, 2022
e6e8062
refactor(configio): Builder renamings
GregoryAlbouy Nov 6, 2022
61ff33c
doc(configio): add documenting comments for Builder
GregoryAlbouy Nov 6, 2022
c89ecb3
fixup! doc(configio): add documenting comments for Builder
GregoryAlbouy Nov 6, 2022
9e8cc86
feat(configio): make Representation private
GregoryAlbouy Nov 6, 2022
e865353
feat(configio): remove public references to representation
GregoryAlbouy Nov 6, 2022
7c3655f
refactor(configio): move `representation` to internal/conversion
GregoryAlbouy Nov 6, 2022
fe8218f
refactor(conversion): rename Repr.ParseAndMutate -> Repr.Decode
GregoryAlbouy Nov 6, 2022
14dcbaf
refactor(conversion): use declarative converters
GregoryAlbouy Nov 7, 2022
fe16752
refactor(conversion): extract parsing functions from converter
GregoryAlbouy Nov 7, 2022
1235680
refactor(conversion): naming, error handling
GregoryAlbouy Nov 8, 2022
9847cb8
wip: encoding
GregoryAlbouy Nov 9, 2022
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
1 change: 0 additions & 1 deletion .env.development

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
go-version: 1.17

- name: Install coverage tool
run: go get github.com/ory/go-acc
run: go install github.com/ory/go-acc@v0.2.8

# Check #1: Lint
- name: Lint
Expand All @@ -28,7 +28,7 @@ jobs:

# Check #2: Test & generate coverage report
- name: Test & coverage
run: make test-cov
run: ./script/coverage

- name: Upload coverage report
uses: codecov/[email protected]
Expand Down
9 changes: 0 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Env files
.env

# Binary files
/bin

# IDE files
/.vscode
/.idea
Expand All @@ -12,6 +6,3 @@
/.benchttp.yml
/.benchttp.yaml
/.benchttp.json

# Benchttp reports
/benchttp.report.*.json
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ linters-settings:
extra-rules: true

goimports:
local-prefixes: github.com/benchttp/engine
local-prefixes: github.com/benchttp/sdk

misspell:
locale: US
Expand All @@ -131,7 +131,6 @@ linters:
disable-all: true
enable:
- bodyclose # enforce resp.Body.Close()
- deadcode
- dupl # duplicate code
- errcheck
- exportloopref
Expand All @@ -145,10 +144,8 @@ linters:
- prealloc # enforce capacity allocation when possible
- revive # golint enhancement
- staticcheck # go vet enhancement
- structcheck # unused struct fields
- testpackage # checks on tests (*_test)
- thelper # enforce t.Helper()
- varcheck # unused global var and const
- wastedassign
fast: false

Expand Down
45 changes: 0 additions & 45 deletions Makefile

This file was deleted.

56 changes: 30 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<h1 align="center">benchttp/engine</h1>

<p align="center">
<a href="https://github.com/benchttp/engine/actions/workflows/ci.yml?query=branch%3Amain">
<a href="https://github.com/benchttp/sdk/actions/workflows/ci.yml?query=branch%3Amain">
<img alt="Github Worklow Status" src="https://img.shields.io/github/workflow/status/benchttp/engine/Lint%20&%20Test%20&%20Build"></a>
<a href="https://codecov.io/gh/benchttp/engine">
<img alt="Code coverage" src="https://img.shields.io/codecov/c/gh/benchttp/engine?label=coverage"></a>
<a href="https://goreportcard.com/report/github.com/benchttp/engine">
<img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/benchttp/engine" /></a>
<a href="https://goreportcard.com/report/github.com/benchttp/sdk">
<img alt="Go Report Card" src="https://goreportcard.com/badge/github.com/benchttp/sdk" /></a>
<br />
<a href="https://pkg.go.dev/github.com/benchttp/engine#section-documentation">
<a href="https://pkg.go.dev/github.com/benchttp/sdk#section-documentation">
<img alt="Go package Reference" src="https://img.shields.io/badge/pkg-reference-informational?logo=go" /></a>
<a href="https://github.com/benchttp/engine/releases">
<a href="https://github.com/benchttp/sdk/releases">
<img alt="Latest version" src="https://img.shields.io/github/v/tag/benchttp/engine?label=release"></a>
</p>

Expand All @@ -28,7 +28,7 @@ Go1.17 environment or higher is required.
Install.

```txt
go get github.com/benchttp/engine
go get github.com/benchttp/sdk
```

## Usage
Expand All @@ -42,22 +42,20 @@ import (
"context"
"fmt"

"github.com/benchttp/engine/runner"
"github.com/benchttp/sdk/benchttp"
)

func main(t *testing.T) {
// Set runner configuration
config := runner.DefaultConfig()
config.Request = config.Request.WithURL("https://example.com")

// Instantiate runner and run benchmark
report, _ := runner.New(nil).Run(context.Background(), config)
func main() {
report, _ := benchttp.
DefaultRunner(). // Default runner with safe configuration
WithNewRequest("GET", "http://localhost:3000", nil). // Attach request
Run(context.Background()) // Run benchmark, retrieve report

fmt.Println(report.Metrics.ResponseTimes.Mean)
}
```

### Usage with JSON config via `configparse`
### Usage with JSON config via `configio`

```go
package main
Expand All @@ -66,27 +64,33 @@ import (
"context"
"fmt"

"github.com/benchttp/engine/configparse"
"github.com/benchttp/engine/runner"
"github.com/benchttp/sdk/benchttp"
"github.com/benchttp/sdk/configio"
)

func main() {
// JSON configuration obtained via e.g. a file or HTTP call
jsonConfig := []byte(`
{
"request": {
"url": "https://example.com"
"url": "http://localhost:3000"
}
}`)

config, _ := configparse.JSON(jsonConfig)
report, _ := runner.New(nil).Run(context.Background(), config)
// Instantiate a base Runner (here the default with a safe configuration)
runner := benchttp.DefaultRunner()

// Parse the json configuration into the Runner
_ = configio.UnmarshalJSONRunner(jsonConfig, &runner)

// Run benchmark, retrieve report
report, _ := runner.Run(context.Background())

fmt.Println(report.Metrics.ResponseTimes.Mean)
}
```

📄 Please refer to [our Wiki](https://github.com/benchttp/engine/wiki/IO-Structures) for exhaustive `Config` and `Report` structures (and more!)
📄 Please refer to [our Wiki](https://github.com/benchttp/sdk/wiki/IO-Structures) for exhaustive `Runner` and `Report` structures (and more!)

## Development

Expand All @@ -97,8 +101,8 @@ func main() {

### Main commands

| Command | Description |
| ------------ | ----------------------------------- |
| `make lint` | Runs lint on the codebase |
| `make tests` | Runs tests suites from all packages |
| `make check` | Runs both lint and tests |
| Command | Description |
| --------------- | ------------------------------------------------- |
| `./script/lint` | Runs lint on the codebase |
| `./script/test` | Runs tests suites from all packages |
| `./script/doc` | Serves Go doc for this module at `localhost:9995` |
8 changes: 4 additions & 4 deletions runner/internal/config/error.go → benchttp/error.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package config
package benchttp

import "strings"

// InvalidConfigError is the errors returned by Global.Validate
// InvalidRunnerError is the errors returned by Config.Validate
// when values are missing or invalid.
type InvalidConfigError struct {
type InvalidRunnerError struct {
Errors []error
}

// Error returns the joined errors of InvalidConfigError as a string.
func (e *InvalidConfigError) Error() string {
func (e *InvalidRunnerError) Error() string {
const sep = "\n - "

var b strings.Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package config_test
package benchttp_test

import (
"errors"
"testing"

"github.com/benchttp/engine/runner/internal/config"
"github.com/benchttp/sdk/benchttp"
)

func TestInvalidConfigError_Error(t *testing.T) {
e := config.InvalidConfigError{
func TestInvalidRunnerError(t *testing.T) {
e := benchttp.InvalidRunnerError{
Errors: []error{
errors.New("error 0"),
errors.New("error 1\nwith new line"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package metrics
import (
"time"

"github.com/benchttp/engine/runner/internal/metrics/timestats"
"github.com/benchttp/engine/runner/internal/recorder"
"github.com/benchttp/sdk/benchttp/internal/metrics/timestats"
"github.com/benchttp/sdk/benchttp/internal/recorder"
)

type TimeStats = timestats.TimeStats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/benchttp/engine/runner/internal/metrics"
"github.com/benchttp/engine/runner/internal/metrics/timestats"
"github.com/benchttp/engine/runner/internal/recorder"
"github.com/benchttp/sdk/benchttp/internal/metrics"
"github.com/benchttp/sdk/benchttp/internal/metrics/timestats"
"github.com/benchttp/sdk/benchttp/internal/recorder"
)

func TestNewAggregate(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metrics
import (
"errors"

"github.com/benchttp/engine/internal/errorutil"
"github.com/benchttp/sdk/internal/errorutil"
)

// ErrUnknownField occurs when a Field is used with an invalid path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metrics_test
import (
"testing"

"github.com/benchttp/engine/runner/internal/metrics"
"github.com/benchttp/sdk/benchttp/internal/metrics"
)

func TestField_Type(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package metrics
import (
"strings"

"github.com/benchttp/engine/runner/internal/reflectpath"
"github.com/benchttp/sdk/benchttp/internal/reflectpath"
)

// Value is a concrete metric value, e.g. 120 or 3 * time.Second.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"
"time"

"github.com/benchttp/engine/runner/internal/metrics"
"github.com/benchttp/engine/runner/internal/metrics/timestats"
"github.com/benchttp/sdk/benchttp/internal/metrics"
"github.com/benchttp/sdk/benchttp/internal/metrics/timestats"
)

func TestMetric_Compare(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/benchttp/engine/runner/internal/metrics/timestats"
"github.com/benchttp/sdk/benchttp/internal/metrics/timestats"
)

func TestCompute(t *testing.T) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"
"time"

"github.com/benchttp/engine/internal/dispatcher"
"github.com/benchttp/sdk/internal/dispatcher"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/benchttp/engine/internal/dispatcher"
"github.com/benchttp/sdk/internal/dispatcher"
)

var errTest = errors.New("test-generated error")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package tests
import (
"errors"

"github.com/benchttp/engine/internal/errorutil"
"github.com/benchttp/engine/runner/internal/metrics"
"github.com/benchttp/sdk/benchttp/internal/metrics"
"github.com/benchttp/sdk/internal/errorutil"
)

var ErrUnknownPredicate = errors.New("tests: unknown predicate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"
"time"

"github.com/benchttp/engine/runner/internal/metrics"
"github.com/benchttp/engine/runner/internal/tests"
"github.com/benchttp/sdk/benchttp/internal/metrics"
"github.com/benchttp/sdk/benchttp/internal/tests"
)

func TestPredicate(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tests
import (
"fmt"

"github.com/benchttp/engine/runner/internal/metrics"
"github.com/benchttp/sdk/benchttp/internal/metrics"
)

type Case struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/benchttp/engine/runner/internal/metrics"
"github.com/benchttp/engine/runner/internal/metrics/timestats"
"github.com/benchttp/engine/runner/internal/tests"
"github.com/benchttp/sdk/benchttp/internal/metrics"
"github.com/benchttp/sdk/benchttp/internal/metrics/timestats"
"github.com/benchttp/sdk/benchttp/internal/tests"
)

func TestRun(t *testing.T) {
Expand Down
Loading