Skip to content

Commit

Permalink
Merge branch 'google:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelzoellner committed Sep 28, 2023
2 parents efeb28b + 86b8dd3 commit ed6b88e
Show file tree
Hide file tree
Showing 29 changed files with 304 additions and 973 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ jobs:
# auto-approve-action requires write on pull-requests
pull-requests: write
steps:
- uses: hmarr/auto-approve-action@de8ae18c173c131e182d4adf2c874d8d2308a85b
- uses: hmarr/auto-approve-action@44888193675f29a83e04faf4002fa8c0b537b1e4
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
4 changes: 2 additions & 2 deletions .github/workflows/benchmark-done.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:
run: |
mkdir -p benchmark-comment
unzip -d benchmark-comment benchmark-comment.zip
echo "::set-output name=pr-number::$(cat benchmark-comment/pr-number)"
echo "pr-number=$(cat benchmark-comment/pr-number)" >> $GITHUB_OUTPUT
COMMENT=$(cat benchmark-comment/benchstat.txt)
COMMENT="${COMMENT//'%'/'%25'}"
COMMENT="${COMMENT//$'\n'/'%0A'}"
COMMENT="${COMMENT//$'\r'/'%0D'}"
echo "::set-output name=comment::$COMMENT"
echo "comment=$COMMENT" >> $GITHUB_OUTPUT
- name: post benchmark results
uses: marocchino/sticky-pull-request-comment@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: '^1.x'
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache@v3
id: cache
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-done.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
mkdir -p test-results
unzip -d test-results test-results.zip
echo "::set-output name=sha::$(cat test-results/sha-number)"
echo "sha=$(cat test-results/sha-number)" >> $GITHUB_OUTPUT
- uses: docker://ghcr.io/enricomi/publish-unit-test-result-action:v1.6
with:
commit: ${{ steps.unpack.outputs.sha }}
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ jobs:
test:
strategy:
matrix:
runs-on: [ubuntu-latest, macos-latest, windows-latest]
# macos-latest is slow and has weird test failures with unixgram message sizes, so it's been disabled.
runs-on: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
Expand Down Expand Up @@ -57,7 +58,7 @@ jobs:
container:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # so that we get tags
- run: make --debug container
Expand All @@ -69,7 +70,7 @@ jobs:
permissions:
security-events: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: securego/gosec@master
with:
# we let the report trigger content trigger a failure using the GitHub Security features.
Expand All @@ -85,8 +86,8 @@ jobs:
container:
image: gcr.io/oss-fuzz-base/base-builder
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '^1.x'
- uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.50
version: v1.52

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ jobs:
steps:
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "flags=--snapshot" >> $GITHUB_ENV
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- uses: goreleaser/goreleaser-action@v4
- uses: goreleaser/goreleaser-action@v5
with:
version: latest
args: release --rm-dist ${{ env.flags }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v7
- uses: actions/stale@v8
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue has been waiting for more information for more than 60 days and will be closed in 7 if no update is provided.'
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ linters:
- interfacer # deprecated
- lll # go says long lines are ok, and this is trivially automatable
- maligned # deprecated
- musttag # don't tell me how to live
- nakedret # weird thing to report on
- nestif # cognitive complexity
- nlreturn # Not a fan of this one, looks messy
Expand Down
7 changes: 0 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ builds:
gcflags:
# I love errors.
- -e
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ depclean:
rm -f .d/* .*dep-stamp
veryclean: clean depclean

GOLANGCILINT_VERSION=v1.50.1
# This version should match the one in .github/workflows/golangci-lint.yml
GOLANGCILINT_VERSION=$(shell grep 'version: v' .github/workflows/golangci-lint.yml | cut -f2 -d: | tr -d ' ')
#GOLANGCILINT_VERSION=v1.52
# lint
.PHONY: lint
lint: $(GOFILES) $(GOGENFILES) $(GOTESTFILES)
mkdir -p $(HOME)/.cache/golangci-lint/$(GOLANGCILINT_VERSION)
podman run --rm -v $(shell pwd):/app -v $(HOME)/.cache/golangci-lint/$(GOLANGCILINT_VERSION):/root/.cache -w /app golangci/golangci-lint:$(GOLANGCILINT_VERSION) golangci-lint run -v
podman run --rm -v $(shell pwd):/app -v $(HOME)/.cache/golangci-lint/$(GOLANGCILINT_VERSION):/root/.cache -w /app docker.io/golangci/golangci-lint:$(GOLANGCILINT_VERSION) golangci-lint run -v

branch := $(shell git rev-parse --abbrev-ref HEAD)
version := $(shell git describe --tags --always --dirty)
Expand Down
20 changes: 3 additions & 17 deletions cmd/mgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
package main

import (
crand "crypto/rand"
"flag"
"fmt"
"math/big"
mrand "math/rand"
"math/rand"

"github.com/google/mtail/internal/runtime/compiler/parser"
)

var (
useCryptoRand = flag.Bool("use_crypto_rand", false, "Use crypto/rand instead of math/rand")
randSeed = flag.Int64("rand_seed", 1, "Seed to use for math.rand.")
minIterations = flag.Int64("min_iterations", 5000, "Minimum number of iterations before stopping program generation.")
dictionary = flag.Bool("dictionary", false, "Generate a fuzz dictionary to stdout only.")
Expand Down Expand Up @@ -91,19 +88,8 @@ func emitter(c chan string) {
}
}

func rand(n int) (r int) {
if *useCryptoRand {
a, _ := crand.Int(crand.Reader, big.NewInt(int64(n)))
r = int(a.Int64())
} else {
/* #nosec G404 */
r = mrand.Intn(n)
}
return
}

