-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add delay in the agent between each metrics push
Signed-off-by: Kévin Lambert <kevin.lambert.ca@gmail.com>
- Loading branch information
Showing
9 changed files
with
555 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package agent | ||
|
||
import ( | ||
"context" | ||
"github.com/datawire/ambassador/v2/pkg/api/agent" | ||
envoyMetrics "github.com/datawire/ambassador/v2/pkg/api/envoy/service/metrics/v3" | ||
io_prometheus_client "github.com/prometheus/client_model/go" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
"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), | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
type AgentMetricsSuite struct { | ||
suite.Suite | ||
|
||
clientMock *MockClient | ||
|
||
stubbedAgent *Agent | ||
} | ||
|
||
func (s *AgentMetricsSuite) SetupTest() { | ||
s.clientMock = &MockClient{} | ||
|
||
s.stubbedAgent = &Agent{ | ||
metricsRelayDeadline: time.Time{}, | ||
comm: &RPCComm{ | ||
client: s.clientMock, | ||
}, | ||
} | ||
} | ||
|
||
func (s *AgentMetricsSuite) AfterTest(suiteName, testName string) { | ||
return | ||
} | ||
|
||
func (s *AgentMetricsSuite) TestMetricsHandlerWithRelay() { | ||
//given | ||
ctx := context.TODO() | ||
|
||
//when | ||
s.stubbedAgent.MetricsRelayHandler(ctx, &envoyMetrics.StreamMetricsMessage{ | ||
Identifier: nil, | ||
EnvoyMetrics: []*io_prometheus_client.MetricFamily{ignoredMetric, acceptedMetric}, | ||
}) | ||
|
||
//then | ||
assert.Equal(s.T(), []*agent.StreamMetricsMessage{{ | ||
EnvoyMetrics: []*io_prometheus_client.MetricFamily{acceptedMetric}, | ||
}}, s.clientMock.SentMetrics) | ||
} | ||
|
||
func (s *AgentMetricsSuite) TestMetricsHandlerWithRelayPass() { | ||
//given | ||
ctx := context.TODO() | ||
s.stubbedAgent.metricsRelayDeadline = time.Now().Add(defaultMinReportPeriod) | ||
|
||
//when | ||
s.stubbedAgent.MetricsRelayHandler(ctx, &envoyMetrics.StreamMetricsMessage{ | ||
Identifier: nil, | ||
EnvoyMetrics: []*io_prometheus_client.MetricFamily{acceptedMetric}, | ||
}) | ||
|
||
//then | ||
assert.Equal(s.T(), 0, len(s.clientMock.SentMetrics)) | ||
} | ||
|
||
func TestSuiteAgentMetrics(t *testing.T) { | ||
suite.Run(t, new(AgentMetricsSuite)) | ||
} |
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.