Skip to content

Commit

Permalink
routesrv: log etag on routes update (#2608)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Sep 20, 2023
1 parent 4503d2c commit c62c064
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions routesrv/eskipbytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type eskipBytes struct {
// formatAndSet takes a slice of routes and stores them eskip-formatted
// in a synchronized way. It returns the length of the stored data, and
// flags signaling whether the data was initialized and updated.
func (e *eskipBytes) formatAndSet(routes []*eskip.Route) (_ int, initialized bool, updated bool) {
func (e *eskipBytes) formatAndSet(routes []*eskip.Route) (_ int, _ string, initialized bool, updated bool) {
buf := &bytes.Buffer{}
eskip.Fprint(buf, eskip.PrettyPrintInfo{Pretty: false, IndentStr: ""}, routes...)
data := buf.Bytes()
Expand All @@ -51,7 +51,7 @@ func (e *eskipBytes) formatAndSet(routes []*eskip.Route) (_ int, initialized boo
initialized = !e.initialized
e.initialized = true

return len(e.data), initialized, updated
return len(e.data), e.etag, initialized, updated
}

func (e *eskipBytes) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand Down
5 changes: 3 additions & 2 deletions routesrv/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (p *poller) poll(wg *sync.WaitGroup) {
"message", LogRoutesEmpty,
)
case routesCount > 0:
routesBytes, initialized, updated := p.b.formatAndSet(routes)
logger := log.WithFields(log.Fields{"count": routesCount, "bytes": routesBytes})
routesBytes, routesEtag, initialized, updated := p.b.formatAndSet(routes)
logger := log.WithFields(log.Fields{"count": routesCount, "bytes": routesBytes, "etag": routesEtag})
if initialized {
logger.Info(LogRoutesInitialized)
span.SetTag("routes.initialized", true)
Expand All @@ -110,6 +110,7 @@ func (p *poller) poll(wg *sync.WaitGroup) {
}
span.SetTag("routes.count", routesCount)
span.SetTag("routes.bytes", routesBytes)
span.SetTag("routes.etag", routesEtag)

if updated && log.IsLevelEnabled(log.DebugLevel) {
routesById := mapRoutes(routes)
Expand Down

0 comments on commit c62c064

Please sign in to comment.