func generateProgram() {
mrand.Seed(*randSeed)
rando := rand.New(rand.NewSource(*randSeed))

c := make(chan string, 1)
go emitter(c)
Expand All @@ -126,7 +112,7 @@ func generateProgram() {
// fmt.Println("n", n)
if len(n.alts) > 0 {
// Pick a state transition at random
a := rand(len(n.alts))
a := rando.Intn(len(n.alts))
// fmt.Println("a", a, n.alts[a], len(n.alts[a]))
// Push the states picked onto the stack (in reverse order)
for i := 0; i < len(n.alts[a]); i++ {
Expand Down
11 changes: 9 additions & 2 deletions docs/Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,18 @@ program state.
in all lowercase.
* `subst(old, new, val)`, a function of three arguments which returns the
input `val` with all substrings or patterns `old` replaced by `new`. When
given a string for `old`, it is a direct proxy of the Go
given a *string* for `old`, it is a direct proxy of the Go
[strings.ReplaceAll](https://golang.org/pkg/strings/#ReplaceAll) function.
When given a regular expression pattern for `old`, it uses

`subst("old", "new", $val)`

When given a *regular expression pattern* for `old`, it uses
[regexp.ReplaceAllLiteralString](https://golang.org/pkg/regexp/#Regexp.ReplaceAllLiteralString).

`subst(/old/, "new", $val)`

Note the different quote characters in the first argument.

There are type coercion functions, useful for overriding the type inference made
by the compiler if it chooses badly. (If the choice is egregious, please file a
bug!)
Expand Down
29 changes: 29 additions & 0 deletions docs/references.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[ANSI C Grammar](http://www.lysator.liu.se/c/ANSI-C-grammar-y.html)

[Awk Grammar](https://pubs.opengroup.org/onlinepubs/7908799/xcu/awk.html#tag_000_000_108_016)

[Original Awk Grammar](https://github.com/onetrueawk/awk/blob/master/awkgram.y)

[GAWK Grammar](http://git.savannah.gnu.org/cgit/gawk.git/tree/awkgram.y)

[Smalltalk-80: The Language and Its Implementation](http://web.archive.org/web/20070927190722/http://users.ipa.net/~dwighth/smalltalk/bluebook/bluebook_imp_toc.html)
Adele Goldberg and David Robson

[The Java Virtual Machine Specification](https://docs.oracle.com/javase/specs/jvms/se7/html/index.html) Lindholm Yellin Bracha Buckley


[Perl operators](https://perldoc.perl.org/perlop#Regexp-Quote-Like-Operators)


["Generating LR syntax error messages from examples", Jeffery, ACM TOPLAS Volume 24 Issue 5 Sep 2003.](https://dl.acm.org/doi/abs/10.1145/937563.937566)



[Hindley Milner in Scala](http://dysphoria.net/2009/06/28/hindley-milner-type-inference-in-scala/)

[The Hindley-Milner Algorithm](http://web.archive.org/web/20050911123640/http://www.cs.berkeley.edu/~nikitab/courses/cs263/hm.html) in perl
by Nikita Borisov


https://medium.com/@dhruvrajvanshi/type-inference-for-beginners-part-2-f39c33ca9513

26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
module github.com/google/mtail

go 1.17
go 1.20

require (
contrib.go.opencensus.io/exporter/jaeger v0.2.1
github.com/golang/glog v1.0.0
github.com/golang/glog v1.1.2
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/google/go-cmp v0.5.9
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.41.0
github.com/prometheus/client_golang v1.17.0
github.com/prometheus/common v0.44.0
go.opencensus.io v0.24.0
golang.org/x/sys v0.5.0
golang.org/x/sys v0.12.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sync v0.3.0 // indirect
google.golang.org/api v0.105.0 // indirect
google.golang.org/genproto v0.0.0-20221206210731-b1a01be3a5f6 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
Loading

0 comments on commit ed6b88e

Please sign in to comment.