Logs
Patchsets
Range Diff ↕ rd-82
1: 55cba32 = 1: 55cba32 chore(analytics): send content-type to `metric-drain`
-: ------- > 2: 334a6dc chore: check for resp
Range Diff ↕ rd-83
1: 55cba32 < -: ------- chore(analytics): send content-type to `metric-drain`
-: ------- > 1:
2: 334a6dc < -: ------- chore: check for resp
Range Diff ↕ rd-84
1: ! 1: ea8a742 chore(analytics): send content-type to `metric-drain`
Range-diff rd-84
- title
- chore(analytics): send content-type to `metric-drain`
- description
-
Patch added - old #1
(none)- new #1
ea8a742
1: ! 1: ea8a742 chore(analytics): send content-type to `metric-drain`
- author changed
-
- Unknown <>+ Eric Bower <me@erock.io>
- title changed
-
-+ chore(analytics): send content-type to `metric-drain`
old
new
old:
httpmuxer/httpmuxer.go
new:httpmuxer/httpmuxer.go
"github.com/gin-gonic/gin" ) +func createMetricDrainMdw(state *utils.State) func(*gin.Context) { + return func(c *gin.Context) { + fmt.Println(c.Keys) + originalURI := c.Keys["originalURI"].(string) + + if viper.GetString("admin-console-token") != "" && strings.Contains(originalURI, viper.GetString("admin-console-token")) { + originalURI = strings.Replace(originalURI, viper.GetString("admin-console-token"), "[REDACTED]", 1) + } + + if viper.GetString("service-console-token") != "" && strings.Contains(originalURI, viper.GetString("service-console-token")) { + originalURI = strings.Replace(originalURI, viper.GetString("service-console-token"), "[REDACTED]", 1) + } + + if c.Keys["httpHolder"] != nil { + currentListener := c.Keys["httpHolder"].(*utils.HTTPHolder) + + if currentListener != nil { + currentListener.SSHConnections.Range(func(I string, conn *utils.SSHConnection) bool { + userId := conn.UserId() + + visit := &utils.MetricDrainVisit{ + Namespace: "tuns", + UserID: userId, + Host: c.Request.Host, + IpAddress: c.ClientIP(), + Status: c.Writer.Status(), + Path: originalURI, + UserAgent: c.Request.UserAgent(), + Referer: c.Request.Referer(), + } + + visit.ContentType = c.Writer.Header().Get("content-type") + + select { + case state.MetricDrain <- visit: + default: + slog.Error("unable to send metric drain visit", slog.Any("visit", visit)) + } + + return true + }) + } + } + + c.Next() + } +} + // Start initializes the HTTP service. func Start(state *utils.State) { releaseMode := gin.ReleaseMode 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(), - } - - select { - case state.MetricDrain <- visit: - default: - slog.Error("unable to send metric drain visit", slog.Any("visit", visit)) - } - return true }) } } gin.WrapH(currentListener.Balancer)(c) - }) + }, createMetricDrainMdw(state)) var acmeIssuer *certmagic.ACMEIssuer = nil
old
new
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