Skip to content

Commit

Permalink
Revert changes to audit metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanik committed Sep 21, 2017
1 parent 35ff63b commit 3b0b313
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 90 deletions.
Expand Up @@ -10,7 +10,6 @@
* subcomponents is subject to the terms and conditions of the * subcomponents is subject to the terms and conditions of the
* subcomponent's license, as noted in the LICENSE file. * subcomponent's license, as noted in the LICENSE file.
*******************************************************************************/ *******************************************************************************/

package org.cloudfoundry.identity.statsd; package org.cloudfoundry.identity.statsd;


import com.timgroup.statsd.NonBlockingStatsDClient; import com.timgroup.statsd.NonBlockingStatsDClient;
Expand Down
Expand Up @@ -39,32 +39,32 @@
*/ */
public class Log4jContextInitializer implements ServletContextListener, Filter { public class Log4jContextInitializer implements ServletContextListener, Filter {


@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
MDC.put("context", sce.getServletContext().getContextPath()); MDC.put("context", sce.getServletContext().getContextPath());
} }


@Override @Override
public void contextDestroyed(ServletContextEvent sce) { public void contextDestroyed(ServletContextEvent sce) {
} }


@Override @Override
public void init(FilterConfig filterConfig) throws ServletException { public void init(FilterConfig filterConfig) throws ServletException {
} }


@Override @Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException { ServletException {
MDC.put("context", ((HttpServletRequest)request).getContextPath()); MDC.put("context", ((HttpServletRequest)request).getContextPath());
try { try {
chain.doFilter(request, response); chain.doFilter(request, response);
} finally { } finally {
MDC.remove("context"); MDC.remove("context");
} }
} }


