This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reproduce bug in stackdriver exporter. (#199)
* Reproduce bug in stackdriver exporter. * Update test. * Fix more tests, remove unnecessary time helper
- Loading branch information
1 parent
b5c7a2c
commit 2fdcf7b
Showing
6 changed files
with
202 additions
and
23 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
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 |
---|---|---|
|
@@ -22,18 +22,186 @@ import ( | |
|
||
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1" | ||
"github.com/golang/protobuf/ptypes/timestamp" | ||
"google.golang.org/api/option" | ||
distributionpb "google.golang.org/genproto/googleapis/api/distribution" | ||
labelpb "google.golang.org/genproto/googleapis/api/label" | ||
googlemetricpb "google.golang.org/genproto/googleapis/api/metric" | ||
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres" | ||
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3" | ||
"google.golang.org/grpc" | ||
|
||
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1" | ||
"github.com/golang/protobuf/ptypes/wrappers" | ||
"github.com/google/go-cmp/cmp" | ||
"go.opencensus.io/resource/resourcekeys" | ||
) | ||
|
||
func TestExportTimeSeriesWithDifferentLabels(t *testing.T) { | ||
server, addr, doneFn := createFakeServer(t) | ||
defer doneFn() | ||
|
||
// Now create a gRPC connection to the agent. | ||
conn, err := grpc.Dial(addr, grpc.WithInsecure()) | ||
if err != nil { | ||
t.Fatalf("Failed to make a gRPC connection to the agent: %v", err) | ||
} | ||
defer conn.Close() | ||
|
||
// Finally create the OpenCensus stats exporter | ||
exporterOptions := Options{ | ||
ProjectID: "equivalence", | ||
MonitoringClientOptions: []option.ClientOption{option.WithGRPCConn(conn)}, | ||
|
||
// Set empty labels to avoid the opencensus-task | ||
DefaultMonitoringLabels: &Labels{}, | ||
} | ||
se, err := NewExporter(exporterOptions) | ||
if err != nil { | ||
t.Fatalf("Failed to create the statsExporter: %v", err) | ||
} | ||
|
||
startTimestamp := ×tamp.Timestamp{ | ||
Seconds: 1543160298, | ||
Nanos: 100000090, | ||
} | ||
endTimestamp := ×tamp.Timestamp{ | ||
Seconds: 1543160298, | ||
Nanos: 100000997, | ||
} | ||
|
||
// Generate the proto Metrics. | ||
var metricPbs []*metricspb.Metric | ||
metricPbs = append(metricPbs, | ||
&metricspb.Metric{ | ||
MetricDescriptor: &metricspb.MetricDescriptor{ | ||
Name: "ocagent.io/calls", | ||
Description: "The number of the various calls", | ||
LabelKeys: []*metricspb.LabelKey{ | ||
{ | ||
Key: "empty_key", | ||
}, | ||
{ | ||
Key: "operation_type", | ||
}, | ||
}, | ||
Unit: "1", | ||
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64, | ||
}, | ||
Timeseries: []*metricspb.TimeSeries{ | ||
{ | ||
StartTimestamp: startTimestamp, | ||
LabelValues: []*metricspb.LabelValue{ | ||
{ | ||
Value: "", | ||
HasValue: true, | ||
}, | ||
{ | ||
Value: "test_1", | ||
HasValue: true, | ||
}, | ||
}, | ||
Points: []*metricspb.Point{ | ||
{ | ||
Timestamp: endTimestamp, | ||
Value: &metricspb.Point_Int64Value{Int64Value: int64(1)}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
StartTimestamp: startTimestamp, | ||
LabelValues: []*metricspb.LabelValue{ | ||
{ | ||
Value: "", | ||
HasValue: true, | ||
}, | ||
{ | ||
Value: "test_2", | ||
HasValue: true, | ||
}, | ||
}, | ||
Points: []*metricspb.Point{ | ||
{ | ||
Timestamp: endTimestamp, | ||
Value: &metricspb.Point_Int64Value{Int64Value: int64(1)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
var wantTimeSeries []*monitoringpb.CreateTimeSeriesRequest | ||
wantTimeSeries = append(wantTimeSeries, &monitoringpb.CreateTimeSeriesRequest{ | ||
Name: "projects/equivalence", | ||
TimeSeries: []*monitoringpb.TimeSeries{ | ||
{ | ||
Metric: &googlemetricpb.Metric{ | ||
Type: "custom.googleapis.com/opencensus/ocagent.io/calls", | ||
Labels: map[string]string{ | ||
"empty_key": "", | ||
"operation_type": "test_1", | ||
}, | ||
}, | ||
Resource: &monitoredrespb.MonitoredResource{ | ||
Type: "global", | ||
}, | ||
MetricKind: googlemetricpb.MetricDescriptor_CUMULATIVE, | ||
ValueType: googlemetricpb.MetricDescriptor_INT64, | ||
Points: []*monitoringpb.Point{ | ||
{ | ||
Interval: &monitoringpb.TimeInterval{ | ||
StartTime: startTimestamp, | ||
EndTime: endTimestamp, | ||
}, | ||
Value: &monitoringpb.TypedValue{ | ||
Value: &monitoringpb.TypedValue_Int64Value{ | ||
Int64Value: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Metric: &googlemetricpb.Metric{ | ||
Type: "custom.googleapis.com/opencensus/ocagent.io/calls", | ||
Labels: map[string]string{ | ||
"empty_key": "", | ||
"operation_type": "test_2", | ||
}, | ||
}, | ||
Resource: &monitoredrespb.MonitoredResource{ | ||
Type: "global", | ||
}, | ||
MetricKind: googlemetricpb.MetricDescriptor_CUMULATIVE, | ||
ValueType: googlemetricpb.MetricDescriptor_INT64, | ||
Points: []*monitoringpb.Point{ | ||
{ | ||
Interval: &monitoringpb.TimeInterval{ | ||
StartTime: startTimestamp, | ||
EndTime: endTimestamp, | ||
}, | ||
Value: &monitoringpb.TypedValue{ | ||
Value: &monitoringpb.TypedValue_Int64Value{ | ||
Int64Value: 1, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, //<metric:<type:"custom.googleapis.com/opencensus/ocagent.io/calls" labels:<key:"opencensus_task" value:"[email protected]" > > resource:<type:"global" > metric_kind:CUMULATIVE value_type:INT64 points:<interval:<end_time:<seconds:1001 > start_time:<seconds:1000 > > value:<int64_value:8 > > > time_series:<metric:<type:"custom.googleapis.com/opencensus/ocagent.io/calls" labels:<key:"opencensus_task" value:"[email protected]" > > resource:<type:"global" > metric_kind:CUMULATIVE value_type:INT64 points:<interval:<end_time:<seconds:1001 > start_time:<seconds:1000 > > value:<int64_value:8 > > > `, | ||
}) | ||
|
||
// Export the proto Metrics to the Stackdriver backend. | ||
se.PushMetricsProto(context.Background(), nil, nil, metricPbs) | ||
se.Flush() | ||
|
||
var gotTimeSeries []*monitoringpb.CreateTimeSeriesRequest | ||
server.forEachStackdriverTimeSeries(func(sdt *monitoringpb.CreateTimeSeriesRequest) { | ||
gotTimeSeries = append(gotTimeSeries, sdt) | ||
}) | ||
|
||
requireTimeSeriesRequestEqual(t, gotTimeSeries, wantTimeSeries) | ||
} | ||
|
||
func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) { | ||
startTimestamp := ×tamp.Timestamp{ | ||
Seconds: 1543160298, | ||
|
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