adarshsanjeev commented on code in PR #15340: URL: https://github.com/apache/druid/pull/15340#discussion_r1442810055
########## extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogramModule.java: ########## @@ -0,0 +1,94 @@ +/* + * 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.druid.spectator.histogram; + +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.jsontype.NamedType; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableList; +import com.google.inject.Binder; +import org.apache.druid.initialization.DruidModule; +import org.apache.druid.segment.serde.ComplexMetrics; + +import java.util.List; + +/** + * Module defining various aggregators for Spectator Histograms + */ +public class SpectatorHistogramModule implements DruidModule +{ + @VisibleForTesting + public static void registerSerde() + { + ComplexMetrics.registerSerde( + SpectatorHistogramAggregatorFactory.TYPE_NAME, + new SpectatorHistogramComplexMetricSerde(SpectatorHistogramAggregatorFactory.TYPE_NAME) + ); + ComplexMetrics.registerSerde( + SpectatorHistogramAggregatorFactory.Timer.TYPE_NAME, + new SpectatorHistogramComplexMetricSerde(SpectatorHistogramAggregatorFactory.Timer.TYPE_NAME) + ); + ComplexMetrics.registerSerde( + SpectatorHistogramAggregatorFactory.Distribution.TYPE_NAME, + new SpectatorHistogramComplexMetricSerde(SpectatorHistogramAggregatorFactory.Distribution.TYPE_NAME) + ); + } + + @Override + public List<? extends Module> getJacksonModules() + { + return ImmutableList.of( + new SimpleModule( + getClass().getSimpleName() + ).registerSubtypes( + new NamedType( + SpectatorHistogramAggregatorFactory.class, + SpectatorHistogramAggregatorFactory.TYPE_NAME + ), + new NamedType( + SpectatorHistogramAggregatorFactory.Timer.class, + SpectatorHistogramAggregatorFactory.Timer.TYPE_NAME + ), + new NamedType( + SpectatorHistogramAggregatorFactory.Distribution.class, + SpectatorHistogramAggregatorFactory.Distribution.TYPE_NAME + ), + new NamedType( + SpectatorHistogramPercentilePostAggregator.class, + SpectatorHistogramPercentilePostAggregator.TYPE_NAME + ), + new NamedType( + SpectatorHistogramPercentilesPostAggregator.class, + SpectatorHistogramPercentilesPostAggregator.TYPE_NAME + ) + ).addSerializer(SpectatorHistogram.class, new SpectatorHistogramJsonSerializer()) + ); + } + + @Override + public void configure(Binder binder) + { + registerSerde(); + //TODO: samarth this probably needs to be added for sql Review Comment: This could either be removed to a comment till sql support is added ########## extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/NullableOffsetsHeader.java: ########## @@ -0,0 +1,378 @@ +/* + * 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.druid.spectator.histogram; + +import com.google.common.base.Preconditions; +import org.apache.druid.io.Channels; +import org.apache.druid.java.util.common.io.smoosh.FileSmoosher; +import org.apache.druid.segment.serde.Serializer; +import org.apache.druid.segment.writeout.SegmentWriteOutMedium; +import org.apache.druid.segment.writeout.WriteOutBytes; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; +import java.nio.LongBuffer; +import java.nio.channels.WritableByteChannel; +import java.util.BitSet; +import java.util.Objects; + +public class NullableOffsetsHeader implements Serializer Review Comment: nit: A javadoc for this class as a small summary of its usages would help make the code more readable ########## extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogram.java: ########## @@ -0,0 +1,423 @@ +/* + * 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.druid.spectator.histogram; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.netflix.spectator.api.histogram.PercentileBuckets; +import it.unimi.dsi.fastutil.shorts.Short2LongMap; +import it.unimi.dsi.fastutil.shorts.Short2LongMaps; +import it.unimi.dsi.fastutil.shorts.Short2LongOpenHashMap; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.jackson.JacksonUtils; +import org.apache.druid.java.util.common.parsers.ParseException; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +// Since queries don't come from SpectatorHistogramAggregator in the case of +// using longSum or doubleSum aggregations. They come from LongSumBufferAggregator. +// Therefore, we extended Number here. +// This will prevent class casting exceptions if trying to query with sum rather +// than explicitly as a SpectatorHistogram +// +// The SpectatorHistorgram is a Number. That number is of intValue(), Review Comment: SpectatorHistogram -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
