mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
Fix Broken Dependency (#12293)
* vendor in library * comment * lint * lint
This commit is contained in:
6
deps.bzl
6
deps.bzl
@@ -4061,12 +4061,6 @@ def prysm_deps():
|
||||
sum = "h1:264/meVYWt1wFw6Mtn+xwkZkXjID42gNra4rycoiDXI=",
|
||||
version = "v2.8.2",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_wercker_journalhook",
|
||||
importpath = "github.com/wercker/journalhook",
|
||||
sum = "h1:shC1HB1UogxN5Ech3Yqaaxj1X/P656PPCB4RbojIJqc=",
|
||||
version = "v0.0.0-20180428041537-5d0a5ae867b3",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_willf_bitset",
|
||||
|
||||
3
go.mod
3
go.mod
@@ -77,7 +77,6 @@ require (
|
||||
github.com/wealdtech/go-bytesutil v1.1.1
|
||||
github.com/wealdtech/go-eth2-util v1.6.3
|
||||
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3
|
||||
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3
|
||||
go.etcd.io/bbolt v1.3.5
|
||||
go.opencensus.io v0.24.0
|
||||
go.uber.org/automaxprocs v1.3.0
|
||||
@@ -242,7 +241,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
|
||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
|
||||
github.com/fatih/color v1.9.0 // indirect
|
||||
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1267,8 +1267,6 @@ github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3 h1:SxrDVSr+oXuT1
|
||||
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3/go.mod h1:qiIimacW5NhVRy8o+YxWo9YrecXqDAKKbL0+sOa0SJ4=
|
||||
github.com/wealdtech/go-eth2-wallet-types/v2 v2.8.2 h1:264/meVYWt1wFw6Mtn+xwkZkXjID42gNra4rycoiDXI=
|
||||
github.com/wealdtech/go-eth2-wallet-types/v2 v2.8.2/go.mod h1:k6kmiKWSWBTd4OxFifTEkPaBLhZspnO2KFD5XJY9nqg=
|
||||
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3 h1:shC1HB1UogxN5Ech3Yqaaxj1X/P656PPCB4RbojIJqc=
|
||||
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg=
|
||||
github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
|
||||
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
|
||||
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"journald.go",
|
||||
"journald_linux.go",
|
||||
"journalhook.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/v4/monitoring/journald",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = select({
|
||||
"@io_bazel_rules_go//go/platform:android": [
|
||||
"@com_github_wercker_journalhook//:go_default_library",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"@com_github_wercker_journalhook//:go_default_library",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
deps = [
|
||||
"@com_github_coreos_go_systemd//journal:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["journalhook_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
)
|
||||
|
||||
@@ -3,11 +3,20 @@
|
||||
package journald
|
||||
|
||||
import (
|
||||
"github.com/wercker/journalhook"
|
||||
"io"
|
||||
|
||||
"github.com/coreos/go-systemd/journal"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Enable enables the journald logrus hook
|
||||
// Enable adds the Journal hook if journal is enabled
|
||||
// Sets log output to ioutil.Discard so stdout isn't captured.
|
||||
func Enable() error {
|
||||
journalhook.Enable()
|
||||
if !journal.Enabled() {
|
||||
logrus.Warning("Journal not available but user requests we log to it. Ignoring")
|
||||
} else {
|
||||
logrus.AddHook(&JournalHook{})
|
||||
logrus.SetOutput(io.Discard)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
75
monitoring/journald/journalhook.go
Normal file
75
monitoring/journald/journalhook.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Package journald was copied directly from https://github.com/wercker/journalhook,
|
||||
// where this library was previously hosted.
|
||||
package journald
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/go-systemd/journal"
|
||||
logrus "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type JournalHook struct{}
|
||||
|
||||
var (
|
||||
severityMap = map[logrus.Level]journal.Priority{
|
||||
logrus.DebugLevel: journal.PriDebug,
|
||||
logrus.InfoLevel: journal.PriInfo,
|
||||
logrus.WarnLevel: journal.PriWarning,
|
||||
logrus.ErrorLevel: journal.PriErr,
|
||||
logrus.FatalLevel: journal.PriCrit,
|
||||
logrus.PanicLevel: journal.PriEmerg,
|
||||
}
|
||||
)
|
||||
|
||||
func stringifyOp(r rune) rune {
|
||||
// Journal wants uppercase strings. See `validVarName`
|
||||
// https://github.com/coreos/go-systemd/blob/ff118ad0f8d9cf99903d3391ca3a295671022cee/journal/journal.go#L137-L147
|
||||
switch {
|
||||
case r >= 'A' && r <= 'Z':
|
||||
return r
|
||||
case r >= '0' && r <= '9':
|
||||
return r
|
||||
case r == '_':
|
||||
return r
|
||||
case r >= 'a' && r <= 'z':
|
||||
return r - 32
|
||||
default:
|
||||
return rune('_')
|
||||
}
|
||||
}
|
||||
|
||||
func stringifyKey(key string) string {
|
||||
key = strings.Map(stringifyOp, key)
|
||||
key = strings.TrimPrefix(key, "_")
|
||||
return key
|
||||
}
|
||||
|
||||
// Journal wants strings but logrus takes anything.
|
||||
func stringifyEntries(data map[string]interface{}) map[string]string {
|
||||
entries := make(map[string]string)
|
||||
for k, v := range data {
|
||||
|
||||
key := stringifyKey(k)
|
||||
entries[key] = fmt.Sprint(v)
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
// Fire fires an entry into the journal.
|
||||
func (hook *JournalHook) Fire(entry *logrus.Entry) error {
|
||||
return journal.Send(entry.Message, severityMap[entry.Level], stringifyEntries(entry.Data))
|
||||
}
|
||||
|
||||
// Levels returns a slice of `Levels` the hook is fired for.
|
||||
func (hook *JournalHook) Levels() []logrus.Level {
|
||||
return []logrus.Level{
|
||||
logrus.PanicLevel,
|
||||
logrus.FatalLevel,
|
||||
logrus.ErrorLevel,
|
||||
logrus.WarnLevel,
|
||||
logrus.InfoLevel,
|
||||
logrus.DebugLevel,
|
||||
}
|
||||
}
|
||||
27
monitoring/journald/journalhook_test.go
Normal file
27
monitoring/journald/journalhook_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package journald
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStringifyEntries(t *testing.T) {
|
||||
input := map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"baz": 123,
|
||||
"foo-foo": "x",
|
||||
"-bar": "1",
|
||||
}
|
||||
|
||||
output := stringifyEntries(input)
|
||||
if output["FOO"] != "bar" {
|
||||
t.Fatalf("%v", output)
|
||||
t.Fatalf("expected value 'bar'. Got %q", output["FOO"])
|
||||
}
|
||||
if output["BAZ"] != "123" {
|
||||
t.Fatalf("expected value '123'. Got %q", output["BAZ"])
|
||||
}
|
||||
if output["FOO_FOO"] != "x" {
|
||||
t.Fatalf("expected value 'x'. Got %q", output["FOO_FOO"])
|
||||
}
|
||||
if output["BAR"] != "1" {
|
||||
t.Fatalf("expected value 'x'. Got %q", output["BAR"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user