mlbiscoc commented on code in PR #2405: URL: https://github.com/apache/solr/pull/2405#discussion_r1610557299
########## solr/core/src/java/org/apache/solr/metrics/prometheus/core/SolrCoreMetric.java: ########## @@ -0,0 +1,54 @@ +/* + * 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.metrics.prometheus.core; + +import com.codahale.metrics.Metric; +import java.util.HashMap; +import java.util.Map; +import org.apache.solr.metrics.prometheus.SolrPrometheusCoreExporter; + +/** + * Base class is a wrapper to categorize and export {@link com.codahale.metrics.Metric} to {@link + * io.prometheus.metrics.model.snapshots.DataPointSnapshot} and register to a {@link + * SolrPrometheusCoreExporter}. {@link com.codahale.metrics.MetricRegistry} does not support tags + * unlike prometheus. Metrics registered to the registry need to be parsed out from the metric name + * to be exported to {@link io.prometheus.metrics.model.snapshots.DataPointSnapshot} + */ +public abstract class SolrCoreMetric { + public Metric dropwizardMetric; + public String coreName; + public String metricName; + public Map<String, String> labels = new HashMap<>(); Review Comment: The `PrometheusTextFormatWriter` will take the MetricSnapshots exported and just output in lexicographical order. So a `HashMap` to `LinkedHashMap` wouldn't really change anything. ########## solr/core/src/java/org/apache/solr/response/PrometheusResponseWriter.java: ########## @@ -0,0 +1,46 @@ +/* + * 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.response; + +import io.prometheus.metrics.expositionformats.PrometheusTextFormatWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Map; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.metrics.prometheus.SolrPrometheusCoreExporter; +import org.apache.solr.request.SolrQueryRequest; + +@SuppressWarnings(value = "unchecked") +public class PrometheusResponseWriter extends RawResponseWriter { + @Override + public void write(OutputStream out, SolrQueryRequest request, SolrQueryResponse response) + throws IOException { + NamedList<Object> prometheusRegistries = + (NamedList<Object>) response.getValues().get("metrics"); + Map<String, Object> registryMap = prometheusRegistries.asShallowMap(); Review Comment: Got it, moved to an `Iterator` instead. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org