Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.admin;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.solr.common.MapWriter;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.CommonTestInjection;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.metrics.SolrMetricManager;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.security.AuthorizationContext;
import org.apache.solr.security.PermissionNameProvider;
import org.apache.solr.util.stats.MetricUtils;
/** Request handler to return metrics */
public class MetricsHandler extends RequestHandlerBase implements PermissionNameProvider {
final SolrMetricManager metricManager;
public static final String COMPACT_PARAM = "compact";
public static final String PREFIX_PARAM = "prefix";
public static final String REGEX_PARAM = "regex";
public static final String PROPERTY_PARAM = "property";
public static final String REGISTRY_PARAM = "registry";
public static final String GROUP_PARAM = "group";
public static final String KEY_PARAM = "key";
public static final String EXPR_PARAM = "expr";
public static final String TYPE_PARAM = "type";
public static final String ALL = "all";
private static final Pattern KEY_SPLIT_REGEX =
Pattern.compile("(? injectedSysProps = CommonTestInjection.injectAdditionalProps();
private final boolean enabled;
public MetricsHandler(CoreContainer coreContainer) {
this.metricManager = coreContainer.getMetricManager();
this.cc = coreContainer;
this.enabled = coreContainer.getConfig().getMetricsConfig().isEnabled();
}
public MetricsHandler(SolrMetricManager metricManager) {
this.metricManager = metricManager;
this.cc = null;
this.enabled = true;
}
public boolean isEnabled() {
return enabled;
}
@Override
public Name getPermissionName(AuthorizationContext request) {
return Name.METRICS_READ_PERM;
}
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
if (metricManager == null) {
throw new SolrException(
SolrException.ErrorCode.INVALID_STATE, "SolrMetricManager instance not initialized");
}
if (cc != null && AdminHandlersProxy.maybeProxyToNodes(req, rsp, cc)) {
return; // Request was proxied to other node
}
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
try {
handleRequest(req.getParams(), (k, v) -> rsp.add(k, v));
} finally {
SolrRequestInfo.clearRequestInfo();
}
}
private void handleRequest(SolrParams params, BiConsumer consumer)
throws Exception {
if (!enabled) {
consumer.accept("error", "metrics collection is disabled");
return;
}
boolean compact = params.getBool(COMPACT_PARAM, true);
String[] keys = params.getParams(KEY_PARAM);
if (keys != null && keys.length > 0) {
handleKeyRequest(keys, consumer);
return;
}
String[] exprs = params.getParams(EXPR_PARAM);
if (exprs != null && exprs.length > 0) {
handleExprRequest(exprs, consumer);
return;
}
MetricFilter mustMatchFilter = parseMustMatchFilter(params);
Predicate propertyFilter = parsePropertyFilter(params);
List metricTypes = parseMetricTypes(params);
List metricFilters =
metricTypes.stream().map(MetricType::asMetricFilter).collect(Collectors.toList());
Set requestedRegistries = parseRegistries(params);
NamedList