From 4e62aac18595243b9ed4c98137c24e7413c1dc48 Mon Sep 17 00:00:00 2001 From: Yang Song Date: Fri, 27 Apr 2018 14:27:58 -0700 Subject: Rename StatsRunner to TagContextExample because it's more about TagContext. (#1156) --- examples/BUILD.bazel | 4 +- examples/README.md | 8 +-- examples/build.gradle | 8 +-- examples/pom.xml | 4 +- .../io/opencensus/examples/stats/StatsRunner.java | 77 ---------------------- .../examples/tags/TagContextExample.java | 77 ++++++++++++++++++++++ 6 files changed, 89 insertions(+), 89 deletions(-) delete mode 100644 examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java create mode 100644 examples/src/main/java/io/opencensus/examples/tags/TagContextExample.java (limited to 'examples') diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index c2d36520..ebda34b7 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -92,8 +92,8 @@ java_library( ) java_binary( - name = "StatsRunner", - main_class = "io.opencensus.examples.stats.StatsRunner", + name = "TagContextExample", + main_class = "io.opencensus.examples.tags.TagContextExample", runtime_deps = [ ":opencensus_examples", ], diff --git a/examples/README.md b/examples/README.md index 5b0a7ce6..921691b7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -17,21 +17,21 @@ $ mvn package appassembler:assemble $ bazel build :all ``` -## To run "StatsRunner" example use +## To run "TagContextExample" use ### Gradle ``` -$ ./build/install/opencensus-examples/bin/StatsRunner +$ ./build/install/opencensus-examples/bin/TagContextExample ``` ### Maven ``` -$ ./target/appassembler/bin/StatsRunner +$ ./target/appassembler/bin/TagContextExample ``` ### Bazel ``` -$ ./bazel-bin/StatsRunner +$ ./bazel-bin/TagContextExample ``` ## To run "ZPagesTester" diff --git a/examples/build.gradle b/examples/build.gradle index 41495041..aa056460 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -84,9 +84,9 @@ apply plugin: 'application' startScripts.enabled = false -task statsRunner(type: CreateStartScripts) { - mainClassName = 'io.opencensus.examples.stats.StatsRunner' - applicationName = 'StatsRunner' +task tagContextExample(type: CreateStartScripts) { + mainClassName = 'io.opencensus.examples.tags.TagContextExample' + applicationName = 'TagContextExample' outputDir = new File(project.buildDir, 'tmp') classpath = jar.outputs.files + project.configurations.runtime } @@ -144,7 +144,7 @@ applicationDistribution.into('bin') { from(multiSpansTracing) from(multiSpansScopedTracing) from(multiSpansContextTracing) - from(statsRunner) + from(tagContextExample) from(zPagesTester) from(quickStart) from(helloWorldServer) diff --git a/examples/pom.xml b/examples/pom.xml index 03b240a6..03e155ea 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -105,8 +105,8 @@ - StatsRunner - io.opencensus.examples.stats.StatsRunner + TagContextExample + io.opencensus.examples.tags.TagContextExample MultiSpansTracing diff --git a/examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java b/examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java deleted file mode 100644 index 18060204..00000000 --- a/examples/src/main/java/io/opencensus/examples/stats/StatsRunner.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016-17, OpenCensus Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opencensus.examples.stats; - -import io.opencensus.common.Scope; -import io.opencensus.stats.Measure.MeasureDouble; -import io.opencensus.stats.Stats; -import io.opencensus.stats.StatsRecorder; -import io.opencensus.tags.TagContext; -import io.opencensus.tags.TagKey; -import io.opencensus.tags.TagValue; -import io.opencensus.tags.Tagger; -import io.opencensus.tags.Tags; - -/** Simple program that uses Stats contexts. */ -public class StatsRunner { - - private static final TagKey K1 = TagKey.create("k1"); - private static final TagKey K2 = TagKey.create("k2"); - private static final TagKey K3 = TagKey.create("k3"); - private static final TagKey K4 = TagKey.create("k4"); - - private static final TagValue V1 = TagValue.create("v1"); - private static final TagValue V2 = TagValue.create("v2"); - private static final TagValue V3 = TagValue.create("v3"); - private static final TagValue V4 = TagValue.create("v4"); - - private static final String UNIT = "1"; - private static final MeasureDouble M1 = MeasureDouble.create("m1", "1st test metric", UNIT); - private static final MeasureDouble M2 = MeasureDouble.create("m2", "2nd test metric", UNIT); - - private static final Tagger tagger = Tags.getTagger(); - private static final StatsRecorder statsRecorder = Stats.getStatsRecorder(); - - private StatsRunner() {} - - /** - * Main method. - * - * @param args the main arguments. - */ - public static void main(String[] args) { - System.out.println("Hello Stats World"); - System.out.println("Default Tags: " + tagger.empty()); - System.out.println("Current Tags: " + tagger.getCurrentTagContext()); - TagContext tags1 = tagger.emptyBuilder().put(K1, V1).put(K2, V2).build(); - try (Scope scopedTagCtx1 = tagger.withTagContext(tags1)) { - System.out.println(" Current Tags: " + tagger.getCurrentTagContext()); - System.out.println( - " Current == Default + tags1: " + tagger.getCurrentTagContext().equals(tags1)); - TagContext tags2 = tagger.toBuilder(tags1).put(K3, V3).put(K4, V4).build(); - try (Scope scopedTagCtx2 = tagger.withTagContext(tags2)) { - System.out.println(" Current Tags: " + tagger.getCurrentTagContext()); - System.out.println( - " Current == Default + tags1 + tags2: " - + tagger.getCurrentTagContext().equals(tags2)); - statsRecorder.newMeasureMap().put(M1, 0.2).put(M2, 0.4).record(); - } - } - System.out.println( - "Current == Default: " + tagger.getCurrentTagContext().equals(tagger.empty())); - } -} diff --git a/examples/src/main/java/io/opencensus/examples/tags/TagContextExample.java b/examples/src/main/java/io/opencensus/examples/tags/TagContextExample.java new file mode 100644 index 00000000..727c5fbb --- /dev/null +++ b/examples/src/main/java/io/opencensus/examples/tags/TagContextExample.java @@ -0,0 +1,77 @@ +/* + * Copyright 2016-17, OpenCensus Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opencensus.examples.tags; + +import io.opencensus.common.Scope; +import io.opencensus.stats.Measure.MeasureDouble; +import io.opencensus.stats.Stats; +import io.opencensus.stats.StatsRecorder; +import io.opencensus.tags.TagContext; +import io.opencensus.tags.TagKey; +import io.opencensus.tags.TagValue; +import io.opencensus.tags.Tagger; +import io.opencensus.tags.Tags; + +/** Simple program that uses {@link TagContext}. */ +public class TagContextExample { + + private static final TagKey K1 = TagKey.create("k1"); + private static final TagKey K2 = TagKey.create("k2"); + private static final TagKey K3 = TagKey.create("k3"); + private static final TagKey K4 = TagKey.create("k4"); + + private static final TagValue V1 = TagValue.create("v1"); + private static final TagValue V2 = TagValue.create("v2"); + private static final TagValue V3 = TagValue.create("v3"); + private static final TagValue V4 = TagValue.create("v4"); + + private static final String UNIT = "1"; + private static final MeasureDouble M1 = MeasureDouble.create("m1", "1st test metric", UNIT); + private static final MeasureDouble M2 = MeasureDouble.create("m2", "2nd test metric", UNIT); + + private static final Tagger tagger = Tags.getTagger(); + private static final StatsRecorder statsRecorder = Stats.getStatsRecorder(); + + private TagContextExample() {} + + /** + * Main method. + * + * @param args the main arguments. + */ + public static void main(String[] args) { + System.out.println("Hello Stats World"); + System.out.println("Default Tags: " + tagger.empty()); + System.out.println("Current Tags: " + tagger.getCurrentTagContext()); + TagContext tags1 = tagger.emptyBuilder().put(K1, V1).put(K2, V2).build(); + try (Scope scopedTagCtx1 = tagger.withTagContext(tags1)) { + System.out.println(" Current Tags: " + tagger.getCurrentTagContext()); + System.out.println( + " Current == Default + tags1: " + tagger.getCurrentTagContext().equals(tags1)); + TagContext tags2 = tagger.toBuilder(tags1).put(K3, V3).put(K4, V4).build(); + try (Scope scopedTagCtx2 = tagger.withTagContext(tags2)) { + System.out.println(" Current Tags: " + tagger.getCurrentTagContext()); + System.out.println( + " Current == Default + tags1 + tags2: " + + tagger.getCurrentTagContext().equals(tags2)); + statsRecorder.newMeasureMap().put(M1, 0.2).put(M2, 0.4).record(); + } + } + System.out.println( + "Current == Default: " + tagger.getCurrentTagContext().equals(tagger.empty())); + } +} -- cgit v1.2.3