mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 20:59:58 +00:00
TUN-4811: Publish quick tunnels' hostname in /metrics under userHostname
for backwards-compatibility
This commit is contained in:
@@ -111,6 +111,13 @@ func (o *Observer) sendConnectedEvent(connIndex uint8, location string) {
|
||||
|
||||
func (o *Observer) sendURL(url string) {
|
||||
o.sendEvent(Event{EventType: SetURL, URL: url})
|
||||
|
||||
if !strings.HasPrefix(url, "https://") {
|
||||
// We add https:// in the prefix for backwards compatibility as we used to do that with the old free tunnels
|
||||
// and some tools (like `wrangler tail`) are regexp-ing for that specifically.
|
||||
url = "https://" + url
|
||||
}
|
||||
o.metrics.userHostnamesCounts.WithLabelValues(url).Inc()
|
||||
}
|
||||
|
||||
func (o *Observer) SendReconnect(connIndex uint8) {
|
||||
|
@@ -6,9 +6,28 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSendUrl(t *testing.T) {
|
||||
observer := NewObserver(&log, &log, false)
|
||||
|
||||
observer.sendURL("my-url.com")
|
||||
assert.Equal(t, 1.0, getCounterValue(t, observer.metrics.userHostnamesCounts, "https://my-url.com"))
|
||||
|
||||
observer.sendURL("https://another-long-one.com")
|
||||
assert.Equal(t, 1.0, getCounterValue(t, observer.metrics.userHostnamesCounts, "https://another-long-one.com"))
|
||||
}
|
||||
|
||||
func getCounterValue(t *testing.T, metric *prometheus.CounterVec, val string) float64 {
|
||||
var m = &dto.Metric{}
|
||||
err := metric.WithLabelValues(val).Write(m)
|
||||
assert.NoError(t, err)
|
||||
return m.Counter.GetValue()
|
||||
}
|
||||
|
||||
func TestRegisterServerLocation(t *testing.T) {
|
||||
m := newTunnelMetrics()
|
||||
tunnels := 20
|
||||
|
Reference in New Issue
Block a user