public static boolean isNotEmpty(String s) { return !isEmpty(s); }
static String getTodaysIndexName() { return "stagemonitor-spans-" + StringUtils.getLogstashStyleDate(); }
private boolean isGrafanaConfigured(String grafanaUrl, String apiToken) { return StringUtils.isNotEmpty(grafanaUrl) && StringUtils.isNotEmpty(apiToken); }
private void setTrackingInformation(Span span, HttpServletRequest httpServletRequest, String clientIp, String userAgenHeader) { final String userName = getUserName(httpServletRequest); final String sessionId = getSessionId(httpServletRequest); span.setTag(SpanUtils.USERNAME, userName); span.setTag("session_id", sessionId); if (userName != null) { span.setTag("tracking.unique_visitor_id", StringUtils.sha1Hash(userName)); } else { span.setTag("tracking.unique_visitor_id", StringUtils.sha1Hash(clientIp + sessionId + userAgenHeader)); } SpanUtils.setClientIp(span, clientIp); }
@Override public String toString(Collection<T> value) { return StringUtils.asCsv(value); }
@JsonCreator public MeasurementSession(@JsonProperty("id") String id, @JsonProperty("applicationName") String applicationName, @JsonProperty("hostName") String hostName, @JsonProperty("instanceName") String instanceName) { this.applicationName = replaceWhitespacesWithDash(applicationName); this.hostName = replaceWhitespacesWithDash(hostName); this.instanceName = replaceWhitespacesWithDash(instanceName); this.id = id; stringRepresentation = "[application=" + applicationName + "] [instance=" + instanceName + "] [host=" + hostName + "]"; startTimestamp = System.currentTimeMillis(); }
@Override public URL convert(String s) throws IllegalArgumentException { try { return new URL(StringUtils.removeTrailingSlash(s)); } catch (MalformedURLException e) { throw new IllegalArgumentException(e.getMessage()); } }
@Override public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String requestURI = req.getRequestURI().substring(req.getContextPath().length()).replace("..", ""); setResponseHeaders(req, res, requestURI); InputStream inputStream = null; try { inputStream = getClass().getClassLoader().getResourceAsStream(StringUtils.removeStart(requestURI, "/")); if (inputStream == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND); return; } IOUtils.copy(inputStream, res.getOutputStream()); res.getOutputStream().flush(); res.flushBuffer(); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException ioe) { // ignore } } }
@Test public void testSha1Hash() throws Exception { // result from org.apache.commons.codec.digest.DigestUtils.sha1Hex assertEquals("a94a8fe5ccb19ba61c4c0873d391e987982fbbd3", StringUtils.sha1Hash("test")); } }
public static String asCsv(String[] strings) { return asCsv(Arrays.asList(strings)); }
public static String slugify(String s) { return replaceWhitespacesWithDash(s.toLowerCase().replaceAll("[^\\w ]+", "")); }
public String getGrafanaUrl() { return StringUtils.removeTrailingSlash(grafanaUrl.getValue()); }
@Test public void testRemoveStart() { assertEquals(StringUtils.removeStart("teststring", "test"), "string"); assertEquals(StringUtils.removeStart("string", "test"), "string"); assertEquals(StringUtils.removeStart("stringtest", "test"), "stringtest"); }
public static String getSignature(String fullClassName, String methodName, String nameFromAnnotation, boolean absolute) { String name = StringUtils.isEmpty(nameFromAnnotation) ? methodName : nameFromAnnotation; if (absolute) { return name; } return getSignature(fullClassName, name); }
@Override public boolean isAvailable() { return StringUtils.isNotEmpty(alertingPlugin.getPushbulletAccessToken()); }
public static String getTodaysIndexName() { return STAGEMONITOR_METRICS_INDEX_PREFIX + StringUtils.getLogstashStyleDate(); }
@Override public void onFinish(SpanWrapper spanWrapper, String operationName, long durationNanos) { final boolean pseudonymizeUserNames = tracingPlugin.isPseudonymizeUserNames(); final boolean anonymizeIPs = tracingPlugin.isAnonymizeIPs(); if (!anonymizeIPs && !pseudonymizeUserNames) { return; } final String username = spanWrapper.getStringTag(SpanUtils.USERNAME); String hashedUserName = username; if (pseudonymizeUserNames) { hashedUserName = StringUtils.sha1Hash(username); spanWrapper.setTag(SpanUtils.USERNAME, hashedUserName); } final boolean disclose = tracingPlugin.getDiscloseUsers().contains(hashedUserName); if (disclose) { spanWrapper.setTag("username_disclosed", username); } if (anonymizeIPs && !disclose) { final String ipV6Address = spanWrapper.getStringTag(Tags.PEER_HOST_IPV6.getKey()); final Number ipV4Address = spanWrapper.getNumberTag(Tags.PEER_HOST_IPV4.getKey()); if (ipV6Address != null) { Tags.PEER_HOST_IPV6.set(spanWrapper, IPAnonymizationUtils.anonymize(ipV6Address)); } else if (ipV4Address != null) { final Inet4Address anonymizedIp = IPAnonymizationUtils.anonymizeIpV4Address(InetAddresses.fromInteger(ipV4Address.intValue())); Tags.PEER_HOST_IPV4.set(spanWrapper, InetAddresses.inetAddressToInt(anonymizedIp)); } } }
public static String getSearchRequestAsString(SearchRequest request) { String query = "POST /"; if (request.indices().length > 0) { query += StringUtils.asCsv(request.indices()) + "/"; if (request.types().length > 0) { query += StringUtils.asCsv(request.types()) + "/"; } } query += "_search"; query += getQueryParameters(request); query += "\n"; query += request.source().toString(); return query; }
private String getSql(String prepared, String sql) { if (StringUtils.isEmpty(sql) || !jdbcPlugin.isCollectPreparedStatementParameters()) { sql = prepared; } return sql.trim(); }
@Override public boolean isAvailable() { return isNotEmpty(alertingPlugin.getSmtpHost()) && isNotEmpty(alertingPlugin.getSmtpFrom()); }