Skip to content

Commit a298915

Browse files
committed
Stream Envoy metrics to the cloud
Signed-off-by: Douglas Camata <[email protected]>
1 parent ed0775f commit a298915

File tree

6 files changed

+451
-120
lines changed

6 files changed

+451
-120
lines changed

api/agent/director.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ syntax = "proto3";
88
import "google/protobuf/duration.proto";
99
import "google/protobuf/timestamp.proto";
1010

11+
import "prometheus/metrics.proto";
12+
1113
package agent;
1214

1315
service Director {
@@ -20,6 +22,9 @@ service Director {
2022
// Report a consistent Snapshot of information to the CEPC.
2123
rpc ReportStream(stream RawSnapshotChunk) returns (SnapshotResponse) {}
2224

25+
// Stream metrics to the CEPC.
26+
rpc StreamMetrics(stream StreamMetricsMessage) returns (StreamMetricsResponse) {}
27+
2328
// Retrieve Directives from the CEPC
2429
rpc Retrieve(Identity) returns (stream Directive) {}
2530

@@ -105,3 +110,14 @@ message Command {
105110
// Log this message if present
106111
string message = 1;
107112
}
113+
114+
message StreamMetricsMessage {
115+
Identity identity = 1;
116+
117+
// A list of metric entries
118+
repeated io.prometheus.client.MetricFamily envoy_metrics = 2;
119+
}
120+
121+
message StreamMetricsResponse {
122+
123+
}

api/prometheus/metrics.proto

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright 2013 Prometheus Team
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
syntax = "proto2";
15+
16+
package io.prometheus.client;
17+
option java_package = "io.prometheus.client";
18+
option go_package = "github.com/prometheus/client_model/go;io_prometheus_client";
19+
20+
import "google/protobuf/timestamp.proto";
21+
22+
message LabelPair {
23+
optional string name = 1;
24+
optional string value = 2;
25+
}
26+
27+
enum MetricType {
28+
COUNTER = 0;
29+
GAUGE = 1;
30+
SUMMARY = 2;
31+
UNTYPED = 3;
32+
HISTOGRAM = 4;
33+
}
34+
35+
message Gauge {
36+
optional double value = 1;
37+
}
38+
39+
message Counter {
40+
optional double value = 1;
41+
optional Exemplar exemplar = 2;
42+
}
43+
44+
message Quantile {
45+
optional double quantile = 1;
46+
optional double value = 2;
47+
}
48+
49+
message Summary {
50+
optional uint64 sample_count = 1;
51+
optional double sample_sum = 2;
52+
repeated Quantile quantile = 3;
53+
}
54+
55+
message Untyped {
56+
optional double value = 1;
57+
}
58+
59+
message Histogram {
60+
optional uint64 sample_count = 1;
61+
optional double sample_sum = 2;
62+
repeated Bucket bucket = 3; // Ordered in increasing order of upper_bound, +Inf bucket is optional.
63+
}
64+
65+
message Bucket {
66+
optional uint64 cumulative_count = 1; // Cumulative in increasing order.
67+
optional double upper_bound = 2; // Inclusive.
68+
optional Exemplar exemplar = 3;
69+
}
70+
71+
message Exemplar {
72+
repeated LabelPair label = 1;
73+
optional double value = 2;
74+
optional google.protobuf.Timestamp timestamp = 3; // OpenMetrics-style.
75+
}
76+
77+
message Metric {
78+
repeated LabelPair label = 1;
79+
optional Gauge gauge = 2;
80+
optional Counter counter = 3;
81+
optional Summary summary = 4;
82+
optional Untyped untyped = 5;
83+
optional Histogram histogram = 7;
84+
optional int64 timestamp_ms = 6;
85+
}
86+
87+
message MetricFamily {
88+
optional string name = 1;
89+
optional string help = 2;
90+
optional MetricType type = 3;
91+
repeated Metric metric = 4;
92+
}

cmd/agent/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ func run(cmd *cobra.Command, args []string) error {
5050
snapshotURL = fmt.Sprintf(DefaultSnapshotURLFmt, entrypoint.ExternalSnapshotPort)
5151
}
5252

53+
metricsServer := agent.NewMetricsServer(ambAgent.MetricsRelayHandler)
54+
go func() {
55+
if err := metricsServer.StartServer(ctx); err != nil {
56+
dlog.Error(ctx, err)
57+
}
58+
}()
59+
5360
if err := ambAgent.Watch(ctx, snapshotURL); err != nil {
5461
return err
5562
}

pkg/agent/agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
envoyMetrics "github.com/datawire/ambassador/v2/pkg/api/envoy/service/metrics/v2"
7+
envoyMetrics "github.com/datawire/ambassador/v2/pkg/api/envoy/service/metrics/v3"
88
"io/ioutil"
99
"net/http"
1010
"net/url"
@@ -28,6 +28,7 @@ type Comm interface {
2828
Close() error
2929
Report(context.Context, *agent.Snapshot, string) error
3030
Directives() <-chan *agent.Directive
31+
StreamMetrics(context.Context, *agent.StreamMetricsMessage, string) error
3132
}
3233

3334
type atomicBool struct {

pkg/agent/envoy_metrics_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package agent
22

33
import (
44
"context"
5-
envoyMetrics "github.com/datawire/ambassador/v2/pkg/api/envoy/service/metrics/v2"
5+
envoyMetrics "github.com/datawire/ambassador/v2/pkg/api/envoy/service/metrics/v3"
66
"github.com/datawire/dlib/dlog"
77
"google.golang.org/grpc"
88
"io"
@@ -39,7 +39,7 @@ func (s *metricsServer) StartServer(ctx context.Context) error {
3939
}
4040

4141
// StreamMetrics implements the StreamMetrics rpc call by calling the stream handler on each
42-
// message received.
42+
// message received. It's invoked whenever metrics arrive from Envoy.
4343
func (s *metricsServer) StreamMetrics(stream envoyMetrics.MetricsService_StreamMetricsServer) error {
4444
ctx := stream.Context()
4545
dlog.Debug(ctx, "started stream")

0 commit comments

Comments
 (0)