Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.stormcrawler.opensearch.metrics;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void prepare(
}

CrawlerMetrics.registerGauge(
context, stormConf, "status.count", () -> latestStatusCounts, freqStats);
context, stormConf, "status.count", this::statusCounts, freqStats);

counters = new StatusCounter[6];

Expand All @@ -96,6 +97,15 @@ public void prepare(
counters[5] = new StatusCounter("TOTAL");
}

/**
* The counts reported by the {@code status.count} metric. A V1 metrics consumer in another
* worker gets them through Kryo, which Storm only sets up for {@link HashMap}, not for the
* {@link ConcurrentHashMap} the counts are kept in.
*/
Map<String, Long> statusCounts() {
return new HashMap<>(latestStatusCounts);
}

@Override
public Map<String, Object> getComponentConfiguration() {
Config conf = new Config();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.stormcrawler.opensearch.metrics;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Output;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.storm.serialization.SerializationFactory;
import org.apache.storm.utils.Utils;
import org.junit.jupiter.api.Test;

class StatusMetricsBoltTest {

/** Kryo as Storm sets it up for a topology that registers no classes of its own. */
private static Kryo stormKryo() {
return SerializationFactory.getKryo(Utils.readDefaultConfig());
}

@Test
void statusCountsCanBeSentToAMetricsConsumerInAnotherWorker() {
final Kryo kryo = stormKryo();
assertDoesNotThrow(
() ->
kryo.writeClassAndObject(
new Output(1024), new StatusMetricsBolt().statusCounts()));
}

@Test
void theMapTheCountsAreKeptInCannotBe() {
// why statusCounts() hands out a copy rather than the map itself
final Kryo kryo = stormKryo();
assertThrows(
IllegalArgumentException.class,
() ->
kryo.writeClassAndObject(
new Output(1024), new ConcurrentHashMap<String, Long>()));
}
}
Loading