forked from cloudflare/pint
-
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.
Ensure we don't report problems from unmodified lines
- Loading branch information
Showing
10 changed files
with
187 additions
and
30 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
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,111 @@ | ||
exec bash -x ./webserver.sh & | ||
exec bash -c 'I=0 ; while [ ! -f server.pid ] && [ $I -lt 30 ]; do sleep 1; I=$((I+1)); done' | ||
|
||
mkdir testrepo | ||
cd testrepo | ||
exec git init --initial-branch=main . | ||
|
||
cp ../src/v1.yml rules.yml | ||
cp ../src/.pint.hcl . | ||
env GIT_AUTHOR_NAME=pint | ||
env GIT_AUTHOR_EMAIL=pint@example.com | ||
env GIT_COMMITTER_NAME=pint | ||
env GIT_COMMITTER_EMAIL=pint@example.com | ||
exec git add . | ||
exec git commit -am 'import rules and config' | ||
|
||
exec git checkout -b v2 | ||
cp ../src/v2.yml rules.yml | ||
exec git commit -am 'v2' | ||
|
||
env BITBUCKET_AUTH_TOKEN="12345" | ||
pint.ok --no-color ci | ||
! stdout . | ||
stderr 'level=info msg="Problems found" Information=1' | ||
|
||
exec sh -c 'cat ../server.pid | xargs kill' | ||
-- src/v1.yml -- | ||
- alert: rule1a | ||
expr: sum(foo{job=~"xxx"}) by(job) | ||
- alert: rule2a | ||
expr: sum(foo{job=~"xxx"}) by(job) | ||
for: 0s | ||
|
||
-- src/v2.yml -- | ||
- alert: rule1b | ||
expr: sum(foo{job=~"xxx"}) by(job) | ||
for: 0s | ||
- alert: rule2b | ||
expr: sum(foo{job=~"xxx"}) by(job) | ||
for: 0s | ||
|
||
-- src/.pint.hcl -- | ||
parser { | ||
relaxed = [".*"] | ||
} | ||
ci { | ||
baseBranch = "main" | ||
} | ||
repository { | ||
bitbucket { | ||
uri = "http://127.0.0.1:6069" | ||
timeout = "10s" | ||
project = "prometheus" | ||
repository = "rules" | ||
} | ||
} | ||
|
||
-- webserver.go -- | ||
package main | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"log" | ||
"net" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
io.WriteString(w, "OK") | ||
}) | ||
|
||
listener, err := net.Listen("tcp", "127.0.0.1:6069") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
server := &http.Server{ | ||
Addr: "127.0.0.1:6069", | ||
} | ||
|
||
go func() { | ||
_ = server.Serve(listener) | ||
}() | ||
|
||
pid := os.Getpid() | ||
err = os.WriteFile("server.pid", []byte(strconv.Itoa(pid)), 0644) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
stop := make(chan os.Signal, 1) | ||
signal.Notify(stop, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) | ||
go func() { | ||
time.Sleep(time.Minute*2) | ||
stop <- syscall.SIGTERM | ||
}() | ||
<-stop | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
server.Shutdown(ctx) | ||
} | ||
|
||
-- webserver.sh -- | ||
env GOCACHE=$TMPDIR go run webserver.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
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
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