diff --git a/monitoring/v3/README.md b/monitoring/v3/README.md index 4004f4fc494..b7ea5622ec6 100644 --- a/monitoring/v3/README.md +++ b/monitoring/v3/README.md @@ -9,6 +9,8 @@ write a TimeSeries value to it. ## Prerequisites to run locally: * [Maven 3](https://maven.apache.org) + * [GCloud CLI](https://cloud.google.com/sdk/gcloud/) + * Create a Cloud project # Set Up Your Local Dev Environment @@ -17,6 +19,7 @@ Create local credentials by running the following command and following the oaut gcloud beta auth application-default login To run: + * `mvn clean install` * `./list_resources_example.sh * `./run_custom_metrics.sh @@ -57,13 +60,3 @@ to the appropriate project ID that matches the Service Account pointed to by `GOOGLE_APPLICATION_CREDENTIALS`, then run: mvn test -DskipTests=false - -## Contributing changes - -See [CONTRIBUTING.md](../../CONTRIBUTING.md). - -## Licensing - -See [LICENSE](../../LICENSE). - - diff --git a/monitoring/v3/src/main/java/CreateCustomMetric.java b/monitoring/v3/src/main/java/CreateCustomMetric.java index 18cdc4b5073..016697e7040 100644 --- a/monitoring/v3/src/main/java/CreateCustomMetric.java +++ b/monitoring/v3/src/main/java/CreateCustomMetric.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2015 Google Inc. - *

- * 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 - *

