Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit e751960

Browse files
Simon ZeltserSergeyKanzhelev
authored andcommitted
Basic working version of Stackdriver stats exporter (#63)
* Introducing Stackdriver Exporter for Opencensus C# library - Current implementation can only store string values - Added the exporter and trace handler only - The exporter relies on newest Trace API from Stackdriver. * Updating translation from ISpan to Stackdriver's Span to cover more fields * Fixing the issue that prevented Stackdriver API call to succeed: now construction of Span resource is taken care of by SpanName class that is part of Stackdriver Trace V2 API. * - Added support for capturing all types of trace spans (long/bool/string) - Fixed csproj, so it produces both .NET Core and .NET versions. It also means signing the assembly using the same mechanism as other assemblies in the solution * - Added support for storing links - Minor fixes to proto<->opencensus translation methods * Fixing merge issue * Added command line support for the Samples project. This will make it easier to script testing multiple exporters as well as prevent commenting and uncommenting different test procedures for different exporters. Finally, it will making test code cleaner for showing samples embedded in documentation website. In order to test the exporter, you can either execute it from the command line: samples.dll prometheus or to debug using Visual Studio: Debug => Sample Properties => Debug. Now create a profile for your testing execution and fill application arguments if needed. Now choose your profile in running configuration of Visual Studio. Running settings are local to the machine and are ignored in PRs. * Adding sceleton of metrics support in Stackdriver Exporter. Currently we can't detect all types of monitoring resources but we can ship the batches of metrics with time series to Stackdriver. Thorough testing TBD * Fixing a few bugs in Stackdriver metrics exporter - Small refactoring - Assinging default values for time intervals * - Fixing a few bugs around metric creation and labels - Refactoring MetricsConversions - Fixing stackdriver stats configuration - population of default resource and projects * First working version of Stackdriver Stats Exporter. 1) Fixed bugs related to Stackdriver Metrics Descriptor creation 2) Renamed Metrics Exporter to Stats Exporter to follow Opencensus terminology 3) Cache Stackdriver Metrics Descriptors locally so it's easy which descriptor holds the time series to upload 4) Fixed test code that was producing the metrics using Opencensus and uploading it to Stackdriver 5) Minor refactoring Current limitations: 1) Supporting only string labels 2) We support only "Global" monitored resource. We need to detect dynamically where the code is running and attach corresponding labels to the monitored resource, so metrics are stored correctly 3) More Tests * Removing commented lines
1 parent 125ca41 commit e751960

File tree

7 files changed

+253
-128
lines changed

7 files changed

+253
-128
lines changed

src/OpenCensus.Exporter.Stackdriver/Implementation/Constants.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@
1717
namespace OpenCensus.Exporter.Stackdriver.Implementation
1818
{
1919
using System;
20+
using System.Collections.Generic;
21+
using System.Collections.Specialized;
2022

2123
internal class Constants
2224
{
2325
public const string LABEL_DESCRIPTION = "OpenCensus TagKey";
2426
public const string OPENCENSUS_TASK = "opencensus_task";
2527
public const string OPENCENSUS_TASK_DESCRIPTION = "Opencensus task identifier";
28+
2629
public const string GCP_GKE_CONTAINER = "k8s_container";
2730
public const string GCP_GCE_INSTANCE = "gce_instance";
2831
public const string AWS_EC2_INSTANCE = "aws_ec2_instance";
2932
public const string GLOBAL = "global";
33+
3034
public const string PROJECT_ID_LABEL_KEY = "project_id";
3135
public static readonly string OPENCENSUS_TASK_VALUE_DEFAULT = generateDefaultTaskValue();
3236

src/OpenCensus.Exporter.Stackdriver/Implementation/MetricsUtils.cs renamed to src/OpenCensus.Exporter.Stackdriver/Implementation/GoogleCloudResourceUtils.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,27 @@
1717
namespace OpenCensus.Exporter.Stackdriver.Implementation
1818
{
1919
using Google.Api;
20+
using System.Collections.Generic;
2021

2122
/// <summary>
22-
/// Utility methods for metrics
23+
/// Utility methods for working with Google Cloud Resources
2324
/// </summary>
24-
public static class MetricsUtils
25+
public static class GoogleCloudResourceUtils
2526
{
27+
private static Dictionary<string, string> gcpResourceLabelMappings = new Dictionary<string, string>()
28+
{
29+
{ "project_id", Constants.PROJECT_ID_LABEL_KEY },
30+
{ "instance_id", Constants.GCP_GCE_INSTANCE },
31+
{ "zone", null }
32+
};
33+
34+
/// <summary>
35+
/// Detects Google Cloud ProjectId based on the environment on which the code runs.
36+
/// Supports GCE/GKE/GAE
37+
/// In case the code runs in a different environment,
38+
/// the method returns null
39+
/// </summary>
40+
/// <returns>Google Cloud Project ID</returns>
2641
public static string GetProjectId()
2742
{
2843
var instance = Google.Api.Gax.Platform.Instance();
@@ -37,29 +52,14 @@ public static string GetProjectId()
3752
/// <returns>Stackdriver Monitored Resource</returns>
3853
public static MonitoredResource GetDefaultResource(string projectId)
3954
{
40-
var builder = new MonitoredResource();
41-
builder.Type = Constants.GLOBAL;
42-
builder.Labels.Add(Constants.PROJECT_ID_LABEL_KEY, projectId);
55+
var resource = new MonitoredResource();
56+
resource.Type = Constants.GLOBAL;
57+
resource.Labels.Add(Constants.PROJECT_ID_LABEL_KEY, projectId);
4358

4459
// TODO - zeltser - setting monitored resource labels for detected resource
4560
// along with all the other metadata
4661

47-
return builder;
48-
}
49-
50-
public static string GetLabelKey(string label)
51-
{
52-
return label.Replace('/', '_');
53-
}
54-
55-
public static string GenerateTypeName(string viewName, string domain)
56-
{
57-
return domain + viewName;
58-
}
59-
60-
public static string GetDisplayName(string viewName, string displayNamePrefix)
61-
{
62-
return displayNamePrefix + viewName;
62+
return resource;
6363
}
6464
}
6565
}

0 commit comments

Comments
 (0)