dashboard / erock/tuns / chore(analytics): send content-type to `metric-drain` #38 rss

accepted · opened on 2024-11-28T03:02:21Z by erock
Help
checkout latest patchset:
ssh pr.pico.sh print pr-38 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print ps-X | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 38
add review to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add --review 38
accept PR:
ssh pr.pico.sh pr accept 38
close PR:
ssh pr.pico.sh pr close 38
Timeline Patchsets

Range-diff rd-83

title
chore(analytics): send content-type to `metric-drain`
description
Patch removed
old #1
55cba32
new #0
(none)
title
description
Patch removed
old #0
(none)
new #1
(none)
title
chore: check for resp
description
Patch removed
old #2
334a6dc
new #0
(none)
Back to top
1: 55cba32 < -: ------- chore(analytics): send content-type to `metric-drain`

old

old:httpmuxer/httpmuxer.go new:httpmuxer/httpmuxer.go
 					slog.Info(logLine, "user", user, "userId", userId)
 
 					visit := &utils.MetricDrainVisit{
-						Namespace: "tuns",
-						UserID:    userId,
-						Host:      param.Request.Host,
-						IpAddress: param.ClientIP,
-						Status:    param.StatusCode,
-						Path:      originalURI,
-						UserAgent: param.Request.UserAgent(),
-						Referer:   param.Request.Referer(),
+						Namespace:   "tuns",
+						UserID:      userId,
+						Host:        param.Request.Host,
+						IpAddress:   param.ClientIP,
+						Status:      param.StatusCode,
+						Path:        originalURI,
+						UserAgent:   param.Request.UserAgent(),
+						Referer:     param.Request.Referer(),
+						ContentType: param.Request.Response.Header.Get("Content-Type"),
 					}
 
 					select {

new


                    

old

old:utils/state.go new:utils/state.go
 
 // MetricDrainVisit represents a visit for the metric drain.
 type MetricDrainVisit struct {
-	Namespace string `json:"namespace"`
-	UserID    string `json:"user_id"`
-	Host      string `json:"host"`
-	Path      string `json:"path"`
-	IpAddress string `json:"ip_address"`
-	UserAgent string `json:"user_agent"`
-	Referer   string `json:"referer"`
-	Status    int    `json:"status"`
+	Namespace   string `json:"namespace"`
+	UserID      string `json:"user_id"`
+	Host        string `json:"host"`
+	Path        string `json:"path"`
+	IpAddress   string `json:"ip_address"`
+	UserAgent   string `json:"user_agent"`
+	Referer     string `json:"referer"`
+	Status      int    `json:"status"`
+	ContentType string `json:"content_type"`
 }
 
 // State handles overall state. It retains mutexed maps for various

new


                    
-: ------- > 1:
2: 334a6dc < -: ------- chore: check for resp

old

old:httpmuxer/httpmuxer.go new:httpmuxer/httpmuxer.go
 					slog.Info(logLine, "user", user, "userId", userId)
 
 					visit := &utils.MetricDrainVisit{
-						Namespace:   "tuns",
-						UserID:      userId,
-						Host:        param.Request.Host,
-						IpAddress:   param.ClientIP,
-						Status:      param.StatusCode,
-						Path:        originalURI,
-						UserAgent:   param.Request.UserAgent(),
-						Referer:     param.Request.Referer(),
-						ContentType: param.Request.Response.Header.Get("Content-Type"),
+						Namespace: "tuns",
+						UserID:    userId,
+						Host:      param.Request.Host,
+						IpAddress: param.ClientIP,
+						Status:    param.StatusCode,
+						Path:      originalURI,
+						UserAgent: param.Request.UserAgent(),
+						Referer:   param.Request.Referer(),
+					}
+
+					if param.Request.Response != nil {
+						visit.ContentType = param.Request.Response.Header.Get("Content-Type")
 					}
 
 					select {

new