Skip to content

Commit

Permalink
orca: add application utilization and range checking (#6357)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley authored Jun 7, 2023
1 parent 6578ef7 commit 7aeea8f
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 76 deletions.
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module google.golang.org/grpc/examples
go 1.17

require (
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4
github.com/golang/protobuf v1.5.3
golang.org/x/oauth2 v0.7.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19
Expand Down
4 changes: 2 additions & 2 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195 h1:58f1tJ1ra+zFINPlwLWvQsR9CzAKt2e+EWV2yX9oXQ4=
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion gcp/observability/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.17
require (
github.com/cespare/xxhash/v2 v2.2.0
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4
github.com/envoyproxy/go-control-plane v0.11.1-0.20230524094728-9239064ad72f
github.com/golang/glog v1.1.0
github.com/golang/protobuf v1.5.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe h1:QQ3GSy+MqSHxm/d8nCtnAiZdYFd45cYZPs8vOOIYKfk=
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195 h1:58f1tJ1ra+zFINPlwLWvQsR9CzAKt2e+EWV2yX9oXQ4=
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.11.1-0.20230524094728-9239064ad72f h1:7T++XKzy4xg7PKy+bM+Sa9/oe1OC88yz2hXQUISoXfA=
Expand Down
2 changes: 1 addition & 1 deletion interop/observability/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
contrib.go.opencensus.io/exporter/stackdriver v0.13.12 // indirect
github.com/aws/aws-sdk-go v1.44.162 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195 // indirect
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 // indirect
github.com/envoyproxy/protoc-gen-validate v0.10.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions interop/observability/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,8 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195 h1:58f1tJ1ra+zFINPlwLWvQsR9CzAKt2e+EWV2yX9oXQ4=
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+gqO04wryn5h75LSazbRlnya1k=
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
32 changes: 10 additions & 22 deletions orca/call_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ import (
"errors"
"io"
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/internal/pretty"
"google.golang.org/grpc/internal/stubserver"
"google.golang.org/grpc/metadata"
Expand All @@ -41,16 +39,6 @@ import (
testpb "google.golang.org/grpc/interop/grpc_testing"
)

type s struct {
grpctest.Tester
}

func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

const defaultTestTimeout = 5 * time.Second

// TestE2ECallMetricsUnary tests the injection of custom backend metrics from
// the server application for a unary RPC, and verifies that expected load
// reports are received at the client.
Expand All @@ -65,9 +53,9 @@ func (s) TestE2ECallMetricsUnary(t *testing.T) {
injectMetrics: true,
wantProto: &v3orcapb.OrcaLoadReport{
CpuUtilization: 1.0,
MemUtilization: 50.0,
MemUtilization: 0.9,
RequestCost: map[string]float64{"queryCost": 25.0},
Utilization: map[string]float64{"queueSize": 75.0},
Utilization: map[string]float64{"queueSize": 0.75},
},
},
{
Expand All @@ -92,7 +80,7 @@ func (s) TestE2ECallMetricsUnary(t *testing.T) {
t.Error(err)
return nil, err
}
recorder.SetMemoryUtilization(50.0)
recorder.SetMemoryUtilization(0.9)
// This value will be overwritten by a write to the same metric
// from the server handler.
recorder.SetNamedUtilization("queueSize", 1.0)
Expand All @@ -114,7 +102,7 @@ func (s) TestE2ECallMetricsUnary(t *testing.T) {
return nil, err
}
recorder.SetRequestCost("queryCost", 25.0)
recorder.SetNamedUtilization("queueSize", 75.0)
recorder.SetNamedUtilization("queueSize", 0.75)
return &testpb.Empty{}, nil
},
}
Expand Down Expand Up @@ -171,9 +159,9 @@ func (s) TestE2ECallMetricsStreaming(t *testing.T) {
injectMetrics: true,
wantProto: &v3orcapb.OrcaLoadReport{
CpuUtilization: 1.0,
MemUtilization: 50.0,
RequestCost: map[string]float64{"queryCost": 25.0},
Utilization: map[string]float64{"queueSize": 75.0},
MemUtilization: 0.5,
RequestCost: map[string]float64{"queryCost": 0.25},
Utilization: map[string]float64{"queueSize": 0.75},
},
},
{
Expand All @@ -198,7 +186,7 @@ func (s) TestE2ECallMetricsStreaming(t *testing.T) {
t.Error(err)
return err
}
recorder.SetMemoryUtilization(50.0)
recorder.SetMemoryUtilization(0.5)
// This value will be overwritten by a write to the same metric
// from the server handler.
recorder.SetNamedUtilization("queueSize", 1.0)
Expand All @@ -217,8 +205,8 @@ func (s) TestE2ECallMetricsStreaming(t *testing.T) {
t.Error(err)
return err
}
recorder.SetRequestCost("queryCost", 25.0)
recorder.SetNamedUtilization("queueSize", 75.0)
recorder.SetRequestCost("queryCost", 0.25)
recorder.SetNamedUtilization("queueSize", 0.75)
}

// Streaming implementation replies with a dummy response until the
Expand Down
14 changes: 13 additions & 1 deletion orca/orca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,29 @@ package orca_test

import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/internal/pretty"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/orca/internal"

v3orcapb "github.com/cncf/xds/go/xds/data/orca/v3"
)

func TestToLoadReport(t *testing.T) {
type s struct {
grpctest.Tester
}

func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

const defaultTestTimeout = 5 * time.Second

func (s) TestToLoadReport(t *testing.T) {
goodReport := &v3orcapb.OrcaLoadReport{
CpuUtilization: 1.0,
MemUtilization: 50.0,
Expand Down
28 changes: 14 additions & 14 deletions orca/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ func (s) TestProducer(t *testing.T) {

// Set a few metrics and wait for them on the client side.
smr.SetCPUUtilization(10)
smr.SetMemoryUtilization(100)
smr.SetNamedUtilization("bob", 555)
smr.SetMemoryUtilization(0.1)
smr.SetNamedUtilization("bob", 0.555)
loadReportWant := &v3orcapb.OrcaLoadReport{
CpuUtilization: 10,
MemUtilization: 100,
Utilization: map[string]float64{"bob": 555},
MemUtilization: 0.1,
Utilization: map[string]float64{"bob": 0.555},
}

testReport:
Expand All @@ -181,13 +181,13 @@ testReport:
}

// Change and add metrics and wait for them on the client side.
smr.SetCPUUtilization(50)
smr.SetMemoryUtilization(200)
smr.SetNamedUtilization("mary", 321)
smr.SetCPUUtilization(0.5)
smr.SetMemoryUtilization(0.2)
smr.SetNamedUtilization("mary", 0.321)
loadReportWant = &v3orcapb.OrcaLoadReport{
CpuUtilization: 50,
MemUtilization: 200,
Utilization: map[string]float64{"bob": 555, "mary": 321},
CpuUtilization: 0.5,
MemUtilization: 0.2,
Utilization: map[string]float64{"bob": 0.555, "mary": 0.321},
}

for {
Expand Down Expand Up @@ -322,8 +322,8 @@ func (s) TestProducerBackoff(t *testing.T) {
// Define a load report to send and expect the client to see.
loadReportWant := &v3orcapb.OrcaLoadReport{
CpuUtilization: 10,
MemUtilization: 100,
Utilization: map[string]float64{"bob": 555},
MemUtilization: 0.1,
Utilization: map[string]float64{"bob": 0.555},
}

// Unblock the fake.
Expand Down Expand Up @@ -444,8 +444,8 @@ func (s) TestProducerMultipleListeners(t *testing.T) {
// Define a load report to send and expect the client to see.
loadReportWant := &v3orcapb.OrcaLoadReport{
CpuUtilization: 10,
MemUtilization: 100,
Utilization: map[string]float64{"bob": 555},
MemUtilization: 0.1,
Utilization: map[string]float64{"bob": 0.555},
}

// Receive reports and update counts for the three listeners.
Expand Down
Loading

0 comments on commit 7aeea8f

Please sign in to comment.