@Override @Override
public void destroy() { public void destroy() {
} }


} }
Expand Up @@ -86,7 +86,7 @@ public Set<java.util.Map.Entry<String, Object>> entrySet() {
for (MBeanOperationInfo operation : operations) { for (MBeanOperationInfo operation : operations) {
String key = operation.getName(); String key = operation.getName();
if (key.startsWith("get") && operation.getSignature().length == 0) { if (key.startsWith("get") && operation.getSignature().length == 0) {
String attribute = StringUtils.camelToPeriod(key.substring(3)); String attribute = StringUtils.camelToUnderscore(key.substring(3));
if (map.containsKey(attribute)) { if (map.containsKey(attribute)) {
continue; continue;
} }
Expand Down Expand Up @@ -168,7 +168,7 @@ private void verySafePut(Map<? extends Object, Object> map, Object key, Object v
private void safePut(Map<Object, Object> map, Object key, Object value, boolean prettifyKeys) { private void safePut(Map<Object, Object> map, Object key, Object value, boolean prettifyKeys) {
Object property = key; Object property = key;
if (key instanceof String && prettifyKeys) { if (key instanceof String && prettifyKeys) {
property = StringUtils.camelToPeriod((String) key); property = StringUtils.camelToUnderscore((String) key);
} }
// Don't prettify system property keys in case user has added upper case properties // Don't prettify system property keys in case user has added upper case properties
map.put(property, getCompositeWrapper(value, prettifyKeys && !key.equals("SystemProperties"))); map.put(property, getCompositeWrapper(value, prettifyKeys && !key.equals("SystemProperties")));
Expand Down
Expand Up @@ -13,32 +13,29 @@


package org.cloudfoundry.identity.statsd; package org.cloudfoundry.identity.statsd;


/**
* @author Dave Syer
*
*/
public class StringUtils { public class StringUtils {


/** /**
* Convert a string from camel case to underscores, also replacing periods with underscores (so for example a fully * Convert a string from camel case to underscores, also replacing periods with underscores (so for example a fully
* qualified Java class name gets underscores everywhere). * qualified Java class name gets underscores everywhere).
* *
* @param value a camel case String * @param value a camel case String
* @return the same value with camels converted to underscores * @return the same value with camels converted to underscores
*/ */
public static String camelToUnderscore(String value) { public static String camelToUnderscore(String value) {
String result = value.replace(" ", "_"); return camelToDelimiter(value, "_");
result = result.replaceAll("([a-z])([A-Z])", "$1_$2"); }
result = result.replace(".", "_");
result = result.toLowerCase(); public static String camelToDelimiter(String value, String delimiter) {
return result; String result = value.replace(" ", delimiter);
} result = result.replaceAll("([a-z])([A-Z])", "$1" + delimiter + "$2");
result = result.replace(".", delimiter);
result = result.toLowerCase();
return result;
}


public static String camelToPeriod(String key) { public static String camelToPeriod(String value) {
String result = key.replace(" ", "."); return camelToDelimiter(value, "_");
result = result.replaceAll("([a-z])([A-Z])", "$1.$2"); }
result = result.replace("_", ".");
result = result.toLowerCase();
return result;
}
} }
Expand Up @@ -25,25 +25,25 @@


public class MBeanMapTests { public class MBeanMapTests {


private MBeanServerConnection server; private MBeanServerConnection server;


@Before @Before
public void start() throws Exception { public void start() throws Exception {
MBeanServerFactoryBean factory = new MBeanServerFactoryBean(); MBeanServerFactoryBean factory = new MBeanServerFactoryBean();
factory.setLocateExistingServerIfPossible(true); factory.setLocateExistingServerIfPossible(true);
factory.afterPropertiesSet(); factory.afterPropertiesSet();
server = factory.getObject(); server = factory.getObject();
} }


@Test @Test
public void testListDomain() throws Exception { public void testListDomain() throws Exception {
Set<ObjectName> names = server.queryNames(ObjectName.getInstance("java.lang:type=Runtime,*"), null); Set<ObjectName> names = server.queryNames(ObjectName.getInstance("java.lang:type=Runtime,*"), null);
System.err.println(names); System.err.println(names);
assertTrue(names.size() == 1); assertTrue(names.size() == 1);
MBeanMap result = new MBeanMap(server, names.iterator().next()); MBeanMap result = new MBeanMap(server, names.iterator().next());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String,String> properties = (Map<String, String>) result.get("system.properties"); Map<String,String> properties = (Map<String, String>) result.get("system_properties");
assertTrue(properties.containsKey("java.vm.version")); assertTrue(properties.containsKey("java.vm.version"));
} }


} }
Expand Up @@ -18,18 +18,6 @@
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;


/*******************************************************************************
* Cloud Foundry
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved.
* <p/>
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
* <p/>
* This product includes a number of subcomponents with
* separate copyright notices and license terms. Your use of these
* subcomponents is subject to the terms and conditions of the
* subcomponent's license, as noted in the LICENSE file.
*******************************************************************************/
public class IntegrationTestUtils { public class IntegrationTestUtils {


public static final String UAA_BASE_URL = "http://localhost:8080/uaa"; public static final String UAA_BASE_URL = "http://localhost:8080/uaa";
Expand Down
Expand Up @@ -50,11 +50,20 @@ public class UaaMetricsEmitterIT {
private static DatagramPacket receivePacket; private static DatagramPacket receivePacket;
private static Map<String, String> firstBatch; private static Map<String, String> firstBatch;
private static List<String> gaugeFragments = Arrays.asList( private static List<String> gaugeFragments = Arrays.asList(
"uaa.audit_service.user_authentication_count",
"uaa.audit_service.principal_not_found_count",
"uaa.audit_service.client_authentication_failure_count",
"uaa.audit_service.user_authentication_count",
"uaa.audit_service.user_authentication_failure_count",
"uaa.audit_service.user_not_found_count",
"uaa.audit_service.principal_authentication_failure_count",
"uaa.audit_service.user_password_failures",
"uaa.audit_service.client_authentication_count",
"uaa.audit_service.user_password_changes",
"uaa.requests.global.completed.count", "uaa.requests.global.completed.count",
"uaa.requests.global.completed.count", "uaa.requests.global.completed.count",
"uaa.requests.global.unhealthy.time", "uaa.requests.global.unhealthy.time",
"uaa.requests.global.unhealthy.count", "uaa.requests.global.unhealthy.count",
"uaa.audit_service.user.authentication.count:",
"uaa.server.inflight.count", "uaa.server.inflight.count",
"uaa.requests.global.status_1xx.count", "uaa.requests.global.status_1xx.count",
"uaa.requests.global.status_2xx.count", "uaa.requests.global.status_2xx.count",
Expand Down Expand Up @@ -96,13 +105,13 @@ public static void setUpOnce() throws IOException {
@Test @Test
public void assert_gauge_metric() throws IOException { public void assert_gauge_metric() throws IOException {
String data1 = firstBatch.get(statsDKey); String data1 = firstBatch.get(statsDKey);
assertNotNull("Expected to find message for:"+statsDKey+" in the first batch.", data1); assertNotNull("Expected to find message for:'"+statsDKey+"' in the first batch.", data1);
String data2 = secondBatch.get(statsDKey); String data2 = secondBatch.get(statsDKey);
assertNotNull("Expected to find message for:"+statsDKey+" in the second batch.", data2); assertNotNull("Expected to find message for:'"+statsDKey+"' in the second batch.", data2);
long first = IntegrationTestUtils.getGaugeValueFromMessage(data1); long first = IntegrationTestUtils.getGaugeValueFromMessage(data1);
long second = IntegrationTestUtils.getGaugeValueFromMessage(data2); long second = IntegrationTestUtils.getGaugeValueFromMessage(data2);
assertThat(statsDKey+" has a positive value.", first, greaterThanOrEqualTo(0l)); assertThat(statsDKey+" must have a positive value.", first, greaterThanOrEqualTo(0l));
assertThat(statsDKey+" has a positive value larger than or equal to the first.", second, greaterThanOrEqualTo(first)); assertThat(statsDKey+" must have a positive value larger than or equal to the first.", second, greaterThanOrEqualTo(first));
} }




Expand Down

0 comments on commit 3b0b313

Please sign in to comment.