Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Conversation

suraj-qlogic
Copy link
Contributor

Fixes #231

@suraj-qlogic suraj-qlogic requested a review from a team September 10, 2020 05:44
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 10, 2020
@suraj-qlogic suraj-qlogic self-assigned this Sep 10, 2020
@product-auto-label product-auto-label bot added the api: monitoring Issues related to the googleapis/java-monitoring API. label Sep 10, 2020
@codecov
Copy link

codecov bot commented Sep 10, 2020

Codecov Report

Merging #250 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9936b6...1793cb7. Read the comment docs.

ProjectName name = ProjectName.of(projectId);

// A Filter that identifies which time series should be compared with the threshold
String metricFilter =
Copy link
Contributor

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?

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

Copy link
Contributor

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.

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

Comment on lines 91 to 93
} catch (ApiException ex) {
System.out.print("\nalert policy was not created." + ex.toString());
}
Copy link
Contributor

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.

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

Comment on lines 71 to 73
} catch (ApiException ex) {
System.out.print("\nmetric descriptor was not created." + ex.toString());
}
Copy link
Contributor

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.

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

Comment on lines 99 to 101
} catch (ApiException ex) {
System.out.print("\n time series could not be written." + ex.toString());
}
Copy link
Contributor

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.

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

Comment on lines 41 to 43
} catch (ApiException ex) {
System.out.print("\nalert policy not found:" + ex.toString());
}
Copy link
Contributor

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.

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

Comment on lines 67 to 69
} catch (ApiException ex) {
System.out.print("\n time series not found." + ex.toString());
}
Copy link
Contributor

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.

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

Comment on lines 57 to 59
} catch (ApiException ex) {
System.out.print("\nmonitored resource descriptors not found." + ex.toString());
}
Copy link
Contributor

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.

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

Comment on lines 68 to 70
} catch (ApiException ex) {
System.out.print("\n time series not found." + ex.toString());
}
Copy link
Contributor

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.

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

Comment on lines 93 to 95
} catch (ApiException ex) {
System.out.print("alert policy not found:" + ex.toString());
}
Copy link
Contributor

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.

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


@Before
public void setUp() {
alertPolicyDisplayName = "alert_policy_name_" + UUID.randomUUID().toString().substring(0, 8);
Copy link
Contributor

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.

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

@suraj-qlogic suraj-qlogic requested a review from lesv September 11, 2020 11:11
Comment on lines 46 to 48
String.format(
"metric.type=\"compute.googleapis.com/instance/"
+ "cpu/utilization\" AND resource.type=\"gce_instance\"");
Copy link
Contributor

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" + '"";

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

Copy link
Contributor

@lesv lesv left a 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.

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 12, 2020
@suraj-qlogic suraj-qlogic added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 14, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 14, 2020
@suraj-qlogic suraj-qlogic requested a review from lesv September 14, 2020 12:19
@suraj-qlogic
Copy link
Contributor Author

@chingor13 ,gentle ping

@suraj-qlogic
Copy link
Contributor Author

@chingor13 , PTAL

@chingor13 chingor13 merged commit 6cc4678 into googleapis:master Oct 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: monitoring Issues related to the googleapis/java-monitoring API. cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix samples format
4 participants