Add support for global tags (including regexes)#117
Conversation
gzussa
left a comment
There was a problem hiding this comment.
This is a great addition to the plugin. Added comments - mostly related to Java syntax and common practices.
| if ( DatadogUtilities.isJobTracked(jobName) ) { | ||
| logger.fine("Started build!"); | ||
|
|
||
| Boolean useJobRegex = DatadogUtilities.getDatadogDescriptor().getJobRegex(); |
There was a problem hiding this comment.
Change Boolean to its primitive. This will avoid creating a new object. Also, do we have to check for null here?
There was a problem hiding this comment.
After talking with @sjenriquez about the scope/UI complexity here we decided to move to a new text area for the tags option. In doing this I removed the need for this variable entirely. Good to know though!
|
|
||
| // Collect Data | ||
| DatadogBuildListener.DescriptorImpl descriptor = DatadogUtilities.getDatadogDescriptor(); | ||
| Boolean useJobRegex = descriptor.getJobRegex(); |
| } | ||
|
|
||
| // Grab jobRegex and coerse to a boolean | ||
| if ( formData.getString("jobRegex").equals("true") ) { |
There was a problem hiding this comment.
in case there is a null, you should do "true".equals(formData.getString("jobRegex"))
There was a problem hiding this comment.
what about this.setJobRegex("true".equals(formData.getString("jobRegex")))?
| * | ||
| * @param jobRegex - a boolean flag on whether to use regexes instead of literals for whitelist/blacklisting jobs. | ||
| */ | ||
| public void setJobRegex(final Boolean jobRegex) { |
| && prop != null && prop.isEmitOnCheckout() ) { | ||
| logger.fine("Checkout! in onCheckout()"); | ||
|
|
||
| Boolean useJobRegex = DatadogUtilities.getDatadogDescriptor().getJobRegex(); |
| * @param jobName - A string containing the name of some job | ||
| * @return - A Map of values containing the key and value of each Datadog tag to apply to the metric/event | ||
| */ | ||
| public static Map<String,String> getRegexJobTags(final String jobName) { |
There was a problem hiding this comment.
I don't think final is needed here either. final would be needed if there would be an interface defining the method signature as such. final only prevent for params to be reassigned within the method itself and only for its scope. Thus, it's only really useful when defined in interfaces.
| try { | ||
| tags.put(tagItem[0], m.group(Character.getNumericValue(tagItem[1].charAt(1)))); | ||
| } catch(IndexOutOfBoundsException e) { | ||
| logger.fine(String.format("Specified a capture group that doesn't exist, not applying tag: " + Arrays.toString(tagItem) + " " + e)); |
There was a problem hiding this comment.
Could use StringBuffer here
There was a problem hiding this comment.
There should be a non trivial performance bump by changing all of the String.format to something like StringBuilder or StringBuffer. We should change all occurrences in a separate PR though as it seems a little out of scope here.
There was a problem hiding this comment.
ok but then either you use format or + sign concatenation but both doesn't make sense to me.
| final List<String> blacklist = DatadogUtilities.joblistStringtoList( DatadogUtilities.getBlacklist() ); | ||
|
|
||
| return blacklist.contains(jobName.toLowerCase()); | ||
| public static boolean isJobBlacklisted(final String jobName) { |
There was a problem hiding this comment.
ditto and everywhere else :)
|
|
||
| private JSONObject builddata; | ||
| private HashMap<String,String> tags; | ||
| private Map<String,String> tags; |
gzussa
left a comment
There was a problem hiding this comment.
Some more comments. Also, you should do a grep "final" and remove it everywhere (unless if it is required by an interface)
| /** | ||
| * Setter function for the {@link jobRegex} global configuration, | ||
| * accepting a boolean value (checkbox) | ||
| * Getter function for the {@link globalJobTags} global configuration, containing |
There was a problem hiding this comment.
👍 nice! didn't even saw that. Good catch 😸
| this.setGlobalJobTags(formData.getString("globalJobTags")); | ||
|
|
||
| // Grab tagNode and coerse to a boolean | ||
| if ( formData.getString("tagNode").equals("true") ) { |
There was a problem hiding this comment.
in case there is a null, you should do "true".equals(formData.getString("jobRegex"))
| try { | ||
| tags.put(tagItem[0], m.group(Character.getNumericValue(tagItem[1].charAt(1)))); | ||
| } catch(IndexOutOfBoundsException e) { | ||
| logger.fine(String.format("Specified a capture group that doesn't exist, not applying tag: " + Arrays.toString(tagItem) + " " + e)); |
There was a problem hiding this comment.
ok but then either you use format or + sign concatenation but both doesn't make sense to me.
gzussa
left a comment
There was a problem hiding this comment.
Let's get this merged now
|
Thanks for all the feedback. I agree that there should be a followup cleaning PR for a couple of the brought up points 🙇 |
Adds a new textarea in the plugin that allows for the addition for the placement of tags globally for jobs. This supports regex and using capture groups for your tags.
Ex: https://cl.ly/3f3r2h0R1R3q
Additional Notes:
I cleaned up the code a little bit and made the type of some objects the interface instead of the subclass type.
Additionally right now, we iterate and compile the list of jobs on each run. I think ultimately it would be best to create some singleton class that holds the configuration objects and to only compile the list of regexes when the form is re saved/re configured. That seems outside the scope of this PR and there doesn't appear to be a noticeable performance hit.