/// <summary> /// Starts the exporter. /// </summary> public void Start() { lock (this.locker) { if (this.isInitialized) { return; } // Register stats(metrics) exporter if (this.viewManager != null) { var credential = this.GetGoogleCredential(); var statsConfig = StackdriverStatsConfiguration.Default; statsConfig.GoogleCredential = credential; if (statsConfig.ProjectId != this.projectId) { statsConfig.ProjectId = this.projectId; statsConfig.MonitoredResource = GoogleCloudResourceUtils.GetDefaultResource(this.projectId); } this.statsExporter = new StackdriverStatsExporter(this.viewManager, statsConfig); this.statsExporter.Start(); } this.isInitialized = true; } }
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(); }
/// <summary> /// Starts the exporter /// </summary> public void Start() { lock (locker) { if (isInitialized) { return; } // Register trace exporter if (exportComponent != null) { var traceExporter = new StackdriverTraceExporter(projectId); exportComponent.SpanExporter.RegisterHandler(ExporterName, traceExporter); } // Register stats(metrics) exporter if (viewManager != null) { var credential = GetGoogleCredential(); var statsConfig = StackdriverStatsConfiguration.Default; statsConfig.GoogleCredential = credential; if (statsConfig.ProjectId != projectId) { statsConfig.ProjectId = projectId; statsConfig.MonitoredResource = GoogleCloudResourceUtils.GetDefaultResource(projectId); } statsExporter = new StackdriverStatsExporter(viewManager, statsConfig); statsExporter.Start(); } isInitialized = true; } }
public void StatsConfiguration_ByDeafult_ProjectIdIsGoogleCloudProjectId() { Assert.NotNull(StackdriverStatsConfiguration.Default); Assert.Equal(GoogleCloudResourceUtils.GetProjectId(), StackdriverStatsConfiguration.Default.ProjectId); }
public void StatsConfiguration_ByDefault_MetricNamePrefixEmpty() { Assert.NotNull(StackdriverStatsConfiguration.Default); Assert.Equal(GoogleCloudResourceUtils.GetProjectId(), StackdriverStatsConfiguration.Default.ProjectId); Assert.Equal(string.Empty, StackdriverStatsConfiguration.Default.MetricNamePrefix); }
/// <summary> /// Initializes a new instance of the <see cref="StackdriverMetricsExporter"/> class with default monitored /// resource. /// </summary> /// <param name="projectId">Project ID to send telemetry to.</param> public StackdriverMetricsExporter(string projectId) : this(projectId, GoogleCloudResourceUtils.GetDefaultResource(projectId)) { }