Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fleet level disable decider logic #377

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.pinterest.singer.config;

import com.pinterest.singer.utils.HashUtils;
import com.pinterest.singer.utils.SingerUtils;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -103,6 +104,11 @@ public Map<String, Integer> getDeciderMap() {
return mDeciderMap;
}

public static String generateDisableDecider(String logName) {
return "singer_disable_" + logName + "___"
+ SingerUtils.getHostnamePrefix().replace('-', '_') + "___decider";
}

/**
* Looks up the value of the decider variable named {@code deciderName} and flips a coin to
* determine if we should be in the experiment based on the specified ID. Useful if a stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class DefaultLogStreamProcessor implements LogStreamProcessor, Runnable {
// Decider for the log stream.
private final String logDecider;

// Decider used in conjunction with logDecider to disable the logstream at a fleet level
jfzunigac marked this conversation as resolved.
Show resolved Hide resolved
private final String fleetDisableDecider;

// LogStream to be processed.
protected final LogStream logStream;

Expand Down Expand Up @@ -165,6 +168,9 @@ public DefaultLogStreamProcessor(
this.exceedTimeSliceLimit = false;
this.lastModificationTimeProcessed = new AtomicLong(-1);
this.lastCompletedCycleTime = new AtomicLong(-1);
this.fleetDisableDecider =
Decider.generateDisableDecider(logStream.getSingerLog().getSingerLogConfig().getName()
.replaceAll("[^a-zA-Z0-9]", "_"));
}

@Override
Expand Down Expand Up @@ -252,6 +258,11 @@ boolean isLoggingAllowedByDecider() {
if (map.containsKey(logDecider)) {
result = map.get(logDecider) != 0;
}
if (result && map.containsKey(fleetDisableDecider) && map.get(fleetDisableDecider) == 100) {
LOG.info("Disabling log stream {} because fleet disable decider {} is set to 100", logStream.getLogStreamName(),
fleetDisableDecider);
result = false;
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ public static String getHostname() {
return hostName;
}

/**
* @return the prefix of the host name
*/
public static String getHostnamePrefix() {
String hostNameStringPrefix = "null";
if (HOSTNAME != null) {
String hostNameToSplit = "";
String[] substrs = HOSTNAME.split("\\d+");
if (substrs.length > 0) {
hostNameToSplit = substrs[0];
}
int dashIndex = hostNameToSplit.lastIndexOf('-');
hostNameStringPrefix = dashIndex == -1 ? hostNameToSplit : hostNameToSplit.substring(0, dashIndex);
}
return hostNameStringPrefix;
}

public static Path getPath(String filePathStr) {
return defaultFileSystem.getPath(filePathStr);
}
Expand Down
Loading