6 Commits

Author SHA1 Message Date
xuu
db72c24de3 fix: not allowing new peer results
All checks were successful
Go Bump / bump (push) Successful in 35s
Go Test / test (push) Successful in 45s
Deploy / deploy (push) Successful in 1m28s
2023-10-20 12:05:26 -06:00
xuu
87170420e4 build: use go install
All checks were successful
Go Bump / bump (push) Successful in 40s
Go Test / test (push) Successful in 51s
Deploy / deploy (push) Successful in 1m44s
2023-10-15 11:45:47 -06:00
xuu
2e79ac4460 chore: add ignore
All checks were successful
Go Bump / bump (push) Successful in 39s
Go Test / test (push) Successful in 49s
Deploy / deploy (push) Successful in 1m34s
2023-10-15 09:09:11 -06:00
xuu
cd1f1d7b5f fix: remove non-errors
All checks were successful
Go Bump / bump (push) Successful in 47s
Go Test / test (push) Successful in 59s
Deploy / deploy (push) Successful in 1m42s
2023-10-07 18:33:00 -06:00
xuu
a3ee0b7900 fix: return on errors
All checks were successful
Go Bump / bump (push) Successful in 46s
Go Test / test (push) Successful in 52s
Deploy / deploy (push) Successful in 1m42s
2023-10-07 18:11:35 -06:00
xuu
114c7101d6 fix: add debug levels
All checks were successful
Go Bump / bump (push) Successful in 43s
Go Test / test (push) Successful in 49s
Deploy / deploy (push) Successful in 1m42s
2023-10-07 17:57:09 -06:00
11 changed files with 31 additions and 19 deletions

View File

@@ -5,7 +5,7 @@
tasks:
- name: Copy build to remote
ansible.builtin.copy:
src: ../build/ev
src: ../ev
dest: /usr/local/bin/ev
owner: root
group: root

View File

@@ -9,12 +9,8 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
fetch-tags: true
- run: apt-get update && apt-get -y install ansible
- name: Set up Go
@@ -22,15 +18,17 @@ jobs:
with:
go-version: 1.21.1
- name: Build
run: go build -ldflags "-s -w" -o ./build/ev ./cmd/ev
- name: Install
run: go install -ldflags "-s -w" go.sour.is/tools/cmd/ev@latest
- run: mv $(go env GOPATH)/bin/ev ev
- name: Compress
uses: https://git.sour.is/actions/ghaction-upx@v2.4.0
with:
version: latest
files: |
./build/ev
./ev
args: -fq
- name: Deploy

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
tools
tmp
sour.is-tools

View File

@@ -1,6 +1,6 @@
export PATH:=$(shell go env GOPATH)/bin:$(PATH)
export EV_DATA=mem:
export EV_HTTP=:8080
export EV_HTTP=:8085
export WEBFINGER_DOMAINS=localhost
.DEFAULT_GOAL := air
@@ -15,7 +15,7 @@ endif
air .
run:
go build . && ./tools
go build -buildvcs=true -o sour.is-tools ./cmd/ev && ./sour.is-tools
test:
go test -cover -race ./...

View File

@@ -179,7 +179,7 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
return nil
})
if err != nil {
span.RecordError(err)
span.AddEvent(err.Error())
w.WriteHeader(http.StatusNotFound)
return
}
@@ -204,8 +204,9 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
peerResults.SetStreamID(aggPeer(peerID))
err = s.es.Load(ctx, peerResults)
if err != nil && !errors.Is(err, ev.ErrNotFound) {
span.RecordError(fmt.Errorf("peer not found: %w", err))
span.AddEvent("peer not found")
w.WriteHeader(http.StatusNotFound)
return
}
var req *Request
@@ -221,8 +222,9 @@ func (s *service) getPending(w http.ResponseWriter, r *http.Request, peerID stri
}
}
if req == nil {
span.RecordError(fmt.Errorf("request not found"))
span.AddEvent("request not found")
w.WriteHeader(http.StatusNoContent)
return
}
negotiator := contentnegotiation.NewNegotiator("application/json", "text/environment", "text/plain", "text/html")
@@ -433,8 +435,8 @@ func (s *service) postResult(w http.ResponseWriter, r *http.Request, reqID strin
err := s.state.Use(ctx, func(ctx context.Context, state *state) error {
var ok bool
if _, ok = state.peers[peerID]; !ok {
log.Printf("peer not found: %s\n", peerID)
return fmt.Errorf("peer not found: %s", peerID)
log.Printf("peer not found: req=%s peer=%s\n", reqID, peerID)
return fmt.Errorf("peer not found: req=%s peer=%s", reqID, peerID)
}
return nil
@@ -448,9 +450,10 @@ func (s *service) postResult(w http.ResponseWriter, r *http.Request, reqID strin
peerResults := &PeerResults{}
peerResults.SetStreamID(aggPeer(peerID))
err = s.es.Load(ctx, peerResults)
if err != nil {
span.RecordError(fmt.Errorf("peer not found: %w", err))
if err != nil && !errors.Is(err, ev.ErrNotFound) {
span.RecordError(fmt.Errorf("peer not found: req=%s peer=%s %w", reqID, peerID, err))
w.WriteHeader(http.StatusNotFound)
return
}
if peerResults.Has(reqID) {

View File

@@ -4,10 +4,13 @@ import (
"context"
"errors"
"log"
"log/slog"
"net/http"
"os"
"os/signal"
"strconv"
"go.sour.is/pkg/env"
"go.sour.is/pkg/lg"
"go.sour.is/pkg/service"
)
@@ -27,6 +30,13 @@ func main() {
}
}
func run(ctx context.Context) error {
// TODO: make this configurable.
level := slog.LevelError
if ok, _ := strconv.ParseBool(env.Default("LOG_DEBUG", "FALSE")); ok {
level = slog.LevelDebug
}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level})))
svc := &service.Harness{}
ctx, stop := lg.Init(ctx, appName)
svc.OnStop(stop)

1
tmp/build-errors.log Normal file
View File

@@ -0,0 +1 @@
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

BIN
tmp/main Executable file

Binary file not shown.