From f0c771c01c1da5b76084f69f55dd485921eeea09 Mon Sep 17 00:00:00 2001 From: seph Date: Fri, 5 Apr 2019 15:14:21 -0400 Subject: [PATCH 1/3] Fix stats example (draft) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the stats example. Exporters don’t work. And I’m sure my comments are wrong. But it’s a start --- examples/stats/quickstart.rb | 40 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/examples/stats/quickstart.rb b/examples/stats/quickstart.rb index c91e90cd..1217b762 100644 --- a/examples/stats/quickstart.rb +++ b/examples/stats/quickstart.rb @@ -2,36 +2,56 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __dir__) require "opencensus" +require 'pp' MIB = 1 << 20 -fontend_key = "my.org/keys/frontend" -video_size_measure = OpenCensus::Stats.measure_int( +frontend_key = "my.org/keys/frontend" +video_size_measure = OpenCensus::Stats.create_measure_int( name: "my.org/measures/video_size", unit: "By", description: "size of processed videos" ) -video_size_distribution = OpenCensus::Stats.distribution_aggregation( +video_size_distribution = OpenCensus::Stats.create_distribution_aggregation( [0.0, 16.0 * MIB, 256.0 * MIB] ) -video_size_view = OpenCensus::Stats.create_view( +# You can either create, and then register the view. Or use +# create_and_register_view to register it to the global thingy. +video_size_view = OpenCensus::Stats::View.new( name: "my.org/views/video_size", measure: video_size_measure, aggregation: video_size_distribution, description: "processed video size over time", - columns: [fontend_key] + columns: [frontend_key] ) -stats_recorder = OpenCensus::Stats.recorder +stats_recorder = OpenCensus::Stats::Recorder.new() stats_recorder.register_view(video_size_view) -tag_map = OpenCensus::Tags::TagMap.new(fontend_key => "mobile-ios9.3.5") +# setup up our in-context tags, and record some measurements +tag_map_ios = OpenCensus::Tags::TagMap.new(frontend_key => "mobile-ios9.3.5") +stats_recorder.record( + video_size_measure.create_measurement(value: 10 * MIB, tags: tag_map_ios), + video_size_measure.create_measurement(value: 11 * MIB, tags: tag_map_ios), + video_size_measure.create_measurement(value: 12 * MIB, tags: tag_map_ios), + video_size_measure.create_measurement(value: 13 * MIB, tags: tag_map_ios), + video_size_measure.create_measurement(value: 14 * MIB, tags: tag_map_ios) +) +# Another context's data +tag_map_osx = OpenCensus::Tags::TagMap.new(frontend_key => "desktop-osx10.14.4") stats_recorder.record( - video_size_measure.measurement(25 * MIB), - tags: tag_map + video_size_measure.create_measurement(value: 20 * MIB, tags: tag_map_osx), + video_size_measure.create_measurement(value: 21 * MIB, tags: tag_map_osx), + video_size_measure.create_measurement(value: 22 * MIB, tags: tag_map_osx), + video_size_measure.create_measurement(value: 23 * MIB, tags: tag_map_osx), + video_size_measure.create_measurement(value: 24 * MIB, tags: tag_map_osx), ) view_data = stats_recorder.view_data video_size_view.name -p view_data.data +pp view_data.data + +# I can't figure out how to make the exporter work +log_exporter = OpenCensus::Stats::Exporters::Logger.new(Logger.new(STDOUT)) +log_exporter.export(view_data.data) From a825fe6b2985caa8ffc4e2c175aee23c25cf1074 Mon Sep 17 00:00:00 2001 From: seph Date: Fri, 5 Apr 2019 15:44:09 -0400 Subject: [PATCH 2/3] Get exporter working --- examples/stats/quickstart.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/stats/quickstart.rb b/examples/stats/quickstart.rb index 1217b762..00ce05a1 100644 --- a/examples/stats/quickstart.rb +++ b/examples/stats/quickstart.rb @@ -48,10 +48,6 @@ video_size_measure.create_measurement(value: 24 * MIB, tags: tag_map_osx), ) -view_data = stats_recorder.view_data video_size_view.name - -pp view_data.data - -# I can't figure out how to make the exporter work +# create an exporter and export data log_exporter = OpenCensus::Stats::Exporters::Logger.new(Logger.new(STDOUT)) -log_exporter.export(view_data.data) +log_exporter.export(stats_recorder.views_data) From 0911f4c5261beefd9d2c11af4b98ff8c426e33dd Mon Sep 17 00:00:00 2001 From: seph Date: Fri, 12 Apr 2019 10:05:46 -0700 Subject: [PATCH 3/3] Lint --- examples/stats/quickstart.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/stats/quickstart.rb b/examples/stats/quickstart.rb index 00ce05a1..93c07965 100644 --- a/examples/stats/quickstart.rb +++ b/examples/stats/quickstart.rb @@ -2,7 +2,6 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __dir__) require "opencensus" -require 'pp' MIB = 1 << 20 frontend_key = "my.org/keys/frontend" @@ -25,7 +24,7 @@ columns: [frontend_key] ) -stats_recorder = OpenCensus::Stats::Recorder.new() +stats_recorder = OpenCensus::Stats::Recorder.new stats_recorder.register_view(video_size_view) # setup up our in-context tags, and record some measurements @@ -45,7 +44,7 @@ video_size_measure.create_measurement(value: 21 * MIB, tags: tag_map_osx), video_size_measure.create_measurement(value: 22 * MIB, tags: tag_map_osx), video_size_measure.create_measurement(value: 23 * MIB, tags: tag_map_osx), - video_size_measure.create_measurement(value: 24 * MIB, tags: tag_map_osx), + video_size_measure.create_measurement(value: 24 * MIB, tags: tag_map_osx) ) # create an exporter and export data