forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented cancellation for GUI (Velocidex#789)
Instrumenting api calls can be used to inject latency. This is required to see what the GUI does when api calls are very latent. Started to implement API call cancellations to ensure that usage under latent conditions is possible.
- Loading branch information
Showing
15 changed files
with
284 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package api | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
) | ||
|
||
var ( | ||
apiHistorgram = promauto.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Name: "gui_api_latency", | ||
Help: "Latency to server API calls.", | ||
Buckets: prometheus.LinearBuckets(0.01, 0.05, 10), | ||
}, | ||
[]string{"api"}, | ||
) | ||
|
||
inject_time = 0 | ||
) | ||
|
||
func Instrument(api string) func() time.Duration { | ||
timer := prometheus.NewTimer(prometheus.ObserverFunc(func(v float64) { | ||
apiHistorgram.WithLabelValues(api).Observe(v) | ||
})) | ||
|
||
// Instrument a delay in API calls. | ||
if inject_time > 0 { | ||
time.Sleep(time.Duration(inject_time) * time.Millisecond) | ||
} | ||
|
||
return timer.ObserveDuration | ||
} |
Oops, something went wrong.