Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

feat(gorouter): add route-service-url to access log #339

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion accesslog/schema/access_log_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -101,6 +102,7 @@ type AccessLogRecord struct {
HeadersOverride http.Header
StatusCode int
RouteEndpoint *route.Endpoint
RouteServiceUrl *url.URL
RoundtripStartedAt time.Time
FirstByteAt time.Time
RoundtripFinishedAt time.Time
Expand Down Expand Up @@ -152,7 +154,7 @@ func (r *AccessLogRecord) getRecord(performTruncate bool) []byte {
}

func (r *AccessLogRecord) makeRecord(performTruncate bool) []byte {
var appID, destIPandPort, appIndex, instanceId string
var appID, destIPandPort, appIndex, instanceId, routeServiceUrl string

if r.RouteEndpoint != nil {
appID = r.RouteEndpoint.ApplicationId
Expand All @@ -161,6 +163,10 @@ func (r *AccessLogRecord) makeRecord(performTruncate bool) []byte {
instanceId = r.RouteEndpoint.PrivateInstanceId
}

if r.RouteServiceUrl != nil {
routeServiceUrl = truncateToSize(r.RouteServiceUrl.String(), "route-service-url", LARGE_BYTES_LIMIT)
}

headers := r.Request.Header
if r.HeadersOverride != nil {
headers = r.HeadersOverride
Expand Down Expand Up @@ -224,6 +230,9 @@ func (r *AccessLogRecord) makeRecord(performTruncate bool) []byte {
b.WriteString(`instance_id:`)
b.WriteDashOrStringValue(instanceId)

b.WriteString(`route_service_url:`)
b.WriteDashOrStringValue(routeServiceUrl)

b.AppendSpaces(false)
b.WriteString(`x_cf_routererror:`)
b.WriteDashOrStringValue(r.RouterError)
Expand Down
1 change: 1 addition & 0 deletions handlers/access_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (a *accessLog) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http
alr.AppRequestFinishedAt = reqInfo.AppRequestFinishedAt
alr.HeadersOverride = reqInfo.BackendReqHeaders
alr.RouteEndpoint = reqInfo.RouteEndpoint
alr.RouteServiceUrl = reqInfo.RouteServiceURL
alr.RequestBytesReceived = requestBodyCounter.GetCount()
alr.BodyBytesSent = proxyWriter.Size()
alr.StatusCode = proxyWriter.Status()
Expand Down
2 changes: 1 addition & 1 deletion handlers/requestinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type key string
const RequestInfoCtxKey key = "RequestInfo"

// RequestInfo stores all metadata about the request and is used to pass
// informaton between handlers
// information between handlers
type RequestInfo struct {
StartedAt, StoppedAt time.Time
AppRequestStartedAt, AppRequestFinishedAt time.Time
Expand Down