Skip to content

Commit 98c44fc

Browse files
author
Bill Prin
committed
Fix style, Use Same Test Project
Also fix error in README and change test project to this repo's project.
1 parent 796dc2b commit 98c44fc

File tree

6 files changed

+83
-95
lines changed

6 files changed

+83
-95
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ env:
2020
before_install:
2121
- openssl aes-256-cbc -K $encrypted_37a4f399de75_key -iv $encrypted_37a4f399de75_iv -in service-account.json.enc -out service-account.json -d
2222

23-
script: mvn verify
23+
script: mvn verify -DskipTests=false
2424
after_success:
2525
- mvn clean cobertura:cobertura coveralls:report

monitoring/v3/README.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ write a TimeSeries value to it.
99
## Prerequisites to run locally:
1010

1111
* [Maven 3](https://maven.apache.org)
12+
* [GCloud CLI](https://cloud.google.com/sdk/gcloud/)
13+
* Create a Cloud project
1214

1315
# Set Up Your Local Dev Environment
1416

@@ -17,6 +19,7 @@ Create local credentials by running the following command and following the oaut
1719
gcloud beta auth application-default login
1820

1921
To run:
22+
2023
* `mvn clean install`
2124
* `./list_resources_example.sh <YOUR-PROJECT-ID>
2225
* `./run_custom_metrics.sh <YOUR-PROJECT-ID>
@@ -57,13 +60,3 @@ to the appropriate project ID that matches the Service Account pointed to by
5760
`GOOGLE_APPLICATION_CREDENTIALS`, then run:
5861

5962
mvn test -DskipTests=false
60-
61-
## Contributing changes
62-
63-
See [CONTRIBUTING.md](../../CONTRIBUTING.md).
64-
65-
## Licensing
66-
67-
See [LICENSE](../../LICENSE).
68-
69-

monitoring/v3/src/main/java/CreateCustomMetric.java

+36-32
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/**
2-
* Copyright (c) 2015 Google Inc.
3-
* <p/>
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
7-
* <p/>
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
* <p/>
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
import com.google.api.services.monitoring.v3.Monitoring;
@@ -40,12 +40,12 @@
4040
import java.util.TimeZone;
4141

4242

43-
44-
4543
/**
46-
* Class to demonstrate creating a custom metric with Cloud Monitoring. This class provides a few
47-
* functions that create a custom GAUGE metric, writes a timeseries value to it, then reads that
48-
* metric's value back within the last 5 minutes to see the value written.
44+
* Class to demonstrate creating a custom metric with Cloud Monitoring.
45+
* <p/>
46+
* <p>This class provides a few functions that create a custom GAUGE metric, writes a timeseries
47+
* value to it, then reads that metric's value back within the last 5 minutes to see the value
48+
* written.
4949
*/
5050
public class CreateCustomMetric {
5151

@@ -111,7 +111,8 @@ public CreateCustomMetric(Monitoring monitoringService, String projectResource)
111111
/**
112112
* Constructs an instance of the class using the default metric name, and takes in a random
113113
* number generaotr (used for test purposes).
114-
* Package-private to be accessible to tests.
114+
* <p/>
115+
* <p>Package-private to be accessible to tests.
115116
*/
116117
CreateCustomMetric(Monitoring monitoringService, String projectResource,
117118
String metricName, int bound) {
@@ -162,7 +163,8 @@ private long getRandomPoint() {
162163
/**
163164
* This method creates a custom metric with arbitrary names, description,
164165
* and units.
165-
* Package-private to be accessible to tests.
166+
* <p/>
167+
* <p>Package-private to be accessible to tests.
166168
*/
167169
MetricDescriptor createCustomMetric() throws IOException {
168170
MetricDescriptor metricDescriptor = new MetricDescriptor();
@@ -196,8 +198,10 @@ MetricDescriptor createCustomMetric() throws IOException {
196198
}
197199

198200
/**
199-
* Retrieve the custom metric created by createCustomMetric. It can sometimes take a few moments
200-
* before a new custom metric is ready to have TimeSeries written to it, so this method is used
201+
* Retrieve the custom metric created by createCustomMetric.
202+
* <p/>
203+
* <p>It can sometimes take a few moments before a new custom metric is ready to have
204+
* TimeSeries written to it, so this method is used
201205
* to check when it is ready.
202206
*/
203207
public MetricDescriptor getCustomMetric() throws IOException {
@@ -218,8 +222,8 @@ public MetricDescriptor getCustomMetric() throws IOException {
218222
}
219223

220224
/**
221-
* Writes a timeseries value for the custom metric created. The value written
222-
* is a random integer value for demonstration purposes. It's a GAUGE metric,
225+
* Writes a timeseries value for the custom metric created.
226+
* <p>The value written is a random integer value for demonstration purposes. It's a GAUGE metric,
223227
* which means its a measure of a value at a point in time, and thus the start
224228
* window and end window times are the same.
225229
*
@@ -264,21 +268,21 @@ void writeCustomMetricTimeseriesValue() throws IOException {
264268
}
265269

266270
/**
267-
* Read the TimeSeries value for the custom metrics created within a window of the
271+
* <p>Read the TimeSeries value for the custom metrics created within a window of the
268272
* last 5 minutes.
269273
*
270274
* @return The TimeSeries response object reflecting the Timeseries of the custom metrics
271-
* for the last 5 minutes.
275+
* for the last 5 minutes.
272276
* @throws IOException On network error.
273277
*/
274278
ListTimeSeriesResponse readTimeseriesValue() throws IOException {
275279
ListTimeSeriesResponse response =
276280
monitoringService.projects().timeSeries().list(projectResource)
277-
.setFilter("metric.type=\"" + metricType + "\"")
278-
.setPageSize(3)
279-
.setIntervalStartTime(getStartTime())
280-
.setIntervalEndTime(getNow())
281-
.execute();
281+
.setFilter("metric.type=\"" + metricType + "\"")
282+
.setPageSize(3)
283+
.setIntervalStartTime(getStartTime())
284+
.setIntervalEndTime(getNow())
285+
.execute();
282286
return response;
283287
}
284288

@@ -302,8 +306,8 @@ public static void main(final String[] args) throws Exception {
302306
// Create an authorized API client
303307
Monitoring monitoringService = ListResources.authenticate();
304308

305-
CreateCustomMetric metricWriter = new CreateCustomMetric(
306-
monitoringService, projectResource);
309+
CreateCustomMetric metricWriter =
310+
new CreateCustomMetric(monitoringService, projectResource);
307311

308312
MetricDescriptor metricDescriptor = metricWriter.createCustomMetric();
309313

monitoring/v3/src/main/java/ListResources.java

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/**
2-
* Copyright (c) 2015 Google Inc.
3-
* <p/>
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
7-
* <p/>
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
* <p/>
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616
// [START all]
1717

@@ -35,7 +35,6 @@
3535
import java.util.TimeZone;
3636

3737

38-
3938
/**
4039
* Simple command-line program to demonstrate connecting to and retrieving data
4140
* from the Google Cloud Monitoring API v3 using application default credentials.
@@ -91,9 +90,10 @@ private ListResources(Monitoring monitoringService, String projectResource) {
9190

9291
/**
9392
* Query the projects.monitoredResourceDescriptors.list API method.
94-
* This lists all the resources available to be monitored in the API.
9593
* <p/>
96-
* Package-private to be accessible to tests.
94+
* <p>This lists all the resources available to be monitored in the API.
95+
* <p/>
96+
* <p>Package-private to be accessible to tests.
9797
*/
9898
void listMonitoredResourceDescriptors() throws IOException {
9999
ListMonitoredResourceDescriptorsResponse monitoredResources =
@@ -105,14 +105,12 @@ void listMonitoredResourceDescriptors() throws IOException {
105105

106106
/**
107107
* Query to MetricDescriptors.list
108-
* This lists all the current metrics.
109-
* <p/>
110-
* Package-private to be accessible to tests.
108+
* <p>This lists all the current metrics. Package-private to be accessible to tests.
111109
*/
112110
void listMetricDescriptors() throws IOException {
113111
ListMetricDescriptorsResponse metricsResponse =
114112
this.monitoringService.projects().metricDescriptors()
115-
.list(this.projectResource).execute();
113+
.list(this.projectResource).execute();
116114
this.outputStream.println("listMetricDescriptors response");
117115
this.outputStream.println(metricsResponse.toPrettyString());
118116
}
@@ -143,7 +141,8 @@ private static String getEndTime() {
143141

144142
/**
145143
* Query to MetricDescriptors.list
146-
* This lists all the current metrics.
144+
*
145+
* <p>This lists all the current metrics.
147146
*/
148147
void listTimeseries() throws IOException {
149148
ListTimeSeriesResponse timeSeriesList = this.monitoringService.projects().timeSeries()

monitoring/v3/src/test/java/CreateCustomMetricTest.java

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
2-
* Copyright (c) 2015 Google Inc.
2+
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
import static com.google.common.truth.Truth.assertThat;
@@ -21,31 +21,21 @@
2121
import com.google.common.collect.ImmutableList;
2222

2323
import org.apache.commons.lang3.RandomStringUtils;
24-
2524
import org.junit.Before;
2625
import org.junit.Test;
2726

2827
import java.util.List;
29-
import java.util.Random;
28+
3029

3130
/**
32-
* Integration tests for the basic Cloud Monitoring v3 examples. Running
33-
* these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a
31+
* Integration tests for the basic Cloud Monitoring v3 examples.
32+
*
33+
* <p>Running these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a
3434
* valid JSON Service Account downloaded from a project with the Cloud
3535
* Monitoring API enabled.
3636
*/
3737
public class CreateCustomMetricTest {
3838

39-
/**
40-
* Overrides the Random number generator so our tests get a predictable result.
41-
*/
42-
private static class MockRandom extends Random {
43-
44-
public int nextInt(int bound) {
45-
return 4;
46-
}
47-
}
48-
4939
/**
5040
* Google Cloud Monitoring client to integration test.
5141
*/

monitoring/v3/src/test/java/ListResourcesTest.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
2-
* Copyright (c) 2015 Google Inc.
2+
* Copyright 2016 Google Inc. All Rights Reserved.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
import static com.google.common.truth.Truth.assertThat;
@@ -24,9 +24,11 @@
2424
import java.io.ByteArrayOutputStream;
2525
import java.io.PrintStream;
2626

27+
2728
/**
28-
* Integration tests for the basic Cloud Monitoring v3 examples. Running
29-
* these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a
29+
* Integration tests for the basic Cloud Monitoring v3 examples.
30+
*
31+
* <p>Running these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a
3032
* valid JSON Service Account downloaded from a project with the Cloud
3133
* Monitoring API enabled.
3234
*/

0 commit comments

Comments
 (0)