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

use tags for metrics #3226

Merged
merged 4 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,27 @@ public final class AuthorizationFramework extends PluginFramework<IAuthorization

private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizationFramework.class);

private final Counter authStackReloadCounter = Metrics.getRegistry().counter("authorization_stack_reload");
private final Counter authCacheHits = Metrics.getRegistry().counter("authorization_cache_hits");
private final Counter authCacheMisses = Metrics.getRegistry().counter("authorization_cache_misses");
private final Counter authSessionsInvalidated = Metrics.getRegistry().counter("authorization_sessions_invalidated");

private final Timer authTimer = Metrics.getRegistry().timer("authorization");
private final Timer authPositiveTimer = Metrics.getRegistry().timer("authorization_positive");
private final Timer authNegativeTimer = Metrics.getRegistry().timer("authorization_negative");
private final Counter authStackReloadCounter = Metrics.getRegistry().
counter("authorization.stack.reload");
private final Counter authCacheHits = Counter.builder("authorization.cache").
description("authorization cache hits").
tag("what", "hits").
register(Metrics.getRegistry());
private final Counter authCacheMisses = Counter.builder("authorization.cache").
description("authorization cache misses").
tag("what", "misses").
register(Metrics.getRegistry());
private final Counter authSessionsInvalidated = Metrics.getRegistry().
counter("authorization.sessions.invalidated");

private final Timer authTimerPositive = Timer.builder("authorization.latency").
description("authorization latency").
tag("outcome", "positive").
register(Metrics.getRegistry());
private final Timer authTimerNegative = Timer.builder("authorization.latency").
description("authorization latency").
tag("outcome", "negative").
register(Metrics.getRegistry());

/**
* Stack of available plugins/stacks in the order of the execution.
Expand Down Expand Up @@ -537,11 +550,10 @@ private boolean checkAll(HttpServletRequest request, String cache, Nameable enti
}

// Update the timers.
authTimer.record(duration);
if (overallDecision) {
authPositiveTimer.record(duration);
authTimerPositive.record(duration);
} else {
authNegativeTimer.record(duration);
authTimerNegative.record(duration);
}

m.put(entity.getName(), overallDecision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ public void stop() {
LOGGER.log(Level.WARNING, "Cannot join WatchDogService thread: ", ex);
}
}
LOGGER.log(Level.INFO, "Watchdog stoped");
LOGGER.log(Level.INFO, "Watchdog stopped");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.framework;
Expand Down Expand Up @@ -56,7 +56,8 @@ public class PluginClassLoader extends ClassLoader {
"org.opengrok.indexer.authorization.plugins.*",
"org.opengrok.indexer.authorization.AuthorizationException",
"org.opengrok.indexer.util.*",
"org.opengrok.indexer.logger.*"
"org.opengrok.indexer.logger.*",
"org.opengrok.indexer.Metrics"
};

private static final String[] PACKAGE_BLACKLIST = new String[]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2018, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.search;
Expand Down Expand Up @@ -73,9 +73,8 @@
import org.opengrok.indexer.web.ProjectHelper;

/**
* This is an encapsulation of the details on how to search in the index
* database.
* This is used for searching from the command line tool and also via the JSON interface.
* This is an encapsulation of the details on how to search in the index database.
* This is used for searching via the REST API.
*
* @author Trond Norbye 2005
* @author Lubos Kosco - upgrade to lucene 3.x, 4.x, 5.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void run() {
}

// Double check that at least one reload() was done.
long reloads = (long) Metrics.getRegistry().counter("authorization_stack_reload").count();
long reloads = (long) Metrics.getRegistry().counter("authorization.stack.reload").count();
assertTrue(reloads > 0);
}

Expand Down
13 changes: 12 additions & 1 deletion plugins/src/main/java/opengrok/auth/plugin/ldap/LdapFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
package opengrok.auth.plugin.ldap;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -41,9 +43,11 @@
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;

import io.micrometer.core.instrument.Timer;
import opengrok.auth.plugin.configuration.Configuration;
import opengrok.auth.plugin.util.WebHook;
import opengrok.auth.plugin.util.WebHooks;
import org.opengrok.indexer.Metrics;

public class LdapFacade extends AbstractLdapProvider {

Expand Down Expand Up @@ -103,6 +107,10 @@ public class LdapFacade extends AbstractLdapProvider {
private long errorTimestamp = 0;
private boolean reported = false;

private final Timer ldapLookupTimer = Timer.builder("ldap.latency").
description("LDAP lookup latency").
register(Metrics.getRegistry());

/**
* Interface for converting LDAP results into user defined types.
*
Expand Down Expand Up @@ -290,7 +298,10 @@ public SearchControls getSearchControls() {
* @return results transformed with mapper
*/
private <T> LdapSearchResult<T> lookup(String dn, String filter, String[] attributes, AttributeMapper<T> mapper) throws LdapException {
return lookup(dn, filter, attributes, mapper, 0);
Instant start = Instant.now();
LdapSearchResult<T> res = lookup(dn, filter, attributes, mapper, 0);
ldapLookupTimer.record(Duration.between(start, Instant.now()));
return res;
}

private String getSearchDescription(String dn, String filter, String[] attributes) {
Expand Down