chore: Remove unused loghandlers package (#64067)

This package is not imported anywhere anymore, so we can safely drop it.

Test plan: Go compiler doesn't complain after package was removed.
This commit is contained in:
Erik Seliger 2024-07-31 04:34:22 +02:00 committed by GitHub
parent 32e58ad055
commit c44ffb0d74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 0 additions and 179 deletions

View File

@ -1,18 +0,0 @@
load("//dev:go_defs.bzl", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "loghandlers",
srcs = ["loghandlers.go"],
importpath = "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/cli/loghandlers",
visibility = ["//cmd/frontend:__subpackages__"],
deps = ["@com_github_inconshreveable_log15//:log15"],
)
go_test(
name = "loghandlers_test",
timeout = "short",
srcs = ["loghandlers_test.go"],
embed = [":loghandlers"],
deps = ["@com_github_inconshreveable_log15//:log15"],
)

View File

@ -1,69 +0,0 @@
// Package loghandlers contains log15 handlers/filters used by the sourcegraph
// cli
package loghandlers
import (
"strings"
"time"
"github.com/inconshreveable/log15" //nolint:logging // Legacy loghandlers for log15
)
// Trace returns a filter for the given traces that run longer than threshold
func Trace(types []string, threshold time.Duration) func(*log15.Record) bool {
all := false
valid := map[string]bool{}
for _, t := range types {
valid[t] = true
if t == "all" {
all = true
}
}
return func(r *log15.Record) bool {
if r.Lvl != log15.LvlDebug {
return true
}
if !strings.HasPrefix(r.Msg, "TRACE ") {
return true
}
if !all && !valid[r.Msg[6:]] {
return false
}
for i := 1; i < len(r.Ctx); i += 2 {
if r.Ctx[i-1] != "duration" {
continue
}
d, ok := r.Ctx[i].(time.Duration)
return !ok || d >= threshold
}
return true
}
}
// NotNoisey filters out high firing and low signal debug logs
func NotNoisey(r *log15.Record) bool {
if r.Lvl != log15.LvlDebug {
return true
}
noiseyPrefixes := []string{"repoUpdater: RefreshVCS"}
for _, prefix := range noiseyPrefixes {
if strings.HasPrefix(r.Msg, prefix) {
return false
}
}
if !strings.HasPrefix(r.Msg, "TRACE backend") || len(r.Ctx) < 2 {
return true
}
rpc, ok := r.Ctx[1].(string)
if !ok {
return true
}
for _, n := range noiseyRPC {
if rpc == n {
return false
}
}
return true
}
var noiseyRPC = []string{"MirrorRepos.RefreshVCS"}

View File

@ -1,92 +0,0 @@
package loghandlers
import (
"testing"
"time"
"github.com/inconshreveable/log15" //nolint:logging // TODO move all logging to sourcegraph/log
)
func TestNotNoisey(t *testing.T) {
keep := []log15.Record{
mkRecord(log15.LvlDebug, "TRACE backend", "rpc", "Annotations.List", "spanID", "SPANID"),
mkRecord(log15.LvlDebug, "TRACE backend", "rpc", "RepoTree.Get", "spanID", "SPANID", "duration", time.Second),
mkRecord(log15.LvlWarn, "repoUpdater: RefreshVCS:", "err", "error"),
}
noisey := []log15.Record{mkRecord(log15.LvlDebug, "repoUpdater: RefreshVCS:", "err", "error")}
for _, rpc := range noiseyRPC {
noisey = append(noisey, mkRecord(log15.LvlDebug, "TRACE backend", "rpc", rpc))
}
for _, r := range keep {
if !NotNoisey(&r) {
t.Errorf("Should keep %v", r)
}
}
for _, r := range noisey {
if NotNoisey(&r) {
t.Errorf("Should filter out %v", r)
}
}
}
var traces = []log15.Record{
mkRecord(log15.LvlDebug, "TRACE backend", "rpc", "RepoTree.Get", "duration", time.Second),
mkRecord(log15.LvlDebug, "TRACE HTTP", "routename", "repo.resolve", "duration", time.Second/3),
mkRecord(log15.LvlDebug, "TRACE HTTP", "routename", "repo.resolve", "duration", 2*time.Second),
}
func TestTrace_All(t *testing.T) {
f := Trace([]string{"all"}, 0)
for _, r := range traces {
if !f(&r) {
t.Errorf("Should allow %v", r)
}
}
}
func TestTrace_None(t *testing.T) {
f := Trace([]string{}, 0)
for _, r := range traces {
if f(&r) {
t.Errorf("Should filter %v", r)
}
}
}
func TestTrace_Specific(t *testing.T) {
f := Trace([]string{"HTTP"}, 0)
for _, r := range traces {
keep := r.Msg == "TRACE HTTP"
if f(&r) == keep {
continue
} else if keep {
t.Errorf("Should keep %v", r)
} else {
t.Errorf("Should filter %v", r)
}
}
}
func TestTrace_Threshold(t *testing.T) {
threshold := time.Second
f := Trace([]string{"all"}, threshold)
for _, r := range traces {
keep := r.Ctx[len(r.Ctx)-1].(time.Duration) >= threshold
if f(&r) == keep {
continue
} else if keep {
t.Errorf("Should keep %v for threshold %s", r, threshold)
} else {
t.Errorf("Should filter %v for threshold %s", r, threshold)
}
}
}
func mkRecord(lvl log15.Lvl, msg string, ctx ...any) log15.Record {
return log15.Record{
Lvl: lvl,
Msg: msg,
Ctx: ctx,
}
}