Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 35b1e1c

Browse files
authored
Add metrics service gRPC gateway. Upgrade deps. (#608)
* Add metrics service gRPC gateway. Upgrade deps. Fixes #607 * Use a tag for ocagent exporter * Add a simple unit test for metrics grpc gateway
1 parent 97ea6d5 commit 35b1e1c

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/census-instrumentation/opencensus-service
33
require (
44
contrib.go.opencensus.io/exporter/aws v0.0.0-20181029163544-2befc13012d0
55
contrib.go.opencensus.io/exporter/jaeger v0.1.1-0.20190430175949-e8b55949d948
6-
contrib.go.opencensus.io/exporter/ocagent v0.5.0
6+
contrib.go.opencensus.io/exporter/ocagent v0.5.1
77
contrib.go.opencensus.io/exporter/prometheus v0.1.0
88
contrib.go.opencensus.io/exporter/stackdriver v0.12.3-0.20190626200219-09504ed717c7 // TODO: pin a released version
99
contrib.go.opencensus.io/exporter/zipkin v0.1.1
@@ -13,7 +13,7 @@ require (
1313
github.com/VividCortex/gohistogram v1.0.0 // indirect
1414
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7
1515
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b // indirect
16-
github.com/census-instrumentation/opencensus-proto v0.2.0
16+
github.com/census-instrumentation/opencensus-proto v0.2.1
1717
github.com/go-kit/kit v0.8.0
1818
github.com/gogo/googleapis v1.2.0 // indirect
1919
github.com/golang/protobuf v1.3.1

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ contrib.go.opencensus.io/exporter/aws v0.0.0-20181029163544-2befc13012d0 h1:YsbW
88
contrib.go.opencensus.io/exporter/aws v0.0.0-20181029163544-2befc13012d0/go.mod h1:uu1P0UCM/6RbsMrgPa98ll8ZcHM858i/AD06a9aLRCA=
99
contrib.go.opencensus.io/exporter/jaeger v0.1.1-0.20190430175949-e8b55949d948 h1:xdP25yLqNGSnpfDmEChwA9ZuKLdiyL0jqJKPm/Ypfag=
1010
contrib.go.opencensus.io/exporter/jaeger v0.1.1-0.20190430175949-e8b55949d948/go.mod h1:ukdzwIYYHgZ7QYtwVFQUjiT28BJHiMhTERo32s6qVgM=
11-
contrib.go.opencensus.io/exporter/ocagent v0.5.0 h1:TKXjQSRS0/cCDrP7KvkgU6SmILtF/yV2TOs/02K/WZQ=
12-
contrib.go.opencensus.io/exporter/ocagent v0.5.0/go.mod h1:ImxhfLRpxoYiSq891pBrLVhN+qmP8BTVvdH2YLs7Gl0=
11+
contrib.go.opencensus.io/exporter/ocagent v0.5.1 h1:TWb6QHJU0L63/AscynXhu5nS8fyw2uObyyYJ+YfEqPc=
12+
contrib.go.opencensus.io/exporter/ocagent v0.5.1/go.mod h1:oGSyf701BHqn69lMacwJJuyGzrk5eiCj86DxXhG2gfk=
1313
contrib.go.opencensus.io/exporter/prometheus v0.1.0 h1:SByaIoWwNgMdPSgl5sMqM2KDE5H/ukPWBRo314xiDvg=
1414
contrib.go.opencensus.io/exporter/prometheus v0.1.0/go.mod h1:cGFniUXGZlKRjzOyuZJ6mgB+PgBcCIa79kEKR8YCW+A=
1515
contrib.go.opencensus.io/exporter/stackdriver v0.12.3-0.20190626200219-09504ed717c7 h1:JLx6F8VdILk5M+2+xVZohpwN0TsC28F8WnJoPNNKogs=
@@ -65,6 +65,8 @@ github.com/cenk/backoff v2.0.0+incompatible/go.mod h1:7FtoeaSnHoZnmZzz47cM35Y9nS
6565
github.com/census-instrumentation/opencensus-proto v0.0.2/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
6666
github.com/census-instrumentation/opencensus-proto v0.2.0 h1:LzQXZOgg4CQfE6bFvXGM30YZL1WW/M337pXml+GrcZ4=
6767
github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
68+
github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=
69+
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
6870
github.com/certifi/gocertifi v0.0.0-20180905225744-ee1a9a0726d2/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4=
6971
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
7072
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=

receiver/opencensusreceiver/opencensus.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ func (ocr *Receiver) startServer() error {
260260
return
261261
}
262262

263+
err = agentmetricspb.RegisterMetricsServiceHandlerFromEndpoint(c, ocr.gatewayMux, endpoint, opts)
264+
if err != nil {
265+
errChan <- err
266+
return
267+
}
268+
263269
// Start the gRPC and HTTP/JSON (grpc-gateway) servers on the same port.
264270
m := cmux.New(ocr.ln)
265271
grpcL := m.MatchWithWriters(

receiver/opencensusreceiver/opencensus_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func TestGrpcGateway_endToEnd(t *testing.T) {
146146
}
147147
}
148148

149-
func TestGrpcGatewayCors_endToEnd(t *testing.T) {
149+
func TestTraceGrpcGatewayCors_endToEnd(t *testing.T) {
150150
addr := ":35991"
151151
corsOrigins := []string{"allowed-*.com"}
152152

@@ -175,6 +175,35 @@ func TestGrpcGatewayCors_endToEnd(t *testing.T) {
175175
verifyCorsResp(t, url, "disallowed-origin.com", 200, false)
176176
}
177177

178+
func TestMetricsGrpcGatewayCors_endToEnd(t *testing.T) {
179+
addr := ":35991"
180+
corsOrigins := []string{"allowed-*.com"}
181+
182+
sink := new(exportertest.SinkMetricsExporter)
183+
ocr, err := New(addr, nil, sink, WithCorsOrigins(corsOrigins))
184+
if err != nil {
185+
t.Fatalf("Failed to create metrics receiver: %v", err)
186+
}
187+
defer ocr.Stop()
188+
189+
go func() {
190+
if err := ocr.StartMetricsReception(context.Background(), nil); err != nil {
191+
t.Fatalf("Failed to start metrics receiver: %v", err)
192+
}
193+
}()
194+
195+
// Wait for the servers to start
196+
<-time.After(10 * time.Millisecond)
197+
198+
url := fmt.Sprintf("http://%s/v1/metrics", addr)
199+
200+
// Verify allowed domain gets responses that allow CORS.
201+
verifyCorsResp(t, url, "allowed-origin.com", 200, true)
202+
203+
// Verify disallowed domain gets responses that disallow CORS.
204+
verifyCorsResp(t, url, "disallowed-origin.com", 200, false)
205+
}
206+
178207
// As per Issue https://github.com/census-instrumentation/opencensus-service/issues/366
179208
// the agent's mux should be able to accept all Proto affiliated content-types and not
180209
// redirect them to the web-grpc-gateway endpoint.

0 commit comments

Comments
 (0)