Skip to content

Commit c7bb243

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 c7bb243

File tree

6 files changed

+91
-109
lines changed

6 files changed

+91
-109
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

+39-36
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;
@@ -28,7 +28,6 @@
2828
import com.google.api.services.monitoring.v3.model.TypedValue;
2929
import com.google.common.collect.ImmutableMap;
3030
import com.google.common.collect.Lists;
31-
3231
import org.joda.time.DateTime;
3332

3433
import java.io.IOException;
@@ -40,12 +39,12 @@
4039
import java.util.TimeZone;
4140

4241

43-
44-
4542
/**
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.
43+
* Class to demonstrate creating a custom metric with Cloud Monitoring.
44+
* <p/>
45+
* <p>This class provides a few functions that create a custom GAUGE metric, writes a timeseries
46+
* value to it, then reads that metric's value back within the last 5 minutes to see the value
47+
* written.</p>
4948
*/
5049
public class CreateCustomMetric {
5150

@@ -111,7 +110,8 @@ public CreateCustomMetric(Monitoring monitoringService, String projectResource)
111110
/**
112111
* Constructs an instance of the class using the default metric name, and takes in a random
113112
* number generaotr (used for test purposes).
114-
* Package-private to be accessible to tests.
113+
* <p/>
114+
* <p>Package-private to be accessible to tests.</p>
115115
*/
116116
CreateCustomMetric(Monitoring monitoringService, String projectResource,
117117
String metricName, int bound) {
@@ -162,7 +162,8 @@ private long getRandomPoint() {
162162
/**
163163
* This method creates a custom metric with arbitrary names, description,
164164
* and units.
165-
* Package-private to be accessible to tests.
165+
* <p/>
166+
* <p>Package-private to be accessible to tests.</p>
166167
*/
167168
MetricDescriptor createCustomMetric() throws IOException {
168169
MetricDescriptor metricDescriptor = new MetricDescriptor();
@@ -196,9 +197,11 @@ MetricDescriptor createCustomMetric() throws IOException {
196197
}
197198

198199
/**
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-
* to check when it is ready.
200+
* Retrieve the custom metric created by createCustomMetric.
201+
* <p/>
202+
* <p>It can sometimes take a few moments before a new custom metric is ready to have
203+
* TimeSeries written to it, so this method is used
204+
* to check when it is ready.</p>
202205
*/
203206
public MetricDescriptor getCustomMetric() throws IOException {
204207
Monitoring.Projects.MetricDescriptors.List metrics =
@@ -218,10 +221,10 @@ public MetricDescriptor getCustomMetric() throws IOException {
218221
}
219222

220223
/**
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,
224+
* Writes a timeseries value for the custom metric created.
225+
* <p>The value written is a random integer value for demonstration purposes. It's a GAUGE metric,
223226
* which means its a measure of a value at a point in time, and thus the start
224-
* window and end window times are the same.
227+
* window and end window times are the same.</p>
225228
*
226229
* @throws IOException On network error.
227230
*/
@@ -264,21 +267,21 @@ void writeCustomMetricTimeseriesValue() throws IOException {
264267
}
265268

266269
/**
267-
* Read the TimeSeries value for the custom metrics created within a window of the
268-
* last 5 minutes.
270+
* <p>Read the TimeSeries value for the custom metrics created within a window of the
271+
* last 5 minutes.</p>
269272
*
270273
* @return The TimeSeries response object reflecting the Timeseries of the custom metrics
271-
* for the last 5 minutes.
274+
* for the last 5 minutes.
272275
* @throws IOException On network error.
273276
*/
274277
ListTimeSeriesResponse readTimeseriesValue() throws IOException {
275278
ListTimeSeriesResponse response =
276279
monitoringService.projects().timeSeries().list(projectResource)
277-
.setFilter("metric.type=\"" + metricType + "\"")
278-
.setPageSize(3)
279-
.setIntervalStartTime(getStartTime())
280-
.setIntervalEndTime(getNow())
281-
.execute();
280+
.setFilter("metric.type=\"" + metricType + "\"")
281+
.setPageSize(3)
282+
.setIntervalStartTime(getStartTime())
283+
.setIntervalEndTime(getNow())
284+
.execute();
282285
return response;
283286
}
284287

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

305-
CreateCustomMetric metricWriter = new CreateCustomMetric(
306-
monitoringService, projectResource);
308+
CreateCustomMetric metricWriter =
309+
new CreateCustomMetric(monitoringService, projectResource);
307310

308311
MetricDescriptor metricDescriptor = metricWriter.createCustomMetric();
309312

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

+20-22
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

@@ -25,7 +25,6 @@
2525
import com.google.api.services.monitoring.v3.model.ListMetricDescriptorsResponse;
2626
import com.google.api.services.monitoring.v3.model.ListMonitoredResourceDescriptorsResponse;
2727
import com.google.api.services.monitoring.v3.model.ListTimeSeriesResponse;
28-
2928
import org.joda.time.DateTime;
3029

3130
import java.io.IOException;
@@ -35,7 +34,6 @@
3534
import java.util.TimeZone;
3635

3736

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

9290
/**
9391
* Query the projects.monitoredResourceDescriptors.list API method.
94-
* This lists all the resources available to be monitored in the API.
95-
* <p/>
96-
* Package-private to be accessible to tests.
92+
*
93+
* <p>This lists all the resources available to be monitored in the API.</p>
94+
*
95+
* <p>Package-private to be accessible to tests.</p>
9796
*/
9897
void listMonitoredResourceDescriptors() throws IOException {
9998
ListMonitoredResourceDescriptorsResponse monitoredResources =
@@ -105,14 +104,12 @@ void listMonitoredResourceDescriptors() throws IOException {
105104

106105
/**
107106
* Query to MetricDescriptors.list
108-
* This lists all the current metrics.
109-
* <p/>
110-
* Package-private to be accessible to tests.
107+
* <p>This lists all the current metrics. Package-private to be accessible to tests.</p>
111108
*/
112109
void listMetricDescriptors() throws IOException {
113110
ListMetricDescriptorsResponse metricsResponse =
114111
this.monitoringService.projects().metricDescriptors()
115-
.list(this.projectResource).execute();
112+
.list(this.projectResource).execute();
116113
this.outputStream.println("listMetricDescriptors response");
117114
this.outputStream.println(metricsResponse.toPrettyString());
118115
}
@@ -143,7 +140,8 @@ private static String getEndTime() {
143140

144141
/**
145142
* Query to MetricDescriptors.list
146-
* This lists all the current metrics.
143+
*
144+
* <p>This lists all the current metrics.</p>
147145
*/
148146
void listTimeseries() throws IOException {
149147
ListTimeSeriesResponse timeSeriesList = this.monitoringService.projects().timeSeries()

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

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,39 @@
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

17-
import static com.google.common.truth.Truth.assertThat;
18-
1917
import com.google.api.services.monitoring.v3.Monitoring;
2018
import com.google.api.services.monitoring.v3.model.Point;
2119
import com.google.common.collect.ImmutableList;
22-
2320
import org.apache.commons.lang3.RandomStringUtils;
24-
2521
import org.junit.Before;
2622
import org.junit.Test;
2723

2824
import java.util.List;
29-
import java.util.Random;
25+
26+
import static com.google.common.truth.Truth.assertThat;
3027

3128
/**
32-
* Integration tests for the basic Cloud Monitoring v3 examples. Running
33-
* these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a
29+
* Integration tests for the basic Cloud Monitoring v3 examples.
30+
* <p/>
31+
* <p>Running these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a
3432
* valid JSON Service Account downloaded from a project with the Cloud
35-
* Monitoring API enabled.
33+
* Monitoring API enabled.</p>
3634
*/
3735
public class CreateCustomMetricTest {
3836

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-
4937
/**
5038
* Google Cloud Monitoring client to integration test.
5139
*/

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

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
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

17-
import static com.google.common.truth.Truth.assertThat;
18-
1917
import com.google.api.services.monitoring.v3.Monitoring;
20-
2118
import org.junit.Before;
2219
import org.junit.Test;
2320

2421
import java.io.ByteArrayOutputStream;
2522
import java.io.PrintStream;
2623

24+
import static com.google.common.truth.Truth.assertThat;
25+
2726
/**
28-
* Integration tests for the basic Cloud Monitoring v3 examples. Running
29-
* these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a
27+
* Integration tests for the basic Cloud Monitoring v3 examples.
28+
* <p/>
29+
* <p>Running these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a
3030
* valid JSON Service Account downloaded from a project with the Cloud
31-
* Monitoring API enabled.
31+
* Monitoring API enabled.</p>
3232
*/
3333
public class ListResourcesTest {
3434

0 commit comments

Comments
 (0)