+/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * 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. + * 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. */ import com.google.api.services.monitoring.v3.Monitoring; @@ -28,7 +28,6 @@ import com.google.api.services.monitoring.v3.model.TypedValue; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; - import org.joda.time.DateTime; import java.io.IOException; @@ -40,12 +39,12 @@ import java.util.TimeZone; - - /** - * Class to demonstrate creating a custom metric with Cloud Monitoring. This class provides a few - * functions that create a custom GAUGE metric, writes a timeseries value to it, then reads that - * metric's value back within the last 5 minutes to see the value written. + * Class to demonstrate creating a custom metric with Cloud Monitoring. + *

+ *

This class provides a few functions that create a custom GAUGE metric, writes a timeseries + * value to it, then reads that metric's value back within the last 5 minutes to see the value + * written.

*/ public class CreateCustomMetric { @@ -111,7 +110,8 @@ public CreateCustomMetric(Monitoring monitoringService, String projectResource) /** * Constructs an instance of the class using the default metric name, and takes in a random * number generaotr (used for test purposes). - * Package-private to be accessible to tests. + *

+ *

Package-private to be accessible to tests.

*/ CreateCustomMetric(Monitoring monitoringService, String projectResource, String metricName, int bound) { @@ -162,7 +162,8 @@ private long getRandomPoint() { /** * This method creates a custom metric with arbitrary names, description, * and units. - * Package-private to be accessible to tests. + *

+ *

Package-private to be accessible to tests.

*/ MetricDescriptor createCustomMetric() throws IOException { MetricDescriptor metricDescriptor = new MetricDescriptor(); @@ -196,9 +197,11 @@ MetricDescriptor createCustomMetric() throws IOException { } /** - * Retrieve the custom metric created by createCustomMetric. It can sometimes take a few moments - * before a new custom metric is ready to have TimeSeries written to it, so this method is used - * to check when it is ready. + * Retrieve the custom metric created by createCustomMetric. + *

+ *

It can sometimes take a few moments before a new custom metric is ready to have + * TimeSeries written to it, so this method is used + * to check when it is ready.

*/ public MetricDescriptor getCustomMetric() throws IOException { Monitoring.Projects.MetricDescriptors.List metrics = @@ -218,10 +221,10 @@ public MetricDescriptor getCustomMetric() throws IOException { } /** - * Writes a timeseries value for the custom metric created. The value written - * is a random integer value for demonstration purposes. It's a GAUGE metric, + * Writes a timeseries value for the custom metric created. + *

The value written is a random integer value for demonstration purposes. It's a GAUGE metric, * which means its a measure of a value at a point in time, and thus the start - * window and end window times are the same. + * window and end window times are the same.

* * @throws IOException On network error. */ @@ -264,21 +267,21 @@ void writeCustomMetricTimeseriesValue() throws IOException { } /** - * Read the TimeSeries value for the custom metrics created within a window of the - * last 5 minutes. + *

Read the TimeSeries value for the custom metrics created within a window of the + * last 5 minutes.

* * @return The TimeSeries response object reflecting the Timeseries of the custom metrics - * for the last 5 minutes. + * for the last 5 minutes. * @throws IOException On network error. */ ListTimeSeriesResponse readTimeseriesValue() throws IOException { ListTimeSeriesResponse response = monitoringService.projects().timeSeries().list(projectResource) - .setFilter("metric.type=\"" + metricType + "\"") - .setPageSize(3) - .setIntervalStartTime(getStartTime()) - .setIntervalEndTime(getNow()) - .execute(); + .setFilter("metric.type=\"" + metricType + "\"") + .setPageSize(3) + .setIntervalStartTime(getStartTime()) + .setIntervalEndTime(getNow()) + .execute(); return response; } @@ -302,8 +305,8 @@ public static void main(final String[] args) throws Exception { // Create an authorized API client Monitoring monitoringService = ListResources.authenticate(); - CreateCustomMetric metricWriter = new CreateCustomMetric( - monitoringService, projectResource); + CreateCustomMetric metricWriter = + new CreateCustomMetric(monitoringService, projectResource); MetricDescriptor metricDescriptor = metricWriter.createCustomMetric(); diff --git a/monitoring/v3/src/main/java/ListResources.java b/monitoring/v3/src/main/java/ListResources.java index 1eeeec28ffa..3eb9c94ede1 100644 --- a/monitoring/v3/src/main/java/ListResources.java +++ b/monitoring/v3/src/main/java/ListResources.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2015 Google Inc. - *

- * 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 - *

+/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * 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. + * 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. */ // [START all] @@ -25,7 +25,6 @@ import com.google.api.services.monitoring.v3.model.ListMetricDescriptorsResponse; import com.google.api.services.monitoring.v3.model.ListMonitoredResourceDescriptorsResponse; import com.google.api.services.monitoring.v3.model.ListTimeSeriesResponse; - import org.joda.time.DateTime; import java.io.IOException; @@ -35,7 +34,6 @@ import java.util.TimeZone; - /** * Simple command-line program to demonstrate connecting to and retrieving data * from the Google Cloud Monitoring API v3 using application default credentials. @@ -91,9 +89,10 @@ private ListResources(Monitoring monitoringService, String projectResource) { /** * Query the projects.monitoredResourceDescriptors.list API method. - * This lists all the resources available to be monitored in the API. - *

- * Package-private to be accessible to tests. + * + *

This lists all the resources available to be monitored in the API.

+ * + *

Package-private to be accessible to tests.

*/ void listMonitoredResourceDescriptors() throws IOException { ListMonitoredResourceDescriptorsResponse monitoredResources = @@ -105,14 +104,12 @@ void listMonitoredResourceDescriptors() throws IOException { /** * Query to MetricDescriptors.list - * This lists all the current metrics. - *

- * Package-private to be accessible to tests. + *

This lists all the current metrics. Package-private to be accessible to tests.

*/ void listMetricDescriptors() throws IOException { ListMetricDescriptorsResponse metricsResponse = this.monitoringService.projects().metricDescriptors() - .list(this.projectResource).execute(); + .list(this.projectResource).execute(); this.outputStream.println("listMetricDescriptors response"); this.outputStream.println(metricsResponse.toPrettyString()); } @@ -143,7 +140,8 @@ private static String getEndTime() { /** * Query to MetricDescriptors.list - * This lists all the current metrics. + * + *

This lists all the current metrics.

*/ void listTimeseries() throws IOException { ListTimeSeriesResponse timeSeriesList = this.monitoringService.projects().timeSeries() diff --git a/monitoring/v3/src/test/java/CreateCustomMetricTest.java b/monitoring/v3/src/test/java/CreateCustomMetricTest.java index f4c2aae8fe9..db11506f926 100644 --- a/monitoring/v3/src/test/java/CreateCustomMetricTest.java +++ b/monitoring/v3/src/test/java/CreateCustomMetricTest.java @@ -1,51 +1,39 @@ /* - * Copyright (c) 2015 Google Inc. + * Copyright 2016 Google Inc. All Rights Reserved. * - * 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 + * 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. + * 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. */ -import static com.google.common.truth.Truth.assertThat; - import com.google.api.services.monitoring.v3.Monitoring; import com.google.api.services.monitoring.v3.model.Point; import com.google.common.collect.ImmutableList; - import org.apache.commons.lang3.RandomStringUtils; - import org.junit.Before; import org.junit.Test; import java.util.List; -import java.util.Random; + +import static com.google.common.truth.Truth.assertThat; /** - * Integration tests for the basic Cloud Monitoring v3 examples. Running - * these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a + * Integration tests for the basic Cloud Monitoring v3 examples. + *

+ *

Running these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a * valid JSON Service Account downloaded from a project with the Cloud - * Monitoring API enabled. + * Monitoring API enabled.

*/ public class CreateCustomMetricTest { - /** - * Overrides the Random number generator so our tests get a predictable result. - */ - private static class MockRandom extends Random { - - public int nextInt(int bound) { - return 4; - } - } - /** * Google Cloud Monitoring client to integration test. */ diff --git a/monitoring/v3/src/test/java/ListResourcesTest.java b/monitoring/v3/src/test/java/ListResourcesTest.java index 234ee858a54..2dda0d0a4b3 100644 --- a/monitoring/v3/src/test/java/ListResourcesTest.java +++ b/monitoring/v3/src/test/java/ListResourcesTest.java @@ -1,34 +1,34 @@ /* - * Copyright (c) 2015 Google Inc. + * Copyright 2016 Google Inc. All Rights Reserved. * - * 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 + * 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. + * 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. */ -import static com.google.common.truth.Truth.assertThat; - import com.google.api.services.monitoring.v3.Monitoring; - import org.junit.Before; import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import static com.google.common.truth.Truth.assertThat; + /** - * Integration tests for the basic Cloud Monitoring v3 examples. Running - * these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a + * Integration tests for the basic Cloud Monitoring v3 examples. + *

+ *

Running these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a * valid JSON Service Account downloaded from a project with the Cloud - * Monitoring API enabled. + * Monitoring API enabled.

*/ public class ListResourcesTest {