-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4207 from emissary-ingress/alicewasko/metrics-syn…
…c-for-2.3 Metrics sync for 2.3
- Loading branch information
Showing
8 changed files
with
225 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package agent | ||
|
||
import ( | ||
"github.com/datawire/ambassador/v2/pkg/api/agent" | ||
envoyMetrics "github.com/datawire/ambassador/v2/pkg/api/envoy/service/metrics/v3" | ||
"github.com/datawire/dlib/dlog" | ||
io_prometheus_client "github.com/prometheus/client_model/go" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
"time" | ||
) | ||
|
||
var ( | ||
counterType = io_prometheus_client.MetricType_COUNTER | ||
acceptedMetric = &io_prometheus_client.MetricFamily{ | ||
Name: StrToPointer("cluster.apple_prod_443.upstream_rq_total"), | ||
Type: &counterType, | ||
Metric: []*io_prometheus_client.Metric{ | ||
{ | ||
Counter: &io_prometheus_client.Counter{ | ||
Value: Float64ToPointer(42), | ||
}, | ||
TimestampMs: Int64ToPointer(time.Now().Unix() * 1000), | ||
}, | ||
}, | ||
} | ||
ignoredMetric = &io_prometheus_client.MetricFamily{ | ||
Name: StrToPointer("cluster.apple_prod_443.metric_to_ignore"), | ||
Type: &counterType, | ||
Metric: []*io_prometheus_client.Metric{ | ||
{ | ||
Counter: &io_prometheus_client.Counter{ | ||
Value: Float64ToPointer(42), | ||
}, | ||
TimestampMs: Int64ToPointer(time.Now().Unix() * 1000), | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
func agentMetricsSetupTest() (*MockClient, *Agent) { | ||
clientMock := &MockClient{} | ||
|
||
stubbedAgent := &Agent{ | ||
metricsBackoffUntil: time.Time{}, | ||
comm: &RPCComm{ | ||
client: clientMock, | ||
}, | ||
} | ||
|
||
return clientMock, stubbedAgent | ||
} | ||
|
||
func TestMetricsRelayHandler(t *testing.T) { | ||
|
||
t.Run("will relay the metrics", func(t *testing.T) { | ||
//given | ||
clientMock, stubbedAgent := agentMetricsSetupTest() | ||
ctx := dlog.NewTestContext(t, true) | ||
|
||
//when | ||
stubbedAgent.MetricsRelayHandler(ctx, &envoyMetrics.StreamMetricsMessage{ | ||
Identifier: nil, | ||
EnvoyMetrics: []*io_prometheus_client.MetricFamily{ignoredMetric, acceptedMetric}, | ||
}) | ||
|
||
//then | ||
assert.Equal(t, []*agent.StreamMetricsMessage{{ | ||
EnvoyMetrics: []*io_prometheus_client.MetricFamily{acceptedMetric}, | ||
}}, clientMock.SentMetrics) | ||
}) | ||
t.Run("will not relay the metrics since it is in cool down period.", func(t *testing.T) { | ||
//given | ||
clientMock, stubbedAgent := agentMetricsSetupTest() | ||
ctx := dlog.NewTestContext(t, true) | ||
stubbedAgent.metricsBackoffUntil = time.Now().Add(defaultMinReportPeriod) | ||
|
||
//when | ||
stubbedAgent.MetricsRelayHandler(ctx, &envoyMetrics.StreamMetricsMessage{ | ||
Identifier: nil, | ||
EnvoyMetrics: []*io_prometheus_client.MetricFamily{acceptedMetric}, | ||
}) | ||
|
||
//then | ||
assert.Equal(t, 0, len(clientMock.SentMetrics)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package agent | ||
|
||
// StrToPointer will return the pointer to the given string. | ||
func StrToPointer(str string) *string { | ||
return &str | ||
} | ||
|
||
// Float64ToPointer will return the pointer to the given float. | ||
func Float64ToPointer(f float64) *float64 { | ||
return &f | ||
} | ||
|
||
// Int64ToPointer will return the pointer to the given int64. | ||
func Int64ToPointer(i int64) *int64 { | ||
return &i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters