tuns
created pr with
38.1
added 38.2
1: 55cba32 = 1: 55cba32 chore(analytics): send content-type to `metric-drain`
-: ------- > 2: 334a6dc chore: check for resp
added 38.3
1: 55cba32 < -: ------- chore(analytics): send content-type to `metric-drain`
-: ------- > 1:
2: 334a6dc < -: ------- chore: check for resp
added 38.4
1: < -: -------
-: ------- > 1: ea8a742 chore(analytics): send content-type to `metric-drain`
cmds
checkout latest patchset:
ssh pr.pico.sh print 38 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 38.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 38
Patchset
38.4
chore(analytics): send content-type to `metric-drain`
Eric Bower
2024-11-28T03:01:26ZSemantic diff summary
1 added,
2 modified,
0 signature changed,
0 removed
across 2 analyzed files
+49
-18
httpmuxer/httpmuxer.go
#
| ... | ... | @@ -32,6 +32,54 @@ import ( | |
| 32 | 32 | "github.com/gin-gonic/gin" | |
| 33 | 33 | ) | |
| 34 | 34 | ||
| 35 | + | func createMetricDrainMdw(state *utils.State) func(*gin.Context) { | |
| 36 | + | return func(c *gin.Context) { | |
| 37 | + | fmt.Println(c.Keys) | |
| 38 | + | originalURI := c.Keys["originalURI"].(string) | |
| 39 | + | ||
| 40 | + | if viper.GetString("admin-console-token") != "" && strings.Contains(originalURI, viper.GetString("admin-console-token")) { | |
| 41 | + | originalURI = strings.Replace(originalURI, viper.GetString("admin-console-token"), "[REDACTED]", 1) | |
| 42 | + | } | |
| 43 | + | ||
| 44 | + | if viper.GetString("service-console-token") != "" && strings.Contains(originalURI, viper.GetString("service-console-token")) { | |
| 45 | + | originalURI = strings.Replace(originalURI, viper.GetString("service-console-token"), "[REDACTED]", 1) | |
| 46 | + | } | |
| 47 | + | ||
| 48 | + | if c.Keys["httpHolder"] != nil { | |
| 49 | + | currentListener := c.Keys["httpHolder"].(*utils.HTTPHolder) | |
| 50 | + | ||
| 51 | + | if currentListener != nil { | |
| 52 | + | currentListener.SSHConnections.Range(func(I string, conn *utils.SSHConnection) bool { | |
| 53 | + | userId := conn.UserId() | |
| 54 | + | ||
| 55 | + | visit := &utils.MetricDrainVisit{ | |
| 56 | + | Namespace: "tuns", | |
| 57 | + | UserID: userId, | |
| 58 | + | Host: c.Request.Host, | |
| 59 | + | IpAddress: c.ClientIP(), | |
| 60 | + | Status: c.Writer.Status(), | |
| 61 | + | Path: originalURI, | |
| 62 | + | UserAgent: c.Request.UserAgent(), | |
| 63 | + | Referer: c.Request.Referer(), | |
| 64 | + | } | |
| 65 | + | ||
| 66 | + | visit.ContentType = c.Writer.Header().Get("content-type") | |
| 67 | + | ||
| 68 | + | select { | |
| 69 | + | case state.MetricDrain <- visit: | |
| 70 | + | default: | |
| 71 | + | slog.Error("unable to send metric drain visit", slog.Any("visit", visit)) | |
| 72 | + | } | |
| 73 | + | ||
| 74 | + | return true | |
| 75 | + | }) | |
| 76 | + | } | |
| 77 | + | } | |
| 78 | + | ||
| 79 | + | c.Next() | |
| 80 | + | } | |
| 81 | + | } | |
| 82 | + | ||
| 35 | 83 | // Start initializes the HTTP service. | |
| 36 | 84 | func Start(state *utils.State) { | |
| 37 | 85 | releaseMode := gin.ReleaseMode |
| ... | ... | @@ -128,23 +176,6 @@ func Start(state *utils.State) { | |
| 128 | 176 | ||
| 129 | 177 | slog.Info(logLine, "user", user, "userId", userId) | |
| 130 | 178 | ||
| 131 | - | visit := &utils.MetricDrainVisit{ | |
| 132 | - | Namespace: "tuns", | |
| 133 | - | UserID: userId, | |
| 134 | - | Host: param.Request.Host, | |
| 135 | - | IpAddress: param.ClientIP, | |
| 136 | - | Status: param.StatusCode, | |
| 137 | - | Path: originalURI, | |
| 138 | - | UserAgent: param.Request.UserAgent(), | |
| 139 | - | Referer: param.Request.Referer(), | |
| 140 | - | } | |
| 141 | - | ||
| 142 | - | select { | |
| 143 | - | case state.MetricDrain <- visit: | |
| 144 | - | default: | |
| 145 | - | slog.Error("unable to send metric drain visit", slog.Any("visit", visit)) | |
| 146 | - | } | |
| 147 | - | ||
| 148 | 179 | return true | |
| 149 | 180 | }) | |
| 150 | 181 | } |
+9
-8
utils/state.go
#
| ... | ... | @@ -218,14 +218,15 @@ type Ports struct { | |
| 218 | 218 | ||
| 219 | 219 | // MetricDrainVisit represents a visit for the metric drain. | |
| 220 | 220 | type MetricDrainVisit struct { | |
| 221 | - | Namespace string `json:"namespace"` | |
| 222 | - | UserID string `json:"user_id"` | |
| 223 | - | Host string `json:"host"` | |
| 224 | - | Path string `json:"path"` | |
| 225 | - | IpAddress string `json:"ip_address"` | |
| 226 | - | UserAgent string `json:"user_agent"` | |
| 227 | - | Referer string `json:"referer"` | |
| 228 | - | Status int `json:"status"` | |
| 221 | + | Namespace string `json:"namespace"` | |
| 222 | + | UserID string `json:"user_id"` | |
| 223 | + | Host string `json:"host"` | |
| 224 | + | Path string `json:"path"` | |
| 225 | + | IpAddress string `json:"ip_address"` | |
| 226 | + | UserAgent string `json:"user_agent"` | |
| 227 | + | Referer string `json:"referer"` | |
| 228 | + | Status int `json:"status"` | |
| 229 | + | ContentType string `json:"content_type"` | |
| 229 | 230 | } | |
| 230 | 231 | ||
| 231 | 232 | // State handles overall state. It retains mutexed maps for various |