-
Notifications
You must be signed in to change notification settings - Fork 19
refactor(samples): fix samples format #250
refactor(samples): fix samples format #250
Conversation
Codecov Report
@@ Coverage Diff @@
## master #250 +/- ##
=========================================
Coverage 78.01% 78.01%
Complexity 422 422
=========================================
Files 36 36
Lines 4067 4067
Branches 49 49
=========================================
Hits 3173 3173
Misses 831 831
Partials 63 63 Continue to review full report at Codecov.
|
dff6cfa
to
272dd89
Compare
272dd89
to
a1512a1
Compare
ProjectName name = ProjectName.of(projectId); | ||
|
||
// A Filter that identifies which time series should be compared with the threshold | ||
String metricFilter = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be better using string format? or some other way to not be quoting so much?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite what I was thinking. Users are going to want to customize this and you have lots of \"
embedded within a string. The first thing I found when I Google'd was this idea: https://stackoverflow.com/questions/15305956/how-to-add-quotes-around-printed-string
String metricFilter = "metric.type="
+ '"'
+ "compute.googleapis.com/instance/cpu/utilization"
+ '"'
+ " AND resource.type="
+ '"'
+ "gce_instance"
+ '"';
What I'm asking for is that we make it more readable and easier for users to modify and adjust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ApiException ex) { | ||
System.out.print("\nalert policy was not created." + ex.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n as string constants get picked up by static analyzers.
If you aren't doing anything with an exception, you probably shouldn't be catching it.
See our sample format guide for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ApiException ex) { | ||
System.out.print("\nmetric descriptor was not created." + ex.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n as string constants get picked up by static analyzers.
If you aren't doing anything with an exception, you probably shouldn't be catching it.
See our sample format guide for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ApiException ex) { | ||
System.out.print("\n time series could not be written." + ex.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n as string constants get picked up by static analyzers.
If you aren't doing anything with an exception, you probably shouldn't be catching it.
See our sample format guide for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ApiException ex) { | ||
System.out.print("\nalert policy not found:" + ex.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n as string constants get picked up by static analyzers.
If you aren't doing anything with an exception, you probably shouldn't be catching it.
See our sample format guide for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ApiException ex) { | ||
System.out.print("\n time series not found." + ex.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n as string constants get picked up by static analyzers.
If you aren't doing anything with an exception, you probably shouldn't be catching it.
See our sample format guide for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ApiException ex) { | ||
System.out.print("\nmonitored resource descriptors not found." + ex.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n as string constants get picked up by static analyzers.
If you aren't doing anything with an exception, you probably shouldn't be catching it.
See our sample format guide for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ApiException ex) { | ||
System.out.print("\n time series not found." + ex.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n as string constants get picked up by static analyzers.
If you aren't doing anything with an exception, you probably shouldn't be catching it.
See our sample format guide for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} catch (ApiException ex) { | ||
System.out.print("alert policy not found:" + ex.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you aren't doing anything with an exception, you probably shouldn't be catching it.
See our sample format guide for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
@Before | ||
public void setUp() { | ||
alertPolicyDisplayName = "alert_policy_name_" + UUID.randomUUID().toString().substring(0, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some bits in the first part of the uuid are constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
String.format( | ||
"metric.type=\"compute.googleapis.com/instance/" | ||
+ "cpu/utilization\" AND resource.type=\"gce_instance\""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue, can we make it easier to read and to edit for customers?
Trying a different approach this time.
String metricFilter =
"metric.type="
+ '"' + compute.googleapis.com/instance/cpu/utilization" + '"'
+ " AND "
+ "resource.type="
+ '"' + "gce_instance" + '"";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all we were doing was executing this code I'd LGTM it, my two comments on string literals with quotes in them are about aesthetics and clarity - how can we make this easier to read and understand. If you can come up with an idea that accomplishes that better than my suggestions - please try it.
@chingor13 ,gentle ping |
@chingor13 , PTAL |
Fixes #231