Esempio n. 1
0
// LoadHandler is the handler for the request to "/". It is to this api endpoint
// that we will send the traffic patterns to test auto-scaling. This endpoint
// first performs some relatively substantial amount of computational work that
// will utilize a portion of the CPU, and then writes the CPU utilization for
// the pod and some metric measuring of quality of service, such as how long it
// took the pod to perform the previous computation.
func LoadHandler(w http.ResponseWriter, r *http.Request) {
	eru, qos, err := profileFunction(costIntensiveTask)

	if err != nil {
		handleError(err, w, r)
	} else {
		trafficPattern := r.URL.Query().Get(TrafficPatternParam)
		err = database.WriteMetrics(eru, qos, trafficPattern)

		if err != nil {
			handleError(err, w, r)
		} else {
			// Output the response as JSON.
			w.WriteHeader(200)

			enc, err := json.Marshal(map[string]interface{}{
				"eru":             eru,
				"qos":             qos,
				"traffic-pattern": trafficPattern,
			})

			if err == nil {
				w.Write(enc)
			}
		}
	}

	return
}
Esempio n. 2
0
func writeToDatabase(t *testing.T) {
	eru, qos, trafficPattern := 1.0, 1.0, "increase-decrease"
	err := database.WriteMetrics(eru, qos, trafficPattern)

	if err != nil {
		t.Fatal("Error writing metrics to the database.")
	}
}