forked from qlik-oss/enigma-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
46 lines (35 loc) · 1.23 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"context"
"fmt"
"github.com/qlik-oss/enigma-go"
)
func main() {
const script = "TempTable: Load RecNo() as ID, Rand() as Value AutoGenerate 1000000"
ctx := context.Background()
// Configure the dialer to use an interceptor.
dialer := enigma.Dialer{
Interceptors: []enigma.Interceptor{
metricsInterceptor,
},
}
// Connect to Qlik Associative Engine
global, err := dialer.Dial(ctx, "ws://localhost:9076", nil)
if err != nil {
fmt.Println("Could not connect", err)
panic(err)
}
// Once connected, create a session app and populate it with some data.
doc, _ := global.CreateSessionApp(ctx)
doc.SetScript(ctx, script)
doc.DoReload(ctx, 0, false, false)
global.DisconnectFromServer()
}
// MetricsInterceptor shows how to an interceptor that collects metrics data can be written.
func metricsInterceptor(ctx context.Context, invocation *enigma.Invocation, proceed enigma.InterceptorContinuation) *enigma.InvocationResponse {
ctxWithMetrics, metricsCollector := enigma.WithMetricsCollector(ctx)
response := proceed(ctxWithMetrics, invocation)
metrics := metricsCollector.Metrics()
fmt.Println(response.RequestID, invocation.RemoteObject.Type, invocation.Method, metrics.ToString())
return response
}