Skip to content

Commit 38456ce

Browse files
committed
Add TargetProduct enum
1 parent 00d4536 commit 38456ce

3 files changed

Lines changed: 43 additions & 9 deletions

File tree

src/clojure/io/factorhouse/kpow/agent.clj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
TopologyDescription$Node TopologyDescription$Processor TopologyDescription$Sink
1414
TopologyDescription$Source TopologyDescription$Subtopology)))
1515

16-
(def kpow-snapshot-topic
17-
{:topic "__oprtr_snapshot_state"})
18-
1916
(extend-protocol p/Datafiable
2017
Taxon
2118
(datafy [v]
@@ -249,8 +246,8 @@
249246
{})
250247

251248
(defn init-registry
252-
[producer metrics-filter]
253-
(start-registry {:snapshot-topic kpow-snapshot-topic
249+
[producer metrics-filter snapshot-topic]
250+
(start-registry {:snapshot-topic snapshot-topic
254251
:producer producer
255252
:metrics-filter metrics-filter}))
256253

src/java/io/factorhouse/kpow/StreamsRegistry.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@
2929
*/
3030
public class StreamsRegistry implements AutoCloseable {
3131

32+
/**
33+
* Specifies the target Factor House product this StreamsRegistry should produce to.
34+
*/
35+
public enum TargetProduct {
36+
KPOW,
37+
FACTOR_PLATFORM;
38+
39+
public String getInternalTopic() {
40+
return switch (this) {
41+
case KPOW -> "__oprtr_snapshot_state";
42+
case FACTOR_PLATFORM -> "fh_snapshots";
43+
};
44+
}
45+
}
46+
3247
/**
3348
* Represents an agent for a registered Kafka Streams application.
3449
* Provides the unique identifier of the registered application.
@@ -129,6 +144,28 @@ public static Properties filterProperties(Properties props) {
129144
* @throws IllegalArgumentException if the provided {@code props} are invalid or incomplete.
130145
*/
131146
public StreamsRegistry(Properties props, MetricFilter metricsFilter) {
147+
this(props, metricsFilter, TargetProduct.KPOW);
148+
}
149+
150+
/**
151+
* Constructs a {@code StreamsRegistry} instance using the specified Kafka properties and metrics filter.
152+
*
153+
* <p>This constructor initializes the registry, allowing Kafka Streams applications to be registered
154+
* for monitoring through Kpow's user interface and API. The provided {@link Properties} object is
155+
* used to configure the underlying Kafka producer, and the {@link MetricFilter} determines which metrics
156+
* are collected and sent to Kpow's internal Kafka topic.</p>
157+
*
158+
* <p><b>Important:</b> The Kafka producer properties provided in {@code props} must match the connection
159+
* details of Kpow's primary cluster, where Kpow's internal topic resides.</p>
160+
*
161+
* @param props the {@link Properties} object containing Kafka configuration.
162+
* Must include essential properties like {@code bootstrap.servers}.
163+
* @param metricsFilter the {@link MetricFilter} to customize which metrics are reported.
164+
* Use {@link MetricFilter#defaultMetricFilter()} for default behavior.
165+
* @param metricsFilter the {@link TargetProduct} specifies which Factor House product should receive the agent's metrics.
166+
* @throws IllegalArgumentException if the provided {@code props} are invalid or incomplete.
167+
*/
168+
public StreamsRegistry(Properties props, MetricFilter metricsFilter, TargetProduct targetProduct) {
132169
IFn require = Clojure.var("clojure.core", "require");
133170
require.invoke(Clojure.read("io.factorhouse.kpow.agent"));
134171
IFn agentFn = Clojure.var("io.factorhouse.kpow.agent", "init-registry");
@@ -138,7 +175,7 @@ public StreamsRegistry(Properties props, MetricFilter metricsFilter) {
138175
Serializer valSerializer = (Serializer) serdesFn.invoke();
139176
Properties producerProps = filterProperties(props);
140177
KafkaProducer producer = new KafkaProducer<>(producerProps, keySerializer, valSerializer);
141-
agent = agentFn.invoke(producer, metricsFilter);
178+
agent = agentFn.invoke(producer, metricsFilter, targetProduct.getInternalTopic());
142179
}
143180

144181
/**

test/io/factorhouse/agent_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
(deftest agent-test
8383
(let [records (atom [])
8484
metrics-filter (-> (MetricFilter.) (.accept))
85-
registry (agent/init-registry (mock-producer records) metrics-filter)
85+
registry (agent/init-registry (mock-producer records) metrics-filter "__oprtr_snapshot_state")
8686
agent-id (agent/register registry
8787
(mock-streams [(mock-metric "first.metric" "first" "mock metric" {} 1.0)
8888
(mock-metric "application-id" "first" "mock metric" {"client-id" "abc123"} "xxx")
@@ -146,7 +146,7 @@
146146
(.acceptNameStartsWith "first")
147147
(.acceptNameStartsWith "rocksdb")
148148
(.deny))
149-
registry (agent/init-registry (mock-producer records) metrics-filter)
149+
registry (agent/init-registry (mock-producer records) metrics-filter "__oprtr_snapshot_state")
150150
agent-id (agent/register registry
151151
(mock-streams [(mock-metric "first.metric" "first" "mock metric" {} 1.0)
152152
(mock-metric "rocksdb.foo" "first" "mock metric" {"client-id" "abc123"} 3.0)
@@ -202,4 +202,4 @@
202202

203203
(is (agent/unregister registry agent))
204204

205-
(is (empty? (agent/close-registry registry)))))
205+
(is (empty? (agent/close-registry registry)))))

0 commit comments

Comments
 (0)