Skip to content

Commit

Permalink
Summarize compact snapshot logs to reduce noise (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlinsley authored Nov 9, 2023
1 parent 9d8ee71 commit 9a7b89d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ jobs:
with:
submodules: true

- name: Runs tests
- name: Lint
run: |
test $(go fmt ./... | wc -l) -eq 0
- name: Run tests
run: |
make build OUTFILE=pganalyze-collector-linux-amd64
make test
DOCKER_BUILDKIT=1 make integration_test
shellcheck contrib/install.sh
- name: Lint
run: |
test $(go fmt ./... | wc -l) -eq 0
27 changes: 26 additions & 1 deletion output/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net/http"
"net/url"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -137,7 +138,31 @@ func submitCompactSnapshot(ctx context.Context, server *state.Server, collection
if len(msg) > 0 && collectionOpts.TestRun {
logger.PrintInfo(" %s", msg)
} else if !quiet {
logger.PrintInfo("Submitted compact %s snapshot successfully", kind)
logger.PrintVerbose("Submitted compact %s snapshot successfully", kind)
if server.CompactLogTime.IsZero() {
server.CompactLogTime = time.Now().Truncate(time.Minute)
server.CompactLogStats = make(map[string]uint8)
} else if time.Now().Sub(server.CompactLogTime) > time.Minute {
var keys []string
for k := range server.CompactLogStats {
keys = append(keys, k)
}
sort.Strings(keys)
details := ""
for i, kind := range keys {
details += fmt.Sprintf("%d %s", server.CompactLogStats[kind], kind)
if i < len(keys)-1 {
details += ", "
}
}
if len(details) > 0 {
logger.PrintInfo("Compact snapshots submitted: " + details)
}
server.CompactLogTime = time.Now().Truncate(time.Minute)
server.CompactLogStats = make(map[string]uint8)
} else {
server.CompactLogStats[kind] = server.CompactLogStats[kind] + 1
}
}

return nil
Expand Down
4 changes: 4 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ type Server struct {
// differences (see https://groups.google.com/g/golang-nuts/c/eIqkhXh9PLg),
// as we access this in high frequency log-related code paths.
LogIgnoreFlags uint32

// State to track compact snapshot submissions, and log them routinely
CompactLogStats map[string]uint8
CompactLogTime time.Time
}

func MakeServer(config config.ServerConfig) *Server {
Expand Down

0 comments on commit 9a7b89d

Please sign in to comment.