-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Expose server config, session queue and node as MBeans for JMX monitoring. #8838
Changes from 1 commit
c1713e6
2c9e6ed
19ecb5c
82f4240
6d0b83c
22f686a
e215be6
d7dabf0
abb6525
8cd8f64
c608c76
5c1302a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,20 @@ | |
import org.openqa.selenium.net.HostIdentifier; | ||
import org.openqa.selenium.net.NetworkUtils; | ||
import org.openqa.selenium.net.PortProber; | ||
import org.openqa.selenium.remote.server.jmx.JMXHelper; | ||
import org.openqa.selenium.remote.server.jmx.ManagedAttribute; | ||
import org.openqa.selenium.remote.server.jmx.ManagedService; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.Optional; | ||
import java.util.logging.Logger; | ||
|
||
@ManagedService(objectName = "org.seleniumhq.grid:type=Config,name=BaseServerConfig", | ||
description = "Server config") | ||
public class BaseServerOptions { | ||
|
||
private static final String SERVER_SECTION = "server"; | ||
|
@@ -40,12 +47,14 @@ public class BaseServerOptions { | |
|
||
public BaseServerOptions(Config config) { | ||
this.config = config; | ||
new JMXHelper().register(this); | ||
} | ||
|
||
public Optional<String> getHostname() { | ||
return config.get(SERVER_SECTION, "hostname"); | ||
} | ||
|
||
@ManagedAttribute(name = "Port") | ||
public int getPort() { | ||
if (port == -1) { | ||
int newPort = config.getInt(SERVER_SECTION, "port") | ||
|
@@ -61,6 +70,7 @@ public int getPort() { | |
return port; | ||
} | ||
|
||
@ManagedAttribute(name = "MaxServerThreads") | ||
public int getMaxServerThreads() { | ||
int count = config.getInt(SERVER_SECTION, "max-threads") | ||
.orElse(200); | ||
|
@@ -94,6 +104,15 @@ public URI getExternalUri() { | |
} | ||
} | ||
|
||
@ManagedAttribute(name = "URL") | ||
public URL getExternalUrl() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Daft question, but why don't we just return the URI? |
||
try { | ||
return getExternalUri().toURL(); | ||
} catch (MalformedURLException e) { | ||
throw new ConfigException("Cannot convert URI to URL" + e.getMessage()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: We probably want a space after |
||
} | ||
} | ||
|
||
public boolean getAllowCORS() { | ||
return config.getBool(SERVER_SECTION, "allow-cors").orElse(false); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ | |
import org.openqa.selenium.internal.Require; | ||
import org.openqa.selenium.remote.http.HttpRequest; | ||
import org.openqa.selenium.remote.http.HttpResponse; | ||
import org.openqa.selenium.remote.server.jmx.JMXHelper; | ||
import org.openqa.selenium.remote.server.jmx.ManagedAttribute; | ||
import org.openqa.selenium.remote.server.jmx.ManagedService; | ||
import org.openqa.selenium.remote.tracing.AttributeKey; | ||
import org.openqa.selenium.remote.tracing.EventAttribute; | ||
import org.openqa.selenium.remote.tracing.EventAttributeValue; | ||
|
@@ -52,6 +55,8 @@ | |
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
@ManagedService(objectName = "org.seleniumhq.grid:type=SessionQueue,name=LocalSessionQueue", | ||
description = "New session queue") | ||
public class LocalNewSessionQueue extends NewSessionQueue { | ||
|
||
private static final Logger LOG = Logger.getLogger(LocalNewSessionQueue.class.getName()); | ||
|
@@ -67,6 +72,7 @@ public LocalNewSessionQueue(Tracer tracer, EventBus bus, Duration retryInterval, | |
super(tracer, retryInterval, requestTimeout); | ||
this.bus = Require.nonNull("Event bus", bus); | ||
Runtime.getRuntime().addShutdownHook(shutdownHook); | ||
new JMXHelper().register(this); | ||
} | ||
|
||
public static NewSessionQueue create(Config config) { | ||
|
@@ -82,6 +88,17 @@ public boolean isReady() { | |
return bus.isReady(); | ||
} | ||
|
||
@ManagedAttribute(name = "NewSessionQueueSize") | ||
public int getQueueSize() { | ||
Lock writeLock = lock.writeLock(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This need only be a read lock |
||
writeLock.lock(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to lock to read the queue size? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it uses ConcurrentLinkedDeque, the size() requires a traversal and value may not be accurate if it is being modified when size is calculated. Hence the lock. But for exposing values if we don't need that kind of accuracy, then we can get rid of the lock. @diemol What would you suggest? |
||
try { | ||
return sessionRequests.size(); | ||
} finally { | ||
writeLock.unlock(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean offerLast(HttpRequest request, RequestId requestId) { | ||
Require.nonNull("New Session request", request); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
getExternalUri
We try and AVOID SHOUTING in Selenium (which is why we haveHttpMethod
, and so on)