How to get current timestamp in proxy-wasm-go-sdk

447 Views Asked by At

When using a WasmPlugin with Istio 1.12 and proxy-wasm-go-sdk, it seems that stdlib-functions like time.Now() are not available, and I have not found an alternative. However, there is GetProperty() function, which allows to access some request properties like request.time.

So I ended up with something like

requestStart, err := proxywasm.GetProperty([]string{"request", "time"})

proxywasm.LogInfof("len %v", len(requestStart))
requestStartTs := binary.LittleEndian.Uint64(requestStart)
proxywasm.LogInfof("request.start %v", requestStartTs)

It prints

2022-02-15T17:48:18.806485Z info    envoy wasm  wasm log redacted: len 8
2022-02-15T17:48:18.806516Z info    envoy wasm  wasm log redacted: request.start 1644947298806002000

Now this seems to be a Unix timestamp with that given time, but I am not at all sure if I have got this right.

Is there maybe a less low-level method to get a current timestamp?

1

There are 1 best solutions below

1
Peter Claes On

Time library should be available. Did you import it in your go file ? Example : https://github.com/tetratelabs/proxy-wasm-go-sdk/blob/main/examples/helloworld/main.go