This commit is contained in:
Daniel 2024-10-31 16:50:08 -04:00
parent d2145bd1d9
commit 662e5d09ec
9 changed files with 22 additions and 15 deletions

View file

@ -120,7 +120,10 @@ func New(cfg config.Alerting, opts ...AlertOption) Alerter {
// Go is the alerting loop. It does not start a goroutine.
func (as *alerter) Go(ctx context.Context) {
as.startBackfill(ctx)
err := as.startBackfill(ctx)
if err != nil {
log.Error().Err(err).Msg("backfill")
}
as.score(time.Now())
ticker := time.NewTicker(alerterTickInterval)
@ -179,7 +182,7 @@ func (as *alerter) testNotifyHandler(w http.ResponseWriter, r *http.Request) {
return
}
w.Write([]byte("Sent"))
_, _ = w.Write([]byte("Sent"))
}
// packedScoredTGs gets a packed list of TG IDs for DB use.
@ -323,9 +326,9 @@ func (as *alerter) startBackfill(ctx context.Context) error {
log.Debug().Time("since", since).Msg("starting stats backfill")
count, err := as.backfill(ctx, since, now)
if err != nil {
return fmt.Errorf("backfill failed: %w", err)
return err
}
log.Debug().Int("callsCount", count).Str("in", time.Now().Sub(now).String()).Int("tgCount", as.scorer.Score().Len()).Msg("backfill finished")
log.Debug().Int("callsCount", count).Str("in", time.Since(now).String()).Int("tgCount", as.scorer.Score().Len()).Msg("backfill finished")
return nil
}

View file

@ -77,7 +77,10 @@ func (s *Simulation) Simulate(ctx context.Context) trending.Scores[cl.Talkgroup]
sinceLookback := time.Time(scoreEnd).Add(-24 * time.Hour * time.Duration(s.LookbackDays))
// backfill from lookback start until score start
s.backfill(ctx, sinceLookback, time.Time(s.ScoreStart))
_, err := s.backfill(ctx, sinceLookback, time.Time(s.ScoreStart))
if err != nil {
log.Error().Err(err).Msg("simulate backfill")
}
// initial score
s.scores = s.scorer.Score()
@ -94,7 +97,10 @@ func (s *Simulation) Simulate(ctx context.Context) trending.Scores[cl.Talkgroup]
// compute time since score start until now
// backfill from scorestart until now. sim is enabled, so scoring will be done by stepClock()
s.backfill(ctx, time.Time(s.ScoreStart), scoreEnd)
_, err = s.backfill(ctx, time.Time(s.ScoreStart), scoreEnd)
if err != nil {
log.Error().Err(err).Msg("simulate backfill final")
}
s.lastScore = scoreEnd
sort.Sort(s.scores)

View file

@ -92,7 +92,7 @@ func pbServerInfo(ctx context.Context) *pb.ServerInfo {
}
func (c *client) Hello(ctx context.Context) {
c.Send(&pb.Message{
_ = c.Send(&pb.Message{
ToClientMessage: &pb.Message_Hello{
Hello: &pb.Hello{
ServerInfo: pbServerInfo(ctx),

View file

@ -57,7 +57,7 @@ func (c *client) SendError(cmd *pb.Command, err error) {
},
},
}
c.Send(e)
_ = c.Send(e)
}
func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error {
@ -73,7 +73,7 @@ func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error {
var md *structpb.Struct
if len(tgi.Metadata) > 0 {
m := make(map[string]interface{})
err := json.Unmarshal(tgi.Metadata, m)
err := json.Unmarshal(tgi.Metadata, &m)
if err != nil {
log.Error().Err(err).Int32("sys", tg.System).Int32("tg", tg.Talkgroup).Msg("unmarshal tg metadata")
}
@ -95,7 +95,7 @@ func (c *client) Talkgroup(ctx context.Context, tg *pb.Talkgroup) error {
SystemName: tgi.SystemName,
}
c.Send(&pb.Message{
_ = c.Send(&pb.Message{
ToClientMessage: &pb.Message_Response{
Response: &pb.CommandResponse{
CommandId: CommandID(ctx),

View file

@ -86,7 +86,7 @@ func (wm *wsManager) serveWS(w http.ResponseWriter, r *http.Request) {
}
func (conn *wsConn) Shutdown() {
conn.Conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseGoingAway, ""), time.Now().Add(writeWait))
_ = conn.Conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseGoingAway, ""), time.Now().Add(writeWait))
}
func (conn *wsConn) readPump(ctx context.Context, reg Registry, c Client) {

View file

@ -17,7 +17,6 @@ type Notifier interface {
type notifier struct {
*notify.Notify
cfg []config.NotifyService
}
func (n *notifier) buildSlackWebhookPayload(cfg config.NotifyService) func(string, string) any {

View file

@ -156,6 +156,7 @@ func RequestLogger() func(next http.Handler) http.Handler {
}
}
//nolint:unused
const (
colorBlack = iota + 30
colorRed

View file

@ -77,7 +77,7 @@ func (s *Server) clientRoute(r chi.Router, clientRoot fs.FS) {
func ServerHeaderAdd(next http.Handler) http.Handler {
serverString := version.HttpString("gordio")
hfn := func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Server", serverString)
w.Header().Set(serverHeader, serverString)
next.ServeHTTP(w, r)
}
return http.HandlerFunc(hfn)

View file

@ -47,8 +47,6 @@ func New(ctx context.Context, cfg *config.Config) (*Server, error) {
return nil, err
}
ctx = database.CtxWithDB(ctx, db)
r := chi.NewRouter()
authenticator := auth.NewAuthenticator(cfg.Auth)