Add simple anonymous usage metrics (#1167)
This change reports total function call count to an analytics url once a day. It's done behind the existing analytics flag.
This commit is contained in:
@@ -209,6 +209,13 @@ spec:
|
|||||||
value: {{ .Values.debugEnv | quote }}
|
value: {{ .Values.debugEnv | quote }}
|
||||||
- name: TRACING_SAMPLING_RATE
|
- name: TRACING_SAMPLING_RATE
|
||||||
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
|
value: {{ .Values.traceSamplingRate | default "0.5" | quote }}
|
||||||
|
{{ if .Values.analytics }}
|
||||||
|
- name: ANALYTICS_URL
|
||||||
|
value: "https://g.fission.sh/metrics"
|
||||||
|
{{ else if .Values.analyticsNonHelmInstall }}
|
||||||
|
- name: ANALYTICS_URL
|
||||||
|
value: "https://g.fission.sh/metrics"
|
||||||
|
{{ end }}
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: "/router-healthz"
|
path: "/router-healthz"
|
||||||
|
|||||||
@@ -211,6 +211,13 @@ spec:
|
|||||||
value: {{ .Values.routerRoundTripSvcAddressUpdateTimeout | default 30 | quote }}
|
value: {{ .Values.routerRoundTripSvcAddressUpdateTimeout | default 30 | quote }}
|
||||||
- name: DEBUG_ENV
|
- name: DEBUG_ENV
|
||||||
value: {{ .Values.debugEnv | quote }}
|
value: {{ .Values.debugEnv | quote }}
|
||||||
|
{{ if .Values.analytics }}
|
||||||
|
- name: ANALYTICS_URL
|
||||||
|
value: "https://g.fission.sh/metrics"
|
||||||
|
{{ else if .Values.analyticsNonHelmInstall }}
|
||||||
|
- name: ANALYTICS_URL
|
||||||
|
value: "https://g.fission.sh/metrics"
|
||||||
|
{{ end }}
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: "/router-healthz"
|
path: "/router-healthz"
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/dchest/uniuri"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Analytics struct {
|
||||||
|
id string
|
||||||
|
url string
|
||||||
|
}
|
||||||
|
AnalyticsData struct {
|
||||||
|
id string
|
||||||
|
FunctionCallCount uint64 `json:"FunctionCallCount"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func MakeAnalytics(url string) *Analytics {
|
||||||
|
|
||||||
|
if len(url) == 0 {
|
||||||
|
url = os.Getenv("ANALYTICS_URL")
|
||||||
|
if len(url) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &Analytics{
|
||||||
|
url: url,
|
||||||
|
id: uniuri.NewLen(8),
|
||||||
|
}
|
||||||
|
go a.run()
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Analytics) gatherData() *AnalyticsData {
|
||||||
|
return &AnalyticsData{
|
||||||
|
FunctionCallCount: atomic.LoadUint64(&globalFunctionCallCount),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Analytics) run() {
|
||||||
|
ticker := time.NewTicker(24 * time.Hour)
|
||||||
|
for range ticker.C {
|
||||||
|
msg := a.gatherData()
|
||||||
|
msg.id = a.id
|
||||||
|
|
||||||
|
msgbytes, err := json.Marshal(*msg)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = http.Post(a.url, "application/json", bytes.NewReader(msgbytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,11 +2,14 @@ package router
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var globalFunctionCallCount uint64
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// functionLabels is the set of metrics labels that relate to
|
// functionLabels is the set of metrics labels that relate to
|
||||||
// functions.
|
// functions.
|
||||||
@@ -116,6 +119,8 @@ func labelsToStrings(f *functionLabels, h *httpLabels) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func functionCallCompleted(f *functionLabels, h *httpLabels, overhead, duration time.Duration, respSize int64) {
|
func functionCallCompleted(f *functionLabels, h *httpLabels, overhead, duration time.Duration, respSize int64) {
|
||||||
|
atomic.AddUint64(&globalFunctionCallCount, 1)
|
||||||
|
|
||||||
l := labelsToStrings(f, h)
|
l := labelsToStrings(f, h)
|
||||||
|
|
||||||
// overhead: time from request ingress into router upto proxing into function pod
|
// overhead: time from request ingress into router upto proxing into function pod
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ func Start(logger *zap.Logger, port int, executorUrl string) {
|
|||||||
// setup a signal handler for SIGTERM
|
// setup a signal handler for SIGTERM
|
||||||
fission.SetupStackTraceHandler()
|
fission.SetupStackTraceHandler()
|
||||||
|
|
||||||
|
_ = MakeAnalytics("")
|
||||||
|
|
||||||
fmap := makeFunctionServiceMap(logger, time.Minute)
|
fmap := makeFunctionServiceMap(logger, time.Minute)
|
||||||
|
|
||||||
frmap := makeFunctionRecorderMap(logger, time.Minute)
|
frmap := makeFunctionRecorderMap(logger, time.Minute)
|
||||||
|
|||||||
Reference in New Issue
Block a user