Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix style, Use Same Test Project #140

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ env:
before_install:
- openssl aes-256-cbc -K $encrypted_37a4f399de75_key -iv $encrypted_37a4f399de75_iv -in service-account.json.enc -out service-account.json -d

script: mvn verify
script: mvn verify -DskipTests=false
after_success:
- mvn clean cobertura:cobertura coveralls:report
13 changes: 3 additions & 10 deletions monitoring/v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <YOUR-PROJECT-ID>
* `./run_custom_metrics.sh <YOUR-PROJECT-ID>
Expand Down Expand Up @@ -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).


66 changes: 35 additions & 31 deletions monitoring/v3/src/main/java/CreateCustomMetric.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/**
* Copyright (c) 2015 Google Inc.
* <p/>
* 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
* <p/>
/*
* 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
* <p/>
*
* 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;
Expand Down Expand Up @@ -40,12 +40,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.
* <p/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the end p tags </p> are optional in HTML5. I don't think I've seen many javadocs that use them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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

Expand Down Expand Up @@ -111,7 +111,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.
* <p/>
* <p>Package-private to be accessible to tests.
*/
CreateCustomMetric(Monitoring monitoringService, String projectResource,
String metricName, int bound) {
Expand Down Expand Up @@ -162,7 +163,8 @@ private long getRandomPoint() {
/**
* This method creates a custom metric with arbitrary names, description,
* and units.
* Package-private to be accessible to tests.
* <p/>
* <p>Package-private to be accessible to tests.
*/
MetricDescriptor createCustomMetric() throws IOException {
MetricDescriptor metricDescriptor = new MetricDescriptor();
Expand Down Expand Up @@ -196,8 +198,10 @@ 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
* Retrieve the custom metric created by createCustomMetric.
* <p/>
* <p>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 {
Expand All @@ -218,8 +222,8 @@ 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.
* <p>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.
*
Expand Down Expand Up @@ -268,17 +272,17 @@ void writeCustomMetricTimeseriesValue() throws IOException {
* 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;
}

Expand All @@ -302,8 +306,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();

Expand Down
39 changes: 19 additions & 20 deletions monitoring/v3/src/main/java/ListResources.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/**
* Copyright (c) 2015 Google Inc.
* <p/>
* 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
* <p/>
/*
* 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
* <p/>
*
* 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]

Expand All @@ -35,7 +35,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.
Expand Down Expand Up @@ -91,9 +90,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.
* <p/>
* Package-private to be accessible to tests.
* <p>This lists all the resources available to be monitored in the API.
* <p/>
* <p>Package-private to be accessible to tests.
*/
void listMonitoredResourceDescriptors() throws IOException {
ListMonitoredResourceDescriptorsResponse monitoredResources =
Expand All @@ -105,14 +105,12 @@ void listMonitoredResourceDescriptors() throws IOException {

/**
* Query to MetricDescriptors.list
* This lists all the current metrics.
* <p/>
* Package-private to be accessible to tests.
* <p>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());
}
Expand Down Expand Up @@ -143,7 +141,8 @@ private static String getEndTime() {

/**
* Query to MetricDescriptors.list
* This lists all the current metrics.
*
* <p>This lists all the current metrics.
*/
void listTimeseries() throws IOException {
ListTimeSeriesResponse timeSeriesList = this.monitoringService.projects().timeSeries()
Expand Down
34 changes: 12 additions & 22 deletions monitoring/v3/src/test/java/CreateCustomMetricTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* 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;
Expand All @@ -21,31 +21,21 @@
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;


/**
* 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.
*
* <p>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.
*/
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.
*/
Expand Down
22 changes: 12 additions & 10 deletions monitoring/v3/src/test/java/ListResourcesTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* 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;
Expand All @@ -24,9 +24,11 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;


/**
* 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.
*
* <p>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.
*/
Expand Down