Skip to content

Commit

Permalink
Add log message to diag auth latency. Replace with metrics on auth ro…
Browse files Browse the repository at this point in the history
…und trip time in the future.
  • Loading branch information
Sean Cunningham committed May 31, 2021
1 parent bbaabd7 commit 2568bfd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/fleet/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,41 @@ func authApiKey(r *http.Request, client *elasticsearch.Client, c cache.Cache) (*
}

func authAgent(r *http.Request, id string, bulker bulk.Bulk, c cache.Cache) (*model.Agent, error) {
start := time.Now()

// authenticate
key, err := authApiKey(r, bulker.Client(), c)
if err != nil {
return nil, err
}

authTime := time.Now()

agent, err := findAgentByApiKeyId(r.Context(), bulker, key.Id)
if err != nil {
return nil, err
}

findTime := time.Now()

// TOOD: Remove temporary log msg to diag roundtrip speed issue on auth
if findTime.Sub(start) > time.Second*5 {
reqId := r.Header.Get(logger.HeaderRequestID)

zlog := log.With().
Str("agentId", id).
Str(EcsHttpRequestId, reqId).
Logger()

zlog.Debug().
Int64(EcsEventDuration, authTime.Sub(start).Nanoseconds()).
Msg("authApiKey slow")

zlog.Debug().
Int64(EcsEventDuration, findTime.Sub(authTime).Nanoseconds()).
Msg("findAgentByApiKeyId slow")
}

// validate key alignment
if agent.AccessApiKeyId != key.Id {
log.Info().
Expand Down

0 comments on commit 2568bfd

Please sign in to comment.