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

Commit c169664

Browse files
authored
Remove AggregationWindow from the public API. (#37)
Most exporters can only handle Cumulative aggregation, and few users have need of Internal; this makes Cumulative the default and moves the ability to set Interval aggregation to a separate header in stats/internal. Pursuant to census-instrumentation/opencensus-specs#47.
1 parent ebd1dfd commit c169664

21 files changed

+175
-188
lines changed

opencensus/exporters/stats/e2e/stackdriver_e2e_test.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ TEST_F(StackdriverE2eTest, OneView) {
161161
prefix_))
162162
.set_measure(kTestMeasureName)
163163
.set_aggregation(::opencensus::stats::Aggregation::Sum())
164-
.set_aggregation_window(
165-
::opencensus::stats::AggregationWindow::Cumulative())
166164
.add_column("key1")
167165
.add_column("key2")
168166
.set_description(
@@ -199,8 +197,6 @@ TEST_F(StackdriverE2eTest, LargeTest) {
199197
prefix_))
200198
.set_measure(kTestMeasureName)
201199
.set_aggregation(::opencensus::stats::Aggregation::Count())
202-
.set_aggregation_window(
203-
::opencensus::stats::AggregationWindow::Cumulative())
204200
.add_column("key1")
205201
.add_column("key2")
206202
.set_description(
@@ -215,8 +211,6 @@ TEST_F(StackdriverE2eTest, LargeTest) {
215211
prefix_))
216212
.set_measure(kTestMeasureName)
217213
.set_aggregation(::opencensus::stats::Aggregation::Sum())
218-
.set_aggregation_window(
219-
::opencensus::stats::AggregationWindow::Cumulative())
220214
.add_column("key1")
221215
.add_column("key2")
222216
.set_description(

opencensus/exporters/stats/internal/stackdriver_utils_test.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ TEST(StackdriverUtilsTest, SetMetricDescriptorMetricKind) {
7777
auto view_descriptor = opencensus::stats::ViewDescriptor();
7878
google::api::MetricDescriptor metric_descriptor;
7979

80-
view_descriptor.set_aggregation_window(
81-
opencensus::stats::AggregationWindow::Cumulative());
8280
SetMetricDescriptor("", view_descriptor, &metric_descriptor);
8381
EXPECT_EQ(google::api::MetricDescriptor::CUMULATIVE,
8482
metric_descriptor.metric_kind());
@@ -157,8 +155,6 @@ TEST(StackdriverUtilsTest, MakeTimeSeriesSumDouble) {
157155
.set_name(view_name)
158156
.set_measure(measure.GetDescriptor().name())
159157
.set_aggregation(opencensus::stats::Aggregation::Sum())
160-
.set_aggregation_window(
161-
opencensus::stats::AggregationWindow::Cumulative())
162158
.add_column(tag_key_1)
163159
.add_column(tag_key_2);
164160
const opencensus::stats::ViewData data = TestUtils::MakeViewData(
@@ -199,8 +195,6 @@ TEST(StackdriverUtilsTest, MakeTimeSeriesSumInt) {
199195
.set_name(view_name)
200196
.set_measure(measure.GetDescriptor().name())
201197
.set_aggregation(opencensus::stats::Aggregation::Sum())
202-
.set_aggregation_window(
203-
opencensus::stats::AggregationWindow::Cumulative())
204198
.add_column(tag_key_1)
205199
.add_column(tag_key_2);
206200
const opencensus::stats::ViewData data = TestUtils::MakeViewData(
@@ -242,8 +236,6 @@ TEST(StackdriverUtilsTest, MakeTimeSeriesCountDouble) {
242236
.set_name(view_name)
243237
.set_measure(measure.GetDescriptor().name())
244238
.set_aggregation(opencensus::stats::Aggregation::Count())
245-
.set_aggregation_window(
246-
opencensus::stats::AggregationWindow::Cumulative())
247239
.add_column(tag_key_1)
248240
.add_column(tag_key_2);
249241
const opencensus::stats::ViewData data = TestUtils::MakeViewData(
@@ -289,8 +281,6 @@ TEST(StackdriverUtilsTest, MakeTimeSeriesDistributionDouble) {
289281
.set_measure(measure.GetDescriptor().name())
290282
.set_aggregation(
291283
opencensus::stats::Aggregation::Distribution(bucket_boundaries))
292-
.set_aggregation_window(
293-
opencensus::stats::AggregationWindow::Cumulative())
294284
.add_column(tag_key_1)
295285
.add_column(tag_key_2);
296286
const opencensus::stats::ViewData data = TestUtils::MakeViewData(

opencensus/plugins/internal/stats_plugin_end2end_test.cc

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,14 @@ TEST_F(StatsPluginEnd2EndTest, ErrorCount) {
8888
.set_measure(kRpcClientErrorCountMeasureName)
8989
.set_name("client_method")
9090
.set_aggregation(stats::Aggregation::Sum())
91-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
91+
9292
.add_column(kMethodTagKey);
9393
stats::View client_method_view(client_method_descriptor);
9494
const auto server_method_descriptor =
9595
stats::ViewDescriptor()
9696
.set_measure(kRpcServerErrorCountMeasureName)
9797
.set_name("server_method")
9898
.set_aggregation(stats::Aggregation::Sum())
99-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
10099
.add_column(kMethodTagKey);
101100
stats::View server_method_view(client_method_descriptor);
102101

@@ -105,15 +104,13 @@ TEST_F(StatsPluginEnd2EndTest, ErrorCount) {
105104
.set_measure(kRpcClientErrorCountMeasureName)
106105
.set_name("client_status")
107106
.set_aggregation(stats::Aggregation::Sum())
108-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
109107
.add_column(kStatusTagKey);
110108
stats::View client_status_view(client_status_descriptor);
111109
const auto server_status_descriptor =
112110
stats::ViewDescriptor()
113111
.set_measure(kRpcServerErrorCountMeasureName)
114112
.set_name("server_status")
115113
.set_aggregation(stats::Aggregation::Sum())
116-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
117114
.add_column(kStatusTagKey);
118115
stats::View server_status_view(server_status_descriptor);
119116

@@ -167,7 +164,6 @@ TEST_F(StatsPluginEnd2EndTest, RequestResponseBytes) {
167164
.set_name("client_request_bytes")
168165
.set_aggregation(stats::Aggregation::Distribution(
169166
stats::BucketBoundaries::Explicit({})))
170-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
171167
.add_column(kMethodTagKey);
172168
stats::View client_request_bytes_view(client_request_bytes_descriptor);
173169
const auto client_response_bytes_descriptor =
@@ -176,7 +172,6 @@ TEST_F(StatsPluginEnd2EndTest, RequestResponseBytes) {
176172
.set_name("client_response_bytes")
177173
.set_aggregation(stats::Aggregation::Distribution(
178174
stats::BucketBoundaries::Explicit({})))
179-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
180175
.add_column(kMethodTagKey);
181176
stats::View client_response_bytes_view(client_response_bytes_descriptor);
182177
const auto server_request_bytes_descriptor =
@@ -185,7 +180,6 @@ TEST_F(StatsPluginEnd2EndTest, RequestResponseBytes) {
185180
.set_name("server_request_bytes")
186181
.set_aggregation(stats::Aggregation::Distribution(
187182
stats::BucketBoundaries::Explicit({})))
188-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
189183
.add_column(kMethodTagKey);
190184
stats::View server_request_bytes_view(server_request_bytes_descriptor);
191185
const auto server_response_bytes_descriptor =
@@ -194,7 +188,6 @@ TEST_F(StatsPluginEnd2EndTest, RequestResponseBytes) {
194188
.set_name("server_response_bytes")
195189
.set_aggregation(stats::Aggregation::Distribution(
196190
stats::BucketBoundaries::Explicit({})))
197-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
198191
.add_column(kMethodTagKey);
199192
stats::View server_response_bytes_view(server_response_bytes_descriptor);
200193

@@ -254,7 +247,6 @@ TEST_F(StatsPluginEnd2EndTest, Latency) {
254247
.set_name("client_latency")
255248
.set_aggregation(stats::Aggregation::Distribution(
256249
stats::BucketBoundaries::Explicit({})))
257-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
258250
.add_column(kMethodTagKey);
259251
stats::View client_latency_view(client_latency_descriptor);
260252
const auto client_server_elapsed_time_descriptor =
@@ -263,7 +255,6 @@ TEST_F(StatsPluginEnd2EndTest, Latency) {
263255
.set_name("client_server_elapsed_time")
264256
.set_aggregation(stats::Aggregation::Distribution(
265257
stats::BucketBoundaries::Explicit({})))
266-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
267258
.add_column(kMethodTagKey);
268259
stats::View client_server_elapsed_time_view(
269260
client_server_elapsed_time_descriptor);
@@ -273,7 +264,6 @@ TEST_F(StatsPluginEnd2EndTest, Latency) {
273264
.set_name("server_server_elapsed_time")
274265
.set_aggregation(stats::Aggregation::Distribution(
275266
stats::BucketBoundaries::Explicit({})))
276-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
277267
.add_column(kMethodTagKey);
278268
stats::View server_server_elapsed_time_view(
279269
server_server_elapsed_time_descriptor);
@@ -332,31 +322,27 @@ TEST_F(StatsPluginEnd2EndTest, StartFinishCount) {
332322
.set_measure(kRpcClientStartedCountMeasureName)
333323
.set_name("client_started_count")
334324
.set_aggregation(stats::Aggregation::Sum())
335-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
336325
.add_column(kMethodTagKey);
337326
stats::View client_started_count_view(client_started_count_descriptor);
338327
const auto client_finished_count_descriptor =
339328
stats::ViewDescriptor()
340329
.set_measure(kRpcClientFinishedCountMeasureName)
341330
.set_name("client_finished_count")
342331
.set_aggregation(stats::Aggregation::Sum())
343-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
344332
.add_column(kMethodTagKey);
345333
stats::View client_finished_count_view(client_finished_count_descriptor);
346334
const auto server_started_count_descriptor =
347335
stats::ViewDescriptor()
348336
.set_measure(kRpcServerStartedCountMeasureName)
349337
.set_name("server_started_count")
350338
.set_aggregation(stats::Aggregation::Sum())
351-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
352339
.add_column(kMethodTagKey);
353340
stats::View server_started_count_view(server_started_count_descriptor);
354341
const auto server_finished_count_descriptor =
355342
stats::ViewDescriptor()
356343
.set_measure(kRpcServerFinishedCountMeasureName)
357344
.set_name("server_finished_count")
358345
.set_aggregation(stats::Aggregation::Sum())
359-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
360346
.add_column(kMethodTagKey);
361347
stats::View server_finished_count_view(server_finished_count_descriptor);
362348

@@ -394,31 +380,27 @@ TEST_F(StatsPluginEnd2EndTest, RequestResponseCount) {
394380
.set_measure(kRpcClientRequestCountMeasureName)
395381
.set_name("client_request_count")
396382
.set_aggregation(stats::Aggregation::Sum())
397-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
398383
.add_column(kMethodTagKey);
399384
stats::View client_request_count_view(client_request_count_descriptor);
400385
const auto client_response_count_descriptor =
401386
stats::ViewDescriptor()
402387
.set_measure(kRpcClientResponseCountMeasureName)
403388
.set_name("client_response_count")
404389
.set_aggregation(stats::Aggregation::Sum())
405-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
406390
.add_column(kMethodTagKey);
407391
stats::View client_response_count_view(client_response_count_descriptor);
408392
const auto server_request_count_descriptor =
409393
stats::ViewDescriptor()
410394
.set_measure(kRpcServerRequestCountMeasureName)
411395
.set_name("server_request_count")
412396
.set_aggregation(stats::Aggregation::Sum())
413-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
414397
.add_column(kMethodTagKey);
415398
stats::View server_request_count_view(server_request_count_descriptor);
416399
const auto server_response_count_descriptor =
417400
stats::ViewDescriptor()
418401
.set_measure(kRpcServerResponseCountMeasureName)
419402
.set_name("server_response_count")
420403
.set_aggregation(stats::Aggregation::Sum())
421-
.set_aggregation_window(stats::AggregationWindow::Cumulative())
422404
.add_column(kMethodTagKey);
423405
stats::View server_response_count_view(server_response_count_descriptor);
424406

opencensus/stats/BUILD

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ package(default_visibility = ["//visibility:private"])
2323
# The public stats API.
2424
cc_library(
2525
name = "stats",
26-
hdrs = ["stats.h"],
26+
hdrs = [
27+
"internal/set_aggregation_window.h",
28+
"stats.h",
29+
],
2730
copts = DEFAULT_COPTS,
2831
visibility = ["//visibility:public"],
2932
deps = [
@@ -59,17 +62,19 @@ cc_library(
5962
"internal/measure_descriptor.cc",
6063
"internal/measure_registry.cc",
6164
"internal/measure_registry_impl.cc",
65+
"internal/set_aggregation_window.cc",
6266
"internal/stats_manager.cc",
6367
"internal/view_data.cc",
6468
"internal/view_data_impl.cc",
6569
"internal/view_descriptor.cc",
6670
],
6771
hdrs = [
6872
"aggregation.h",
69-
"aggregation_window.h",
7073
"bucket_boundaries.h",
7174
"distribution.h",
75+
"internal/aggregation_window.h",
7276
"internal/measure_registry_impl.h",
77+
"internal/set_aggregation_window.h",
7378
"internal/stats_manager.h",
7479
"internal/view_data_impl.h",
7580
"measure.h",
@@ -80,15 +85,15 @@ cc_library(
8085
],
8186
copts = DEFAULT_COPTS,
8287
deps = [
88+
"//opencensus/common/internal:stats_object",
89+
"//opencensus/common/internal:string_vector_hash",
8390
"@com_google_absl//absl/base:core_headers",
8491
"@com_google_absl//absl/memory",
8592
"@com_google_absl//absl/strings",
8693
"@com_google_absl//absl/synchronization",
8794
"@com_google_absl//absl/time",
8895
"@com_google_absl//absl/types:optional",
8996
"@com_google_absl//absl/types:span",
90-
"//opencensus/common/internal:stats_object",
91-
"//opencensus/common/internal:string_vector_hash",
9297
],
9398
)
9499

opencensus/stats/examples/exporter_example.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,30 @@ TEST_F(ExporterExample, Distribution) {
7777
SetupFoo();
7878

7979
// The stats consumer creates a View on Foo Usage.
80-
const auto cumulative_descriptor =
80+
const auto sum_descriptor =
8181
opencensus::stats::ViewDescriptor()
8282
.set_name("example.com/Bar/FooUsage-sum-cumulative-foo_id")
8383
.set_measure(kFooUsageMeasureName)
8484
.set_aggregation(opencensus::stats::Aggregation::Sum())
85-
.set_aggregation_window(
86-
opencensus::stats::AggregationWindow::Cumulative())
8785
.add_column("foo_id")
8886
.set_description(
8987
"Cumulative sum of example.com/Foo/FooUsage broken down "
9088
"by 'foo_id'.");
91-
const auto interval_descriptor =
89+
const auto count_descriptor =
9290
opencensus::stats::ViewDescriptor()
9391
.set_name("example.com/Bar/FooUsage-sum-interval-foo_id")
9492
.set_measure(kFooUsageMeasureName)
95-
.set_aggregation(opencensus::stats::Aggregation::Sum())
96-
.set_aggregation_window(
97-
opencensus::stats::AggregationWindow::Interval(absl::Hours(1)))
93+
.set_aggregation(opencensus::stats::Aggregation::Count())
9894
.add_column("foo_id")
9995
.set_description(
100-
"Rolling sum of example.com/Foo/FooUsage over the previous hour "
101-
"broken down by 'foo_id'.");
96+
"Cumulative count of example.com/Foo/FooUsage broken down by "
97+
"'foo_id'.");
10298

10399
// The order of view registration and exporter creation does not matter, as
104100
// long as both precede data recording.
105-
opencensus::stats::StatsExporter::AddView(cumulative_descriptor);
101+
opencensus::stats::StatsExporter::AddView(sum_descriptor);
106102
ExampleExporter::Register();
107-
opencensus::stats::StatsExporter::AddView(interval_descriptor);
103+
opencensus::stats::StatsExporter::AddView(count_descriptor);
108104

109105
// Someone calls the Foo API, recording usage under example.com/Bar/FooUsage.
110106
UseFoo("foo1", 1);

opencensus/stats/examples/view_and_recording_example.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ TEST(ViewAndRecordingExample, Sum) {
6363
.set_name("example.com/Bar/FooUsage-sum-cumulative-foo_id")
6464
.set_measure(kFooUsageMeasureName)
6565
.set_aggregation(opencensus::stats::Aggregation::Sum())
66-
.set_aggregation_window(
67-
opencensus::stats::AggregationWindow::Cumulative())
6866
.add_column("foo_id")
6967
.set_description(
7068
"Cumulative sum of example.com/Foo/FooUsage broken down by "

opencensus/stats/internal/aggregation_window.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "opencensus/stats/aggregation_window.h"
15+
#include "opencensus/stats/internal/aggregation_window.h"
1616

1717
#include "absl/strings/str_cat.h"
1818

opencensus/stats/aggregation_window.h renamed to opencensus/stats/internal/aggregation_window.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017, OpenCensus Authors
1+
// Copyright 2018, OpenCensus Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef OPENCENSUS_STATS_AGGREGATION_WINDOW_H_
16-
#define OPENCENSUS_STATS_AGGREGATION_WINDOW_H_
15+
#ifndef OPENCENSUS_STATS_INTERNAL_AGGREGATION_WINDOW_H_
16+
#define OPENCENSUS_STATS_INTERNAL_AGGREGATION_WINDOW_H_
1717

1818
#include <string>
1919

@@ -68,4 +68,4 @@ class AggregationWindow final {
6868
} // namespace stats
6969
} // namespace opencensus
7070

71-
#endif // OPENCENSUS_STATS_AGGREGATION_WINDOW_H_
71+
#endif // OPENCENSUS_STATS_INTERNAL_AGGREGATION_WINDOW_H_

opencensus/stats/internal/debug_string_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include "gmock/gmock.h"
1717
#include "gtest/gtest.h"
1818
#include "opencensus/stats/aggregation.h"
19-
#include "opencensus/stats/aggregation_window.h"
2019
#include "opencensus/stats/bucket_boundaries.h"
20+
#include "opencensus/stats/internal/aggregation_window.h"
2121
#include "opencensus/stats/measure_descriptor.h"
2222
#include "opencensus/stats/measure_registry.h"
2323
#include "opencensus/stats/view_descriptor.h"
@@ -64,9 +64,9 @@ TEST(DebugStringTest, ViewDescriptor) {
6464
ViewDescriptor descriptor = ViewDescriptor()
6565
.set_measure(measure_name)
6666
.set_aggregation(aggregation)
67-
.set_aggregation_window(aggregation_window)
6867
.add_column(tag_key)
6968
.set_description(description);
69+
SetAggregationWindow(aggregation_window, &descriptor);
7070

7171
EXPECT_PRED_FORMAT2(::testing::IsSubstring,
7272
measure.GetDescriptor().DebugString(),

0 commit comments

Comments
 (0)