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 TimeSeries GenerateNewTimeSeries( string metricName, IEnumerable <KeyValuePair <string, string> > labelSet, MetricDescriptor.Types.MetricKind metricKind) { var googleMetric = new Google.Api.Metric { Type = $"custom.googleapis.com/server/{metricName}", }; if (labelSet != null) { googleMetric.Labels.Add( labelSet.ToDictionary(x => x.Key, x => x.Value)); } return(new TimeSeries { Metric = googleMetric, Resource = this.monitoredResource, MetricKind = metricKind, }); }