@Override public List<MetricFamilySamples> collect() { GaugeMetricFamily testSessionMetric = new GaugeMetricFamily("selenium_test_sessions_running", "The number of Selenium test sessions that are running by proxy type", Collections.singletonList("proxy")); Iterable<RemoteProxy> iterable = () -> proxySet.iterator(); Map<String, Integer> countByProxies = StreamSupport.stream(iterable.spliterator(), false).collect( Collectors.groupingBy(p -> p.getClass().getSimpleName(), Collectors.summingInt(p -> p.getTotalUsed()))); countByProxies.entrySet().stream() .forEach(e -> testSessionMetric.addMetric(Collections.singletonList(e.getKey()), e.getValue())); List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); mfs.add(testSessionMetric); return mfs; }
/** * @see GridRegistry#getUsedProxies() */ public List<RemoteProxy> getUsedProxies() { return proxies.getBusyProxies(); }
/** * @see GridRegistry#removeIfPresent(RemoteProxy) */ public void removeIfPresent(RemoteProxy proxy) { // Find the original proxy. While the supplied one is logically equivalent, it may be a fresh object with // an empty TestSlot list, which doesn't figure into the proxy equivalence check. Since we want to free up // those test sessions, we need to operate on that original object. if (proxies.contains(proxy)) { LOG.debug(String.format("Cleaning up stale test sessions on the unregistered node %s", proxy)); final RemoteProxy p = proxies.remove(proxy); p.getTestSlots().forEach(testSlot -> forceRelease(testSlot, SessionTerminationReason.PROXY_REREGISTRATION)); p.teardown(); } }
/** * @see GridRegistry#getProxyById(String) */ public RemoteProxy getProxyById(String id) { LOG.debug("Getting proxy {}", id); return proxies.getProxyById(id); }
public void add(RemoteProxy proxy) { boolean shouldAdd = true; if (proxy instanceof DockerSeleniumRemoteProxy) { DockerSeleniumRemoteProxy dockerSeleniumRemoteProxy = (DockerSeleniumRemoteProxy) proxy; shouldAdd = this.register(dockerSeleniumRemoteProxy); } if (shouldAdd) { super.add(proxy); } else { // Won't be tracking the proxy, so it won't be removed and shutdown later - tear down. proxy.teardown(); } }
private boolean takeRequestHandler(RequestHandler handler) { final TestSession session = proxies.getNewSession(handler.getRequest().getDesiredCapabilities()); final boolean sessionCreated = session != null; if (sessionCreated) { String remoteName = session.getSlot().getProxy().getId(); long timeToAssignProxy = System.currentTimeMillis() - handler.getRequest().getCreationTime(); LOG.info("Test session with internal key {} assigned to remote ({}) after {} seconds ({} ms).", session.getInternalKey(), remoteName, timeToAssignProxy / 1000, timeToAssignProxy); seleniumTestSessionStartLatency.observe(timeToAssignProxy / Collector.MILLISECONDS_PER_SECOND); seleniumTestSessionsWaiting.dec(); activeTestSessions.add(session); handler.bindSession(session); } return sessionCreated; }
private List<URL> getRegistryURLs(GridRegistry registry) { Iterator<RemoteProxy> remoteProxyIterator = registry.getAllProxies().iterator(); List<URL> urlList = new ArrayList<>(); while (remoteProxyIterator.hasNext()) { RemoteProxy remoteProxy = remoteProxyIterator.next(); urlList.add(remoteProxy.getRemoteHost()); } return urlList; }
private List<URL> getRegistryURLs(Registry registry) { Iterator<RemoteProxy> remoteProxyIterator = registry.getAllProxies().iterator(); List<URL> urlList = new ArrayList<>(); while (remoteProxyIterator.hasNext()) { RemoteProxy remoteProxy = remoteProxyIterator.next(); urlList.add(remoteProxy.getRemoteHost()); } return urlList; }
private List<ProxyInfo> getProxyInfo(boolean doStatusQuery) { List<ProxyInfo> nodes = new ArrayList<>(); ProxySet proxies = this.getRegistry().getAllProxies(); Iterator<RemoteProxy> iterator = proxies.iterator(); while (iterator.hasNext()) { RemoteProxy proxy = iterator.next(); nodes.add(new ProxyInfo(proxy, doStatusQuery)); } return nodes; } }
private List<ProxyInfo> getProxyInfo(boolean doStatusQuery) { List<ProxyInfo> nodes = new ArrayList<>(); ProxySet proxies = this.getRegistry().getAllProxies(); Iterator<RemoteProxy> iterator = proxies.iterator(); while (iterator.hasNext()) { RemoteProxy proxy = iterator.next(); nodes.add(new ProxyInfo(proxy, doStatusQuery)); } return nodes; } }
private List<ProxyInfo> getProxyInfo() { List<ProxyInfo> nodes = new ArrayList<>(); ProxySet proxies = this.getRegistry().getAllProxies(); Iterator<RemoteProxy> iterator = proxies.iterator(); while (iterator.hasNext()) { RemoteProxy proxy = iterator.next(); if ((proxy instanceof SeLionRemoteProxy) && (((SeLionRemoteProxy) proxy).supportsForceShutdown())) { nodes.add(new ProxyInfo(proxy, false)); } } return nodes; } }
private List<ProxyInfo> getProxyInfo() { List<ProxyInfo> nodes = new ArrayList<>(); ProxySet proxies = this.getRegistry().getAllProxies(); Iterator<RemoteProxy> iterator = proxies.iterator(); while (iterator.hasNext()) { RemoteProxy proxy = iterator.next(); if ((proxy instanceof SeLionRemoteProxy) && (((SeLionRemoteProxy) proxy).supportsForceShutdown())) { nodes.add(new ProxyInfo(proxy, false)); } } return nodes; } }
public Void call() throws Exception { GridRegistry registry = HubHolder.getHub().getRegistry(); if (registry != null) { Iterator<RemoteProxy> it = registry.getAllProxies().iterator(); while (it.hasNext()) { RemoteProxy proxy = it.next(); if (remoteUrl.equals(proxy.getRemoteHost().toString())) { registry.removeIfPresent(proxy); } } } return null; }
private JsonObject getResponse() throws IOException { JsonObject requestJSON = new JsonObject(); ProxySet proxies = this.getRegistry().getAllProxies(); Iterator<RemoteProxy> iterator = proxies.iterator(); JsonArray busyProxies = new JsonArray(); JsonArray freeProxies = new JsonArray(); while (iterator.hasNext()) { RemoteProxy eachProxy = iterator.next(); if (eachProxy.isBusy()) { busyProxies.add(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON()); } else { freeProxies.add(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON()); } } requestJSON.add("BusyProxies", busyProxies); requestJSON.add("FreeProxies", freeProxies); return requestJSON; }
private JsonObject getResponse() throws IOException { JsonObject requestJSON = new JsonObject(); ProxySet proxies = this.getRegistry().getAllProxies(); Iterator<RemoteProxy> iterator = proxies.iterator(); JsonArray busyProxies = new JsonArray(); JsonArray freeProxies = new JsonArray(); while (iterator.hasNext()) { RemoteProxy eachProxy = iterator.next(); if (eachProxy.isBusy()) { busyProxies.add(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON()); } else { freeProxies.add(eachProxy.getOriginalRegistrationRequest().getAssociatedJSON()); } } requestJSON.add("BusyProxies", busyProxies); requestJSON.add("FreeProxies", freeProxies); return requestJSON; }