-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add/Replace fields with SetFields (#4)
- Loading branch information
Showing
12 changed files
with
342 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: test-unit | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
env: | ||
GO111MODULE: "on" | ||
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing. | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Go cache | ||
uses: actions/cache@v2 | ||
with: | ||
# In order: | ||
# * Module download cache | ||
# * Build cache (Linux) | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go-cache | ||
- name: Restore base test coverage | ||
if: matrix.go-version == '1.16.x' | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
unit-base.txt | ||
# Use base sha for PR or new commit hash for master/main push in test result key. | ||
key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }} | ||
- name: Checkout base code | ||
if: matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != '' | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.event.pull_request.base.sha }} | ||
path: __base | ||
- name: Run test for base code | ||
if: matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != '' | ||
run: | | ||
cd __base | ||
make test-unit | ||
go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > ../unit-base.txt | ||
- name: Test | ||
id: test | ||
run: | | ||
make test-unit | ||
go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > unit.txt | ||
OUTPUT=$(test -e unit-base.txt && (diff unit-base.txt unit.txt || exit 0) || cat unit.txt) | ||
OUTPUT="${OUTPUT//'%'/'%25'}" | ||
OUTPUT="${OUTPUT//$'\n'/'%0A'}" | ||
OUTPUT="${OUTPUT//$'\r'/'%0D'}" | ||
TOTAL=$(grep 'total:' unit.txt) | ||
echo "::set-output name=diff::$OUTPUT" | ||
echo "::set-output name=total::$TOTAL" | ||
- name: Store base coverage | ||
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }} | ||
run: cp unit.txt unit-base.txt | ||
- name: Comment Test Coverage | ||
if: matrix.go-version == '1.16.x' | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
header: unit-test | ||
message: | | ||
### Unit Test Coverage | ||
${{ steps.test.outputs.total }} | ||
<details><summary>Coverage diff with base branch</summary> | ||
```diff | ||
${{ steps.test.outputs.diff }} | ||
``` | ||
</details> | ||
- name: Upload code coverage | ||
if: matrix.go-version == '1.16.x' | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
file: ./unit.coverprofile | ||
flags: unittests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/.idea | ||
/bench-* | ||
/unit.coverprofile | ||
/*.coverprofile | ||
/.vscode | ||
/bench-*.txt | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml | ||
run: | ||
tests: true | ||
|
||
linters-settings: | ||
errcheck: | ||
check-type-assertions: true | ||
check-blank: true | ||
gocyclo: | ||
min-complexity: 20 | ||
dupl: | ||
threshold: 100 | ||
misspell: | ||
locale: US | ||
unused: | ||
check-exported: false | ||
unparam: | ||
check-exported: true | ||
|
||
linters: | ||
enable-all: true | ||
disable: | ||
- lll | ||
- maligned | ||
- gochecknoglobals | ||
- gomnd | ||
- wrapcheck | ||
- paralleltest | ||
- forbidigo | ||
- exhaustivestruct | ||
- interfacer | ||
- forcetypeassert | ||
- scopelint | ||
|
||
issues: | ||
exclude-use-default: false | ||
exclude-rules: | ||
- linters: | ||
- gomnd | ||
- goconst | ||
- goerr113 | ||
- noctx | ||
- funlen | ||
- dupl | ||
path: "_test.go" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ctxd | ||
|
||
// FieldNames defines standard field names. | ||
// | ||
// Default names are aligned with https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html. | ||
type FieldNames struct { | ||
Timestamp string `default:"@timestamp"` | ||
Message string `default:"message"` | ||
|
||
// ClientIP is an IP address of the client (IPv4 or IPv6). | ||
ClientIP string `default:"client.ip"` | ||
|
||
HTTPMethod string `default:"http.request.method"` | ||
HTTPResponseBytes string `default:"http.response.bytes"` | ||
HTTPResponseStatus string `default:"http.response.status_code"` | ||
|
||
URL string `default:"url.original"` | ||
|
||
// UserAgentOriginal is an unparsed user_agent string. | ||
UserAgentOriginal string `default:"user_agent.original"` | ||
|
||
SpanID string `default:"span.id"` | ||
TraceID string `default:"trace.id"` | ||
TransactionID string `default:"transaction.id"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.