use of org.apache.commons.lang3.ObjectUtils.firstNonNull in project dhis2-core by dhis2.
the class DefaultExpressionService method generateExpression.
/**
* Generates an expression based on the given data maps.
*
* @param expression the expression.
* @param valueMap the value map.
* @param constantMap the constant map.
* @param orgUnitCountMap the organisation unit count map.
* @param days the number of days.
* @param missingValueStrategy the missing value strategy.
* @param aggregateMap the aggregate map.
* @return an expression.
*/
private String generateExpression(String expression, Map<? extends DimensionalItemObject, Double> valueMap, Map<String, Double> constantMap, Map<String, Integer> orgUnitCountMap, Integer days, MissingValueStrategy missingValueStrategy, Map<String, List<Double>> aggregateMap) {
if (expression == null || expression.isEmpty()) {
return null;
}
expression = ExpressionUtils.normalizeExpression(expression);
Map<String, Double> dimensionItemValueMap = valueMap.entrySet().stream().filter(e -> e.getValue() != null).collect(Collectors.toMap(e -> e.getKey().getDimensionItem(), e -> e.getValue()));
missingValueStrategy = ObjectUtils.firstNonNull(missingValueStrategy, NEVER_SKIP);
// ---------------------------------------------------------------------
// Aggregates
// ---------------------------------------------------------------------
StringBuffer sb = new StringBuffer();
Pattern prefix = CustomFunctions.AGGREGATE_PATTERN_PREFIX;
Matcher matcher = prefix.matcher(expression);
int scan = 0, len = expression.length(), tail = 0;
while (scan < len && matcher.find(scan)) {
int start = matcher.end();
int end = Expression.matchExpression(expression, start);
if (end < 0) {
sb.append(expression.substring(scan, start));
scan = start + 1;
tail = start;
} else if (aggregateMap == null || expression.charAt(start) == '<') {
sb.append(expression.substring(scan, end));
scan = end + 1;
tail = end;
} else {
String subExpression = expression.substring(start, end);
List<Double> samples = aggregateMap.get(subExpression);
if (samples == null) {
if (SKIP_IF_ANY_VALUE_MISSING.equals(missingValueStrategy)) {
return null;
}
} else {
String literal = (samples == null) ? ("[]") : (samples.toString());
sb.append(expression.substring(scan, start));
sb.append(literal);
}
scan = end;
tail = end;
}
}
sb.append(expression.substring(tail));
expression = sb.toString();
// ---------------------------------------------------------------------
// DimensionalItemObjects
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = VARIABLE_PATTERN.matcher(expression);
int matchCount = 0;
int valueCount = 0;
while (matcher.find()) {
matchCount++;
String dimItem = matcher.group(GROUP_ID);
final Double value = dimensionItemValueMap.get(dimItem);
boolean missingValue = value == null;
if (missingValue && SKIP_IF_ANY_VALUE_MISSING.equals(missingValueStrategy)) {
return null;
}
if (!missingValue) {
valueCount++;
}
String replacement = value != null ? String.valueOf(value) : NULL_REPLACEMENT;
matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
}
if (SKIP_IF_ALL_VALUES_MISSING.equals(missingValueStrategy) && matchCount > 0 && valueCount == 0) {
return null;
}
expression = TextUtils.appendTail(matcher, sb);
// ---------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = CONSTANT_PATTERN.matcher(expression);
while (matcher.find()) {
final Double constant = constantMap != null ? constantMap.get(matcher.group(GROUP_ID)) : null;
String replacement = constant != null ? String.valueOf(constant) : NULL_REPLACEMENT;
matcher.appendReplacement(sb, replacement);
}
expression = TextUtils.appendTail(matcher, sb);
// ---------------------------------------------------------------------
// Org unit groups
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = OU_GROUP_PATTERN.matcher(expression);
while (matcher.find()) {
final Integer count = orgUnitCountMap != null ? orgUnitCountMap.get(matcher.group(GROUP_ID)) : null;
String replacement = count != null ? String.valueOf(count) : NULL_REPLACEMENT;
matcher.appendReplacement(sb, replacement);
}
expression = TextUtils.appendTail(matcher, sb);
// ---------------------------------------------------------------------
// Days
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = DAYS_PATTERN.matcher(expression);
while (matcher.find()) {
String replacement = days != null ? String.valueOf(days) : NULL_REPLACEMENT;
matcher.appendReplacement(sb, replacement);
}
return TextUtils.appendTail(matcher, sb);
}
use of org.apache.commons.lang3.ObjectUtils.firstNonNull in project hmftools by hartwigmedical.
the class BreakPointInspectorApplication method main.
public static void main(final String... args) throws IOException {
final AnalysisBuilder analysisBuilder = new AnalysisBuilder();
final Options options = createOptions();
try {
final CommandLine cmd = createCommandLine(options, args);
final String refPath = cmd.getOptionValue(REF_PATH);
final String refSlicePath = cmd.getOptionValue(REF_SLICE);
final String tumorPath = cmd.getOptionValue(TUMOR_PATH);
final String tumorSlicePath = cmd.getOptionValue(TUMOR_SLICE);
final String vcfPath = cmd.getOptionValue(VCF);
if (cmd.hasOption(PROXIMITY)) {
analysisBuilder.setRange(Integer.parseInt(cmd.getOptionValue(PROXIMITY, "500")));
}
if (cmd.hasOption(CONTAMINATION)) {
analysisBuilder.setContaminationFraction(Float.parseFloat(cmd.getOptionValue(CONTAMINATION, "0")));
}
if (refPath == null || tumorPath == null || vcfPath == null) {
printHelpAndExit(options);
return;
}
final File tumorBAM = new File(tumorPath);
final SamReader tumorReader = SamReaderFactory.makeDefault().open(tumorBAM);
final File refBAM = new File(refPath);
final SamReader refReader = SamReaderFactory.makeDefault().open(refBAM);
final File vcfFile = new File(vcfPath);
final VCFFileReader vcfReader = new VCFFileReader(vcfFile, false);
final List<String> samples = vcfReader.getFileHeader().getGenotypeSamples();
if (samples.size() != 2) {
System.err.println("could not determine tumor and sample from VCF");
System.exit(1);
return;
}
TSVOutput.PrintHeaders();
final Analysis analysis = analysisBuilder.setRefReader(refReader).setTumorReader(tumorReader).createAnalysis();
final List<QueryInterval> combinedQueryIntervals = Lists.newArrayList();
final Map<String, VariantContext> variantMap = new HashMap<>();
final List<VariantContext> variants = Lists.newArrayList();
for (VariantContext variant : vcfReader) {
variantMap.put(variant.getID(), variant);
final VariantContext mateVariant = variant;
if (variant.hasAttribute("MATEID")) {
variant = variantMap.get(variant.getAttributeAsString("MATEID", ""));
if (variant == null) {
continue;
}
}
final String location = variant.getContig() + ":" + Integer.toString(variant.getStart());
final Location location1 = Location.parseLocationString(location, tumorReader.getFileHeader().getSequenceDictionary());
final Range uncertainty1 = extractCIPOS(variant);
final List<Integer> CIEND = variant.getAttributeAsIntList("CIEND", 0);
Range uncertainty2 = CIEND.size() == 2 ? new Range(CIEND.get(0), CIEND.get(1)) : null;
final boolean IMPRECISE = variant.hasAttribute("IMPRECISE");
HMFVariantType svType;
final Location location2;
switch(variant.getStructuralVariantType()) {
case INS:
svType = HMFVariantType.INS;
location2 = location1.set(variant.getAttributeAsInt("END", 0));
break;
case INV:
if (variant.hasAttribute("INV3")) {
svType = HMFVariantType.INV3;
} else if (variant.hasAttribute("INV5")) {
svType = HMFVariantType.INV5;
} else {
System.err.println(variant.getID() + " : expected either INV3 or INV5 flag");
continue;
}
location2 = location1.add(Math.abs(variant.getAttributeAsInt("SVLEN", 0)));
break;
case DEL:
svType = HMFVariantType.DEL;
location2 = location1.add(Math.abs(variant.getAttributeAsInt("SVLEN", 0)));
break;
case DUP:
svType = HMFVariantType.DUP;
location2 = location1.add(Math.abs(variant.getAttributeAsInt("SVLEN", 0)));
break;
case BND:
// process the breakend string
final String call = variant.getAlternateAllele(0).getDisplayString();
final String[] leftSplit = call.split("\\]");
final String[] rightSplit = call.split("\\[");
if (leftSplit.length >= 2) {
location2 = Location.parseLocationString(leftSplit[1], tumorReader.getFileHeader().getSequenceDictionary());
if (leftSplit[0].length() > 0) {
svType = HMFVariantType.INV3;
uncertainty2 = Range.invert(uncertainty1);
} else {
svType = HMFVariantType.DUP;
uncertainty2 = uncertainty1;
}
} else if (rightSplit.length >= 2) {
location2 = Location.parseLocationString(rightSplit[1], tumorReader.getFileHeader().getSequenceDictionary());
if (rightSplit[0].length() > 0) {
svType = HMFVariantType.DEL;
uncertainty2 = uncertainty1;
} else {
svType = HMFVariantType.INV5;
uncertainty2 = Range.invert(uncertainty1);
}
} else {
System.err.println(variant.getID() + " : could not parse breakpoint");
continue;
}
if (IMPRECISE) {
uncertainty2 = extractCIPOS(mateVariant);
}
break;
default:
System.err.println(variant.getID() + " : UNEXPECTED SVTYPE=" + variant.getStructuralVariantType());
continue;
}
final HMFVariantContext ctx = new HMFVariantContext(variant.getID(), location1, location2, svType, IMPRECISE);
ctx.Filter.addAll(variant.getFilters().stream().filter(s -> !s.startsWith("BPI")).collect(Collectors.toSet()));
ctx.Uncertainty1 = uncertainty1;
ctx.Uncertainty2 = ObjectUtils.firstNonNull(uncertainty2, fixup(uncertainty1, IMPRECISE, svType == HMFVariantType.INV3 || svType == HMFVariantType.INV5));
ctx.HomologySequence = variant.getAttributeAsString("HOMSEQ", "");
if (variant.hasAttribute("LEFT_SVINSSEQ") && variant.hasAttribute("RIGHT_SVINSSEQ")) {
ctx.InsertSequence = variant.getAttributeAsString("LEFT_SVINSSEQ", "") + "..." + variant.getAttributeAsString("RIGHT_SVINSSEQ", "");
} else {
ctx.InsertSequence = variant.getAttributeAsString("SVINSSEQ", "");
}
ctx.BND = variant.getStructuralVariantType() == StructuralVariantType.BND;
switch(ctx.Type) {
case INS:
case DEL:
ctx.OrientationBP1 = 1;
ctx.OrientationBP2 = -1;
break;
case INV3:
ctx.OrientationBP1 = 1;
ctx.OrientationBP2 = 1;
break;
case INV5:
ctx.OrientationBP1 = -1;
ctx.OrientationBP2 = -1;
break;
case DUP:
ctx.OrientationBP1 = -1;
ctx.OrientationBP2 = 1;
break;
}
final StructuralVariantResult result = analysis.processStructuralVariant(ctx);
combinedQueryIntervals.addAll(asList(result.QueryIntervals));
TSVOutput.print(variant, ctx, result);
final BiConsumer<VariantContext, Boolean> vcfUpdater = (v, swap) -> {
final Set<String> filters = v.getCommonInfo().getFiltersMaybeNull();
if (filters != null) {
filters.clear();
}
// we will map BreakpointError to a flag
if (result.Filters.contains(Filter.Filters.BreakpointError.toString())) {
v.getCommonInfo().putAttribute("BPI_AMBIGUOUS", true, true);
} else {
v.getCommonInfo().addFilters(result.Filters);
}
if (result.Filters.isEmpty()) {
final List<Double> af = asList(result.AlleleFrequency.getLeft(), result.AlleleFrequency.getRight());
v.getCommonInfo().putAttribute(AlleleFrequency.VCF_INFO_TAG, swap ? Lists.reverse(af) : af, true);
}
if (result.Breakpoints.getLeft() != null) {
v.getCommonInfo().putAttribute(swap ? "BPI_END" : "BPI_START", result.Breakpoints.getLeft().Position, true);
}
if (result.Breakpoints.getRight() != null) {
v.getCommonInfo().putAttribute(swap ? "BPI_START" : "BPI_END", result.Breakpoints.getRight().Position, true);
}
// remove CIPOS / CIEND when we have an insert sequence
if (!v.hasAttribute("IMPRECISE") && v.hasAttribute("SVINSSEQ")) {
v.getCommonInfo().removeAttribute("CIPOS");
v.getCommonInfo().removeAttribute("CIEND");
}
variants.add(v);
};
vcfUpdater.accept(variant, false);
if (mateVariant != variant) {
vcfUpdater.accept(mateVariant, true);
}
}
// TODO: update START, END with BPI values and save Manta values in new attributes
final String vcfOutputPath = cmd.getOptionValue(VCF_OUT);
if (vcfOutputPath != null) {
final VCFHeader header = vcfReader.getFileHeader();
header.addMetaDataLine(new VCFInfoHeaderLine("BPI_START", 1, VCFHeaderLineType.Integer, "BPI adjusted breakend location"));
header.addMetaDataLine(new VCFInfoHeaderLine("BPI_END", 1, VCFHeaderLineType.Integer, "BPI adjusted breakend location"));
header.addMetaDataLine(new VCFInfoHeaderLine("BPI_AMBIGUOUS", 0, VCFHeaderLineType.Flag, "BPI could not determine the breakpoints, inspect manually"));
header.addMetaDataLine(new VCFHeaderLine("bpiVersion", BreakPointInspectorApplication.class.getPackage().getImplementationVersion()));
Filter.UpdateVCFHeader(header);
AlleleFrequency.UpdateVCFHeader(header);
// setup VCF
final VariantContextWriter writer = new VariantContextWriterBuilder().setReferenceDictionary(header.getSequenceDictionary()).setOutputFile(vcfOutputPath).build();
writer.writeHeader(header);
// write variants
variants.sort(new VariantContextComparator(header.getSequenceDictionary()));
variants.forEach(writer::add);
writer.close();
}
final QueryInterval[] optimizedIntervals = QueryInterval.optimizeIntervals(combinedQueryIntervals.toArray(new QueryInterval[combinedQueryIntervals.size()]));
if (tumorSlicePath != null) {
writeToSlice(tumorSlicePath, tumorReader, optimizedIntervals);
}
if (refSlicePath != null) {
writeToSlice(refSlicePath, refReader, optimizedIntervals);
}
refReader.close();
tumorReader.close();
} catch (ParseException e) {
printHelpAndExit(options);
System.exit(1);
}
}
use of org.apache.commons.lang3.ObjectUtils.firstNonNull in project dhis2-core by dhis2.
the class JdbcRawAnalyticsManager method getSelectStatement.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Returns a SQL select statement.
*
* @param params the data query parameters.
* @param dimensions the list of dimensions.
* @return a SQL select statement.
*/
private String getSelectStatement(DataQueryParams params, List<DimensionalObject> dimensions) {
String idScheme = ObjectUtils.firstNonNull(params.getOutputIdScheme(), IdScheme.UID).getIdentifiableString().toLowerCase();
List<String> dimensionColumns = dimensions.stream().map(d -> asColumnSelect(d, idScheme)).collect(Collectors.toList());
SqlHelper sqlHelper = new SqlHelper();
String sql = "select " + StringUtils.join(dimensionColumns, ", ") + ", " + DIM_NAME_OU + ", value " + "from " + params.getTableName() + " as " + ANALYTICS_TBL_ALIAS + " " + "inner join organisationunit ou on ax.ou = ou.uid " + "inner join _orgunitstructure ous on ax.ou = ous.organisationunituid " + "inner join _periodstructure ps on ax.pe = ps.iso ";
for (DimensionalObject dim : dimensions) {
if (!dim.getItems().isEmpty() && !dim.isFixed()) {
String col = quote(dim.getDimensionName());
if (DimensionalObject.ORGUNIT_DIM_ID.equals(dim.getDimension())) {
sql += sqlHelper.whereAnd() + " (";
for (DimensionalItemObject item : dim.getItems()) {
OrganisationUnit unit = (OrganisationUnit) item;
sql += DIM_NAME_OU + " like '" + unit.getPath() + "%' or ";
}
sql = TextUtils.removeLastOr(sql) + ") ";
} else {
sql += sqlHelper.whereAnd() + " " + col + " in (" + getQuotedCommaDelimitedString(getUids(dim.getItems())) + ") ";
}
}
}
sql += sqlHelper.whereAnd() + " " + "ps.startdate >= '" + DateUtils.getMediumDateString(params.getStartDate()) + "' and " + "ps.enddate <= '" + DateUtils.getMediumDateString(params.getEndDate()) + "' ";
return sql;
}
use of org.apache.commons.lang3.ObjectUtils.firstNonNull in project alf.io by alfio-event.
the class EventManager method updateEventHeader.
public void updateEventHeader(Event original, EventModification em, String username) {
IntPredicate ownershipChecker = checkOwnershipByOrgId(username, organizationRepository);
boolean sameOrganization = original.getOrganizationId() == em.getOrganizationId();
Validate.isTrue(ownershipChecker.test(original.getOrganizationId()) && (sameOrganization || ownershipChecker.test(em.getOrganizationId())), "Invalid organizationId");
int eventId = original.getId();
Validate.isTrue(sameOrganization || groupRepository.countByEventId(eventId) == 0, "Cannot change organization because there is a group linked to this event.");
Validate.isTrue(sameOrganization || !subscriptionRepository.hasLinkedSubscription(eventId), "Cannot change organization because there are one or more subscriptions linked.");
boolean formatUpdated = em.getFormat() != original.getFormat();
if (em.getFormat() == EventFormat.ONLINE && formatUpdated) {
Validate.isTrue(original.getAllowedPaymentProxies().stream().allMatch(p -> p != PaymentProxy.ON_SITE), ERROR_ONLINE_ON_SITE_NOT_COMPATIBLE);
}
String timeZone = ObjectUtils.firstNonNull(em.getZoneId(), em.getGeolocation() != null ? em.getGeolocation().getTimeZone() : null);
String latitude = ObjectUtils.firstNonNull(em.getLatitude(), em.getGeolocation() != null ? em.getGeolocation().getLatitude() : null);
String longitude = ObjectUtils.firstNonNull(em.getLongitude(), em.getGeolocation() != null ? em.getGeolocation().getLongitude() : null);
final ZoneId zoneId = ZoneId.of(timeZone);
final ZonedDateTime begin = em.getBegin().toZonedDateTime(zoneId);
final ZonedDateTime end = em.getEnd().toZonedDateTime(zoneId);
eventRepository.updateHeader(eventId, em.getDisplayName(), em.getWebsiteUrl(), em.getExternalUrl(), em.getTermsAndConditionsUrl(), em.getPrivacyPolicyUrl(), em.getImageUrl(), em.getFileBlobId(), em.getLocation(), latitude, longitude, begin, end, timeZone, em.getOrganizationId(), em.getLocales(), em.getFormat());
createOrUpdateEventDescription(eventId, em);
if (!original.getBegin().equals(begin) || !original.getEnd().equals(end)) {
fixOutOfRangeCategories(em, username, zoneId, end);
}
if (formatUpdated) {
// update ticket access type for categories if the format has been updated
var ticketAccessType = evaluateTicketAccessType(original.getFormat(), em.getFormat());
ticketCategoryRepository.updateTicketAccessTypeForEvent(eventId, ticketAccessType);
}
extensionManager.handleEventHeaderUpdate(eventRepository.findById(eventId), organizationRepository.findOrganizationForUser(username, em.getOrganizationId()).orElseThrow());
}
use of org.apache.commons.lang3.ObjectUtils.firstNonNull in project java by wavefrontHQ.
the class ProxyConfig method verifyAndInit.
@Override
public void verifyAndInit() {
if (unparsed_params != null) {
logger.info("Unparsed arguments: " + Joiner.on(", ").join(unparsed_params));
}
ReportableConfig config;
// If they've specified a push configuration file, override the command line values
try {
if (pushConfigFile != null) {
config = new ReportableConfig(pushConfigFile);
} else {
// dummy config
config = new ReportableConfig();
}
prefix = Strings.emptyToNull(config.getString("prefix", prefix));
// don't track token in proxy config metrics
token = ObjectUtils.firstNonNull(config.getRawProperty("token", token), "undefined").trim();
server = config.getString("server", server);
hostname = config.getString("hostname", hostname);
idFile = config.getString("idFile", idFile);
pushRateLimit = config.getInteger("pushRateLimit", pushRateLimit);
pushRateLimitHistograms = config.getInteger("pushRateLimitHistograms", pushRateLimitHistograms);
pushRateLimitSourceTags = config.getDouble("pushRateLimitSourceTags", pushRateLimitSourceTags);
pushRateLimitSpans = config.getInteger("pushRateLimitSpans", pushRateLimitSpans);
pushRateLimitSpanLogs = config.getInteger("pushRateLimitSpanLogs", pushRateLimitSpanLogs);
pushRateLimitEvents = config.getDouble("pushRateLimitEvents", pushRateLimitEvents);
pushRateLimitMaxBurstSeconds = config.getInteger("pushRateLimitMaxBurstSeconds", pushRateLimitMaxBurstSeconds);
pushBlockedSamples = config.getInteger("pushBlockedSamples", pushBlockedSamples);
blockedPointsLoggerName = config.getString("blockedPointsLoggerName", blockedPointsLoggerName);
blockedHistogramsLoggerName = config.getString("blockedHistogramsLoggerName", blockedHistogramsLoggerName);
blockedSpansLoggerName = config.getString("blockedSpansLoggerName", blockedSpansLoggerName);
pushListenerPorts = config.getString("pushListenerPorts", pushListenerPorts);
pushListenerMaxReceivedLength = config.getInteger("pushListenerMaxReceivedLength", pushListenerMaxReceivedLength);
pushListenerHttpBufferSize = config.getInteger("pushListenerHttpBufferSize", pushListenerHttpBufferSize);
traceListenerMaxReceivedLength = config.getInteger("traceListenerMaxReceivedLength", traceListenerMaxReceivedLength);
traceListenerHttpBufferSize = config.getInteger("traceListenerHttpBufferSize", traceListenerHttpBufferSize);
listenerIdleConnectionTimeout = config.getInteger("listenerIdleConnectionTimeout", listenerIdleConnectionTimeout);
memGuardFlushThreshold = config.getInteger("memGuardFlushThreshold", memGuardFlushThreshold);
// Histogram: global settings
histogramPassthroughRecompression = config.getBoolean("histogramPassthroughRecompression", histogramPassthroughRecompression);
histogramStateDirectory = config.getString("histogramStateDirectory", histogramStateDirectory);
histogramAccumulatorResolveInterval = config.getLong("histogramAccumulatorResolveInterval", histogramAccumulatorResolveInterval);
histogramAccumulatorFlushInterval = config.getLong("histogramAccumulatorFlushInterval", histogramAccumulatorFlushInterval);
histogramAccumulatorFlushMaxBatchSize = config.getInteger("histogramAccumulatorFlushMaxBatchSize", histogramAccumulatorFlushMaxBatchSize);
histogramMaxReceivedLength = config.getInteger("histogramMaxReceivedLength", histogramMaxReceivedLength);
histogramHttpBufferSize = config.getInteger("histogramHttpBufferSize", histogramHttpBufferSize);
deltaCountersAggregationListenerPorts = config.getString("deltaCountersAggregationListenerPorts", deltaCountersAggregationListenerPorts);
deltaCountersAggregationIntervalSeconds = config.getLong("deltaCountersAggregationIntervalSeconds", deltaCountersAggregationIntervalSeconds);
customTracingListenerPorts = config.getString("customTracingListenerPorts", customTracingListenerPorts);
// Histogram: deprecated settings - fall back for backwards compatibility
if (config.isDefined("avgHistogramKeyBytes")) {
histogramMinuteAvgKeyBytes = histogramHourAvgKeyBytes = histogramDayAvgKeyBytes = histogramDistAvgKeyBytes = config.getInteger("avgHistogramKeyBytes", 150);
}
if (config.isDefined("avgHistogramDigestBytes")) {
histogramMinuteAvgDigestBytes = histogramHourAvgDigestBytes = histogramDayAvgDigestBytes = histogramDistAvgDigestBytes = config.getInteger("avgHistogramDigestBytes", 500);
}
if (config.isDefined("histogramAccumulatorSize")) {
histogramMinuteAccumulatorSize = histogramHourAccumulatorSize = histogramDayAccumulatorSize = histogramDistAccumulatorSize = config.getLong("histogramAccumulatorSize", 100000);
}
if (config.isDefined("histogramCompression")) {
histogramMinuteCompression = histogramHourCompression = histogramDayCompression = histogramDistCompression = config.getNumber("histogramCompression", null, 20, 1000).shortValue();
}
if (config.isDefined("persistAccumulator")) {
histogramMinuteAccumulatorPersisted = histogramHourAccumulatorPersisted = histogramDayAccumulatorPersisted = histogramDistAccumulatorPersisted = config.getBoolean("persistAccumulator", false);
}
// Histogram: minute accumulator settings
histogramMinuteListenerPorts = config.getString("histogramMinuteListenerPorts", histogramMinuteListenerPorts);
histogramMinuteFlushSecs = config.getInteger("histogramMinuteFlushSecs", histogramMinuteFlushSecs);
histogramMinuteCompression = config.getNumber("histogramMinuteCompression", histogramMinuteCompression, 20, 1000).shortValue();
histogramMinuteAvgKeyBytes = config.getInteger("histogramMinuteAvgKeyBytes", histogramMinuteAvgKeyBytes);
histogramMinuteAvgDigestBytes = 32 + histogramMinuteCompression * 7;
histogramMinuteAvgDigestBytes = config.getInteger("histogramMinuteAvgDigestBytes", histogramMinuteAvgDigestBytes);
histogramMinuteAccumulatorSize = config.getLong("histogramMinuteAccumulatorSize", histogramMinuteAccumulatorSize);
histogramMinuteAccumulatorPersisted = config.getBoolean("histogramMinuteAccumulatorPersisted", histogramMinuteAccumulatorPersisted);
histogramMinuteMemoryCache = config.getBoolean("histogramMinuteMemoryCache", histogramMinuteMemoryCache);
// Histogram: hour accumulator settings
histogramHourListenerPorts = config.getString("histogramHourListenerPorts", histogramHourListenerPorts);
histogramHourFlushSecs = config.getInteger("histogramHourFlushSecs", histogramHourFlushSecs);
histogramHourCompression = config.getNumber("histogramHourCompression", histogramHourCompression, 20, 1000).shortValue();
histogramHourAvgKeyBytes = config.getInteger("histogramHourAvgKeyBytes", histogramHourAvgKeyBytes);
histogramHourAvgDigestBytes = 32 + histogramHourCompression * 7;
histogramHourAvgDigestBytes = config.getInteger("histogramHourAvgDigestBytes", histogramHourAvgDigestBytes);
histogramHourAccumulatorSize = config.getLong("histogramHourAccumulatorSize", histogramHourAccumulatorSize);
histogramHourAccumulatorPersisted = config.getBoolean("histogramHourAccumulatorPersisted", histogramHourAccumulatorPersisted);
histogramHourMemoryCache = config.getBoolean("histogramHourMemoryCache", histogramHourMemoryCache);
// Histogram: day accumulator settings
histogramDayListenerPorts = config.getString("histogramDayListenerPorts", histogramDayListenerPorts);
histogramDayFlushSecs = config.getInteger("histogramDayFlushSecs", histogramDayFlushSecs);
histogramDayCompression = config.getNumber("histogramDayCompression", histogramDayCompression, 20, 1000).shortValue();
histogramDayAvgKeyBytes = config.getInteger("histogramDayAvgKeyBytes", histogramDayAvgKeyBytes);
histogramDayAvgDigestBytes = 32 + histogramDayCompression * 7;
histogramDayAvgDigestBytes = config.getInteger("histogramDayAvgDigestBytes", histogramDayAvgDigestBytes);
histogramDayAccumulatorSize = config.getLong("histogramDayAccumulatorSize", histogramDayAccumulatorSize);
histogramDayAccumulatorPersisted = config.getBoolean("histogramDayAccumulatorPersisted", histogramDayAccumulatorPersisted);
histogramDayMemoryCache = config.getBoolean("histogramDayMemoryCache", histogramDayMemoryCache);
// Histogram: dist accumulator settings
histogramDistListenerPorts = config.getString("histogramDistListenerPorts", histogramDistListenerPorts);
histogramDistFlushSecs = config.getInteger("histogramDistFlushSecs", histogramDistFlushSecs);
histogramDistCompression = config.getNumber("histogramDistCompression", histogramDistCompression, 20, 1000).shortValue();
histogramDistAvgKeyBytes = config.getInteger("histogramDistAvgKeyBytes", histogramDistAvgKeyBytes);
histogramDistAvgDigestBytes = 32 + histogramDistCompression * 7;
histogramDistAvgDigestBytes = config.getInteger("histogramDistAvgDigestBytes", histogramDistAvgDigestBytes);
histogramDistAccumulatorSize = config.getLong("histogramDistAccumulatorSize", histogramDistAccumulatorSize);
histogramDistAccumulatorPersisted = config.getBoolean("histogramDistAccumulatorPersisted", histogramDistAccumulatorPersisted);
histogramDistMemoryCache = config.getBoolean("histogramDistMemoryCache", histogramDistMemoryCache);
exportQueuePorts = config.getString("exportQueuePorts", exportQueuePorts);
exportQueueOutputFile = config.getString("exportQueueOutputFile", exportQueueOutputFile);
exportQueueRetainData = config.getBoolean("exportQueueRetainData", exportQueueRetainData);
useNoopSender = config.getBoolean("useNoopSender", useNoopSender);
flushThreads = config.getInteger("flushThreads", flushThreads);
flushThreadsEvents = config.getInteger("flushThreadsEvents", flushThreadsEvents);
flushThreadsSourceTags = config.getInteger("flushThreadsSourceTags", flushThreadsSourceTags);
jsonListenerPorts = config.getString("jsonListenerPorts", jsonListenerPorts);
writeHttpJsonListenerPorts = config.getString("writeHttpJsonListenerPorts", writeHttpJsonListenerPorts);
dataDogJsonPorts = config.getString("dataDogJsonPorts", dataDogJsonPorts);
dataDogRequestRelayTarget = config.getString("dataDogRequestRelayTarget", dataDogRequestRelayTarget);
dataDogRequestRelayAsyncThreads = config.getInteger("dataDogRequestRelayAsyncThreads", dataDogRequestRelayAsyncThreads);
dataDogRequestRelaySyncMode = config.getBoolean("dataDogRequestRelaySyncMode", dataDogRequestRelaySyncMode);
dataDogProcessSystemMetrics = config.getBoolean("dataDogProcessSystemMetrics", dataDogProcessSystemMetrics);
dataDogProcessServiceChecks = config.getBoolean("dataDogProcessServiceChecks", dataDogProcessServiceChecks);
graphitePorts = config.getString("graphitePorts", graphitePorts);
graphiteFormat = config.getString("graphiteFormat", graphiteFormat);
graphiteFieldsToRemove = config.getString("graphiteFieldsToRemove", graphiteFieldsToRemove);
graphiteDelimiters = config.getString("graphiteDelimiters", graphiteDelimiters);
allowRegex = config.getString("allowRegex", config.getString("whitelistRegex", allowRegex));
blockRegex = config.getString("blockRegex", config.getString("blacklistRegex", blockRegex));
opentsdbPorts = config.getString("opentsdbPorts", opentsdbPorts);
opentsdbAllowRegex = config.getString("opentsdbAllowRegex", config.getString("opentsdbWhitelistRegex", opentsdbAllowRegex));
opentsdbBlockRegex = config.getString("opentsdbBlockRegex", config.getString("opentsdbBlacklistRegex", opentsdbBlockRegex));
proxyHost = config.getString("proxyHost", proxyHost);
proxyPort = config.getInteger("proxyPort", proxyPort);
proxyPassword = config.getString("proxyPassword", proxyPassword, s -> "<removed>");
proxyUser = config.getString("proxyUser", proxyUser);
httpUserAgent = config.getString("httpUserAgent", httpUserAgent);
httpConnectTimeout = config.getInteger("httpConnectTimeout", httpConnectTimeout);
httpRequestTimeout = config.getInteger("httpRequestTimeout", httpRequestTimeout);
httpMaxConnTotal = Math.min(200, config.getInteger("httpMaxConnTotal", httpMaxConnTotal));
httpMaxConnPerRoute = Math.min(100, config.getInteger("httpMaxConnPerRoute", httpMaxConnPerRoute));
httpAutoRetries = config.getInteger("httpAutoRetries", httpAutoRetries);
gzipCompression = config.getBoolean("gzipCompression", gzipCompression);
gzipCompressionLevel = config.getNumber("gzipCompressionLevel", gzipCompressionLevel, 1, 9).intValue();
soLingerTime = config.getInteger("soLingerTime", soLingerTime);
splitPushWhenRateLimited = config.getBoolean("splitPushWhenRateLimited", splitPushWhenRateLimited);
customSourceTags = config.getString("customSourceTags", customSourceTags);
agentMetricsPointTags = config.getString("agentMetricsPointTags", agentMetricsPointTags);
ephemeral = config.getBoolean("ephemeral", ephemeral);
disableRdnsLookup = config.getBoolean("disableRdnsLookup", disableRdnsLookup);
picklePorts = config.getString("picklePorts", picklePorts);
traceListenerPorts = config.getString("traceListenerPorts", traceListenerPorts);
traceJaegerListenerPorts = config.getString("traceJaegerListenerPorts", traceJaegerListenerPorts);
traceJaegerHttpListenerPorts = config.getString("traceJaegerHttpListenerPorts", traceJaegerHttpListenerPorts);
traceJaegerGrpcListenerPorts = config.getString("traceJaegerGrpcListenerPorts", traceJaegerGrpcListenerPorts);
traceJaegerApplicationName = config.getString("traceJaegerApplicationName", traceJaegerApplicationName);
traceZipkinListenerPorts = config.getString("traceZipkinListenerPorts", traceZipkinListenerPorts);
traceZipkinApplicationName = config.getString("traceZipkinApplicationName", traceZipkinApplicationName);
customTracingListenerPorts = config.getString("customTracingListenerPorts", customTracingListenerPorts);
customTracingApplicationName = config.getString("customTracingApplicationName", customTracingApplicationName);
customTracingServiceName = config.getString("customTracingServiceName", customTracingServiceName);
traceSamplingRate = config.getDouble("traceSamplingRate", traceSamplingRate);
traceSamplingDuration = config.getInteger("traceSamplingDuration", traceSamplingDuration);
traceDerivedCustomTagKeys = config.getString("traceDerivedCustomTagKeys", traceDerivedCustomTagKeys);
backendSpanHeadSamplingPercentIgnored = config.getBoolean("backendSpanHeadSamplingPercentIgnored", backendSpanHeadSamplingPercentIgnored);
pushRelayListenerPorts = config.getString("pushRelayListenerPorts", pushRelayListenerPorts);
pushRelayHistogramAggregator = config.getBoolean("pushRelayHistogramAggregator", pushRelayHistogramAggregator);
pushRelayHistogramAggregatorAccumulatorSize = config.getLong("pushRelayHistogramAggregatorAccumulatorSize", pushRelayHistogramAggregatorAccumulatorSize);
pushRelayHistogramAggregatorFlushSecs = config.getInteger("pushRelayHistogramAggregatorFlushSecs", pushRelayHistogramAggregatorFlushSecs);
pushRelayHistogramAggregatorCompression = config.getNumber("pushRelayHistogramAggregatorCompression", pushRelayHistogramAggregatorCompression).shortValue();
bufferFile = config.getString("buffer", bufferFile);
bufferShardSize = config.getInteger("bufferShardSize", bufferShardSize);
disableBufferSharding = config.getBoolean("disableBufferSharding", disableBufferSharding);
taskQueueLevel = TaskQueueLevel.fromString(config.getString("taskQueueStrategy", taskQueueLevel.toString()));
purgeBuffer = config.getBoolean("purgeBuffer", purgeBuffer);
preprocessorConfigFile = config.getString("preprocessorConfigFile", preprocessorConfigFile);
dataBackfillCutoffHours = config.getInteger("dataBackfillCutoffHours", dataBackfillCutoffHours);
dataPrefillCutoffHours = config.getInteger("dataPrefillCutoffHours", dataPrefillCutoffHours);
filebeatPort = config.getInteger("filebeatPort", filebeatPort);
rawLogsPort = config.getInteger("rawLogsPort", rawLogsPort);
rawLogsMaxReceivedLength = config.getInteger("rawLogsMaxReceivedLength", rawLogsMaxReceivedLength);
rawLogsHttpBufferSize = config.getInteger("rawLogsHttpBufferSize", rawLogsHttpBufferSize);
logsIngestionConfigFile = config.getString("logsIngestionConfigFile", logsIngestionConfigFile);
sqsQueueBuffer = config.getBoolean("sqsBuffer", sqsQueueBuffer);
sqsQueueNameTemplate = config.getString("sqsQueueNameTemplate", sqsQueueNameTemplate);
sqsQueueRegion = config.getString("sqsQueueRegion", sqsQueueRegion);
sqsQueueIdentifier = config.getString("sqsQueueIdentifier", sqsQueueIdentifier);
// auth settings
authMethod = TokenValidationMethod.fromString(config.getString("authMethod", authMethod.toString()));
authTokenIntrospectionServiceUrl = config.getString("authTokenIntrospectionServiceUrl", authTokenIntrospectionServiceUrl);
authTokenIntrospectionAuthorizationHeader = config.getString("authTokenIntrospectionAuthorizationHeader", authTokenIntrospectionAuthorizationHeader);
authResponseRefreshInterval = config.getInteger("authResponseRefreshInterval", authResponseRefreshInterval);
authResponseMaxTtl = config.getInteger("authResponseMaxTtl", authResponseMaxTtl);
authStaticToken = config.getString("authStaticToken", authStaticToken);
// health check / admin API settings
adminApiListenerPort = config.getInteger("adminApiListenerPort", adminApiListenerPort);
adminApiRemoteIpAllowRegex = config.getString("adminApiRemoteIpWhitelistRegex", adminApiRemoteIpAllowRegex);
httpHealthCheckPorts = config.getString("httpHealthCheckPorts", httpHealthCheckPorts);
httpHealthCheckAllPorts = config.getBoolean("httpHealthCheckAllPorts", false);
httpHealthCheckPath = config.getString("httpHealthCheckPath", httpHealthCheckPath);
httpHealthCheckResponseContentType = config.getString("httpHealthCheckResponseContentType", httpHealthCheckResponseContentType);
httpHealthCheckPassStatusCode = config.getInteger("httpHealthCheckPassStatusCode", httpHealthCheckPassStatusCode);
httpHealthCheckPassResponseBody = config.getString("httpHealthCheckPassResponseBody", httpHealthCheckPassResponseBody);
httpHealthCheckFailStatusCode = config.getInteger("httpHealthCheckFailStatusCode", httpHealthCheckFailStatusCode);
httpHealthCheckFailResponseBody = config.getString("httpHealthCheckFailResponseBody", httpHealthCheckFailResponseBody);
// TLS configurations
privateCertPath = config.getString("privateCertPath", privateCertPath);
privateKeyPath = config.getString("privateKeyPath", privateKeyPath);
tlsPorts = config.getString("tlsPorts", tlsPorts);
// Traffic shaping config
trafficShaping = config.getBoolean("trafficShaping", trafficShaping);
trafficShapingWindowSeconds = config.getInteger("trafficShapingWindowSeconds", trafficShapingWindowSeconds);
trafficShapingHeadroom = config.getDouble("trafficShapingHeadroom", trafficShapingHeadroom);
// CORS configuration
corsEnabledPorts = config.getString("corsEnabledPorts", corsEnabledPorts);
corsOrigin = config.getString("corsOrigin", corsOrigin);
corsAllowNullOrigin = config.getBoolean("corsAllowNullOrigin", corsAllowNullOrigin);
// clamp values for pushFlushMaxPoints/etc between min split size
// (or 1 in case of source tags and events) and default batch size.
// also make sure it is never higher than the configured rate limit.
pushFlushMaxPoints = Math.max(Math.min(Math.min(config.getInteger("pushFlushMaxPoints", pushFlushMaxPoints), DEFAULT_BATCH_SIZE), (int) pushRateLimit), DEFAULT_MIN_SPLIT_BATCH_SIZE);
pushFlushMaxHistograms = Math.max(Math.min(Math.min(config.getInteger("pushFlushMaxHistograms", pushFlushMaxHistograms), DEFAULT_BATCH_SIZE_HISTOGRAMS), (int) pushRateLimitHistograms), DEFAULT_MIN_SPLIT_BATCH_SIZE);
pushFlushMaxSourceTags = Math.max(Math.min(Math.min(config.getInteger("pushFlushMaxSourceTags", pushFlushMaxSourceTags), DEFAULT_BATCH_SIZE_SOURCE_TAGS), (int) pushRateLimitSourceTags), 1);
pushFlushMaxSpans = Math.max(Math.min(Math.min(config.getInteger("pushFlushMaxSpans", pushFlushMaxSpans), DEFAULT_BATCH_SIZE_SPANS), (int) pushRateLimitSpans), DEFAULT_MIN_SPLIT_BATCH_SIZE);
pushFlushMaxSpanLogs = Math.max(Math.min(Math.min(config.getInteger("pushFlushMaxSpanLogs", pushFlushMaxSpanLogs), DEFAULT_BATCH_SIZE_SPAN_LOGS), (int) pushRateLimitSpanLogs), DEFAULT_MIN_SPLIT_BATCH_SIZE);
pushFlushMaxEvents = Math.min(Math.min(Math.max(config.getInteger("pushFlushMaxEvents", pushFlushMaxEvents), 1), DEFAULT_BATCH_SIZE_EVENTS), (int) (pushRateLimitEvents + 1));
/*
default value for pushMemoryBufferLimit is 16 * pushFlushMaxPoints, but no more than 25% of
available heap memory. 25% is chosen heuristically as a safe number for scenarios with
limited system resources (4 CPU cores or less, heap size less than 4GB) to prevent OOM.
this is a conservative estimate, budgeting 200 characters (400 bytes) per per point line.
Also, it shouldn't be less than 1 batch size (pushFlushMaxPoints).
*/
int listeningPorts = Iterables.size(Splitter.on(",").omitEmptyStrings().trimResults().split(pushListenerPorts));
long calculatedMemoryBufferLimit = Math.max(Math.min(16 * pushFlushMaxPoints, Runtime.getRuntime().maxMemory() / Math.max(0, listeningPorts) / 4 / flushThreads / 400), pushFlushMaxPoints);
logger.fine("Calculated pushMemoryBufferLimit: " + calculatedMemoryBufferLimit);
pushMemoryBufferLimit = Math.max(config.getInteger("pushMemoryBufferLimit", pushMemoryBufferLimit), pushFlushMaxPoints);
logger.fine("Configured pushMemoryBufferLimit: " + pushMemoryBufferLimit);
pushFlushInterval = config.getInteger("pushFlushInterval", pushFlushInterval);
retryBackoffBaseSeconds = Math.max(Math.min(config.getDouble("retryBackoffBaseSeconds", retryBackoffBaseSeconds), MAX_RETRY_BACKOFF_BASE_SECONDS), 1.0);
} catch (Throwable exception) {
logger.severe("Could not load configuration file " + pushConfigFile);
throw new RuntimeException(exception.getMessage());
}
if (httpUserAgent == null) {
httpUserAgent = "Wavefront-Proxy/" + getBuildVersion();
}
if (pushConfigFile != null) {
logger.info("Loaded configuration file " + pushConfigFile);
}
}
Aggregations