Skip to content

Commit

Permalink
Modify metric endpoints (#1629)
Browse files Browse the repository at this point in the history
* Rename /metrics to /abnDashboard

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Fix comments

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Change experiment query parameter to test

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Fix comment

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Split application parameter into namespace and application

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Change PUT /experimentResult to /testResult

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Remove extraneous line

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Change putExperimentResult to use test query param

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Fix logging statement

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Fix variable name

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

* Up coverage

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>

---------

Signed-off-by: Alan Cha <Alan.cha1@ibm.com>
  • Loading branch information
Alan-Cha committed Sep 8, 2023
1 parent 3c2a0a0 commit f873bca
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 87 deletions.
2 changes: 1 addition & 1 deletion action/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestKubeRun(t *testing.T) {
metricsServerCalled = true

// check query parameters
assert.Equal(t, myName, req.URL.Query().Get("experiment"))
assert.Equal(t, myName, req.URL.Query().Get("test"))
assert.Equal(t, myNamespace, req.URL.Query().Get("namespace"))

// check payload
Expand Down
13 changes: 13 additions & 0 deletions base/collect_http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package base

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -126,6 +127,18 @@ func (t *collectHTTPTask) validateInputs() error {

// getFortioOptions constructs Fortio's HTTP runner options based on collect task inputs
func getFortioOptions(c endpoint) (*fhttp.HTTPRunnerOptions, error) {
if c.QPS == nil {
return nil, errors.New("no value for QPS")
}

if c.Connections == nil {
return nil, errors.New("no value for Connections")
}

if c.AllowInitialErrors == nil {
return nil, errors.New("no value for AllowInitialErrors")
}

// basic runner
fo := &fhttp.HTTPRunnerOptions{
RunnerOptions: periodic.RunnerOptions{
Expand Down
44 changes: 44 additions & 0 deletions base/collect_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,3 +489,47 @@ func TestRunCollectHTTPWithIncorrectNumVersions(t *testing.T) {
// error ensures that Fortio results are not written to insights
assert.Nil(t, exp.Result.Insights.TaskData)
}

func TestGetFortioOptions(t *testing.T) {
// check to catch nil QPS
_, err := getFortioOptions(endpoint{})
assert.Error(t, err)

// check for catch nil connections
QPS := float32(8)
_, err = getFortioOptions(endpoint{
QPS: &QPS,
})
assert.Error(t, err)

// check to catch nil allowInitialErrors
connections := 8
_, err = getFortioOptions(endpoint{
QPS: &QPS,
Connections: &connections,
})
assert.Error(t, err)

numRequests := int64(5)
contentType := "testType"
payloadStr := "testPayload"
allowInitialErrors := true

options, err := getFortioOptions(endpoint{
NumRequests: &numRequests,
ContentType: &contentType,
PayloadStr: &payloadStr,
QPS: &QPS,
Connections: &connections,
AllowInitialErrors: &allowInitialErrors,
})

assert.NoError(t, err)

s, _ := json.Marshal(options)
fmt.Println(string(s))

assert.Equal(t, numRequests, options.RunnerOptions.Exactly)
assert.Equal(t, contentType, options.ContentType)
assert.Equal(t, []byte(payloadStr), options.Payload)
}
2 changes: 1 addition & 1 deletion base/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestRunExperiment(t *testing.T) {
metricsServerCalled = true

// check query parameters
assert.Equal(t, myName, req.URL.Query().Get("experiment"))
assert.Equal(t, myName, req.URL.Query().Get("test"))
assert.Equal(t, myNamespace, req.URL.Query().Get("namespace"))

// check payload
Expand Down
16 changes: 8 additions & 8 deletions base/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const (
// MetricsServerURL is the URL of the metrics server
MetricsServerURL = "METRICS_SERVER_URL"

// MetricsPath is the path to the GET /metrics endpoint
MetricsPath = "/metrics"
// TestResultPath is the path to the PUT /testResult endpoint
TestResultPath = "/testResult"

// ExperimentResultPath is the path to the PUT /experimentResult endpoint
ExperimentResultPath = "/experimentResult"
// AbnDashboard is the path to the GET /abnDashboard endpoint
AbnDashboard = "/abnDashboard"
// HTTPDashboardPath is the path to the GET /httpDashboard endpoint
HTTPDashboardPath = "/httpDashboard"
// GRPCDashboardPath is the path to the GET /grpcDashboard endpoint
Expand Down Expand Up @@ -79,10 +79,10 @@ func callMetricsService(method, metricsServerURL, path string, queryParams map[s
return nil
}

// PutExperimentResultToMetricsService sends the experiment result to the metrics service
// PutExperimentResultToMetricsService sends the test result to the metrics service
func PutExperimentResultToMetricsService(metricsServerURL, namespace, experiment string, experimentResult *ExperimentResult) error {
return callMetricsService(http.MethodPut, metricsServerURL, ExperimentResultPath, map[string]string{
"namespace": namespace,
"experiment": experiment,
return callMetricsService(http.MethodPut, metricsServerURL, TestResultPath, map[string]string{
"namespace": namespace,
"test": experiment,
}, experimentResult)
}
6 changes: 3 additions & 3 deletions base/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type MetricsServerCallback func(req *http.Request)
type MockMetricsServerInput struct {
MetricsServerURL string

// PUT /experimentResult
// PUT /testResult
ExperimentResultCallback MetricsServerCallback
// GET /grpcDashboard
GRPCDashboardCallback MetricsServerCallback
Expand All @@ -115,10 +115,10 @@ type MockMetricsServerInput struct {
// MockMetricsServer is a mock metrics server
// use the callback functions in the MockMetricsServerInput to test if those endpoints are called
func MockMetricsServer(input MockMetricsServerInput) {
// PUT /experimentResult
// PUT /testResult
httpmock.RegisterResponder(
http.MethodPut,
input.MetricsServerURL+ExperimentResultPath,
input.MetricsServerURL+TestResultPath,
func(req *http.Request) (*http.Response, error) {
if input.ExperimentResultCallback != nil {
input.ExperimentResultCallback(req)
Expand Down
2 changes: 1 addition & 1 deletion cmd/krun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestKRun(t *testing.T) {
metricsServerCalled = true

// check query parameters
assert.Equal(t, myName, req.URL.Query().Get("experiment"))
assert.Equal(t, myName, req.URL.Query().Get("test"))
assert.Equal(t, myNamespace, req.URL.Query().Get("namespace"))

// check payload
Expand Down
2 changes: 1 addition & 1 deletion driver/kubedriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestKubeRun(t *testing.T) {
metricsServerCalled = true

// check query parameters
assert.Equal(t, myName, req.URL.Query().Get("experiment"))
assert.Equal(t, myName, req.URL.Query().Get("test"))
assert.Equal(t, myNamespace, req.URL.Query().Get("namespace"))

// check payload
Expand Down
Loading

0 comments on commit f873bca

Please sign in to comment.