Skip to content
This repository was archived by the owner on Jan 23, 2020. It is now read-only.

Add support for global tags (including regexes)#117

Merged
sjenriquez merged 10 commits into
masterfrom
nick/add_job_regex_tags
Aug 7, 2018
Merged

Add support for global tags (including regexes)#117
sjenriquez merged 10 commits into
masterfrom
nick/add_job_regex_tags

Conversation

@nmuesch

@nmuesch nmuesch commented Jun 18, 2018

Copy link
Copy Markdown
Contributor

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.

@gzussa gzussa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change Boolean to its primitive. This will avoid creating a new object. Also, do we have to check for null here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}

// Grab jobRegex and coerse to a boolean
if ( formData.getString("jobRegex").equals("true") ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case there is a null, you should do "true".equals(formData.getString("jobRegex"))

@gzussa gzussa Jul 16, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need final?

&& prop != null && prop.isEmitOnCheckout() ) {
logger.fine("Checkout! in onCheckout()");

Boolean useJobRegex = DatadogUtilities.getDatadogDescriptor().getJobRegex();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

* @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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use StringBuffer here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto and everywhere else :)


private JSONObject builddata;
private HashMap<String,String> tags;
private Map<String,String> tags;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@gzussa gzussa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 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") ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok but then either you use format or + sign concatenation but both doesn't make sense to me.

@gzussa gzussa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this merged now

@nmuesch

nmuesch commented Jul 17, 2018

Copy link
Copy Markdown
Contributor Author

Thanks for all the feedback. I agree that there should be a followup cleaning PR for a couple of the brought up points 🙇

@nmuesch nmuesch changed the title Add support for regexes for whitelist/blacklist jobs and global tags Add support for global tags (including regexes) Jul 17, 2018
@sjenriquez
sjenriquez merged commit 48a9843 into master Aug 7, 2018
@sjenriquez
sjenriquez deleted the nick/add_job_regex_tags branch August 7, 2018 18:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants