private static void TestExportAsync( AggregationType aggregationType, MetricData metricData, MetricDescriptor.Types.MetricKind expectedMetricKind, TypedValue expectedTypedValue, IDictionary <string, string> expectedLabels = null) { MockStackdriverMetricsExporter.CallBase = true; var metric = new Metric("<metric-namespace>", MetricName, "<metric-description>", aggregationType); metric.Data.Add(metricData); var expectedMonitoredResource = GoogleCloudResourceUtils.GetDefaultResource(ProjectId); var expectedGoogleMetric = new Google.Api.Metric { Type = $"custom.googleapis.com/server/{MetricName}", }; if (expectedLabels != null) { expectedGoogleMetric.Labels.Add(expectedLabels); } var expectedTimeSeries = new TimeSeries { Metric = expectedGoogleMetric, Resource = expectedMonitoredResource, MetricKind = expectedMetricKind, }; var expectedTimeInterval = new TimeInterval { StartTime = expectedMetricKind == MetricDescriptor.Types.MetricKind.Cumulative ? Timestamp.FromDateTimeOffset(StartTimestamp) : null, EndTime = Timestamp.FromDateTimeOffset(EndTimestamp), }; MockStackdriverMetricsExporter .Setup(sm => sm.UploadToGoogleCloudMonitoring(expectedTimeSeries, expectedTypedValue, expectedTimeInterval)) .Verifiable(); MockStackdriverMetricsExporter.Object.ExportAsync(new List <Metric> { metric }, CancellationToken.None); MockStackdriverMetricsExporter.Verify(); }
private static void TestExportAsyncNoMetrics( AggregationType aggregationType, MetricData metricData) { MockStackdriverMetricsExporter.CallBase = true; var metric = new Metric("<metric-namespace>", "<metric-name>", "<metric-description>", aggregationType); metric.Data.Add(metricData); MockStackdriverMetricsExporter .Setup(cm => cm.UploadToGoogleCloudMonitoring(It.IsAny <TimeSeries>(), It.IsAny <TypedValue>(), It.IsAny <TimeInterval>())) .Throws(new Exception("UploadToGoogleCloudMonitoring should not be called.")); MockStackdriverMetricsExporter.Object.ExportAsync(new List <Metric> { metric }, CancellationToken.None); MockStackdriverMetricsExporter.Verify(); }
/// <inheritdoc/> public override void Process(Metric metric) { this.metrics.Add(metric); }
public override void Process(Metric metric) { }