Skip to content

Commit 6d9b6a6

Browse files
authored
Merge pull request #13 from factorhouse/feature/factor-platform
Add TargetProduct enum
2 parents 00d4536 + aa2f532 commit 6d9b6a6

5 files changed

Lines changed: 67 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Change Log
22
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
33

4+
## [1.1.0] - 2026-04-22
5+
6+
## Changed
7+
8+
- Added new enum `io.factorhouse.kpow.StreamsRegistry.TargetProduct`: supported values are `KPOW` and `FACTOR_PLATFORM`
9+
- `io.factorhouse.kpow.StreamsRegistry` now accepts an optional third argument where you can specify the target product.
10+
- For backwards compatibility, the existing 2-artity `io.factorhouse.kpow.StreamsRegistry` constructor will initialize the `StreamsRegistry` instance with a default target product of `KPOW`.
11+
412
## [1.0.0] - 2025-02-27
513

614
A major release of the StreamsAgent with some breaking changes.

project.clj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject io.factorhouse/kpow-streams-agent "1.0.0"
1+
(defproject io.factorhouse/kpow-streams-agent "1.1.0"
22
:description "Kpow's Kafka Streams monitoring agent"
33
:url "https://github.com/factorhouse/kpow-streams-agent"
44
:license {:name "Apache-2.0 License"
@@ -23,10 +23,10 @@
2323
[:roles
2424
[:role "developer"]
2525
[:role "maintainer"]]]])
26-
:dependencies [[org.clojure/clojure "1.12.0"]
27-
[com.cognitect/transit-clj "1.0.333"]
28-
[org.clojure/tools.logging "1.3.0"]
29-
[org.apache.kafka/kafka-streams "3.7.1" :scope "provided"]]
26+
:dependencies [[org.clojure/clojure "1.12.4"]
27+
[com.cognitect/transit-clj "1.1.357"]
28+
[org.clojure/tools.logging "1.3.1"]
29+
[org.apache.kafka/kafka-streams "4.0.2"]]
3030
:pom-plugins [[org.sonatype.central/central-publishing-maven-plugin "0.6.0"
3131
{:extensions "true"
3232
:configuration [:publishingServerId "central"]}]
@@ -50,11 +50,11 @@
5050
:aot :all}
5151
:profiles {:kaocha {:dependencies [[lambdaisland/kaocha "1.91.1392"]]}
5252
:dev {:resource-paths ["dev-resources"]
53-
:plugins [[lein-cljfmt "0.9.2"]]
54-
:dependencies [[org.slf4j/slf4j-api "2.0.16"]
55-
[ch.qos.logback/logback-classic "1.3.14"]
56-
[cheshire "5.13.0" :exclusions [com.fasterxml.jackson.core/jackson-databind]]
57-
[clj-kondo "2024.09.27"]]}
53+
:plugins [[dev.weavejester/lein-cljfmt "0.16.4"]]
54+
:dependencies [[org.slf4j/slf4j-api "2.0.17"]
55+
[ch.qos.logback/logback-classic "1.5.32"]
56+
[cheshire "6.2.0"]
57+
[clj-kondo "2026.04.15"]]}
5858
:smoke {:pedantic? :abort}}
5959
:aliases {"kaocha" ["with-profile" "+kaocha" "run" "-m" "kaocha.runner"]
6060
"kondo" ["with-profile" "+smoke" "run" "-m" "clj-kondo.main" "--lint" "src"]

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 {:topic snapshot-topic}
254251
:producer producer
255252
:metrics-filter metrics-filter}))
256253

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

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

32+
/**
33+
* Specifies the target Factor House product this StreamsRegistry instance should produce to.
34+
*/
35+
public enum TargetProduct {
36+
KPOW,
37+
FACTOR_PLATFORM;
38+
39+
public String getInternalTopic() {
40+
switch (this) {
41+
case KPOW:
42+
return "__oprtr_snapshot_state";
43+
case FACTOR_PLATFORM:
44+
return "fh_snapshots";
45+
default:
46+
throw new IllegalStateException("Unexpected value: " + this);
47+
}
48+
}
49+
}
50+
3251
/**
3352
* Represents an agent for a registered Kafka Streams application.
3453
* Provides the unique identifier of the registered application.
@@ -119,6 +138,8 @@ public static Properties filterProperties(Properties props) {
119138
* used to configure the underlying Kafka producer, and the {@link MetricFilter} determines which metrics
120139
* are collected and sent to Kpow's internal Kafka topic.</p>
121140
*
141+
* <p>This method will construct an instance of the {@link StreamsRegistry} with a default target product of Kpow.</p>
142+
*
122143
* <p><b>Important:</b> The Kafka producer properties provided in {@code props} must match the connection
123144
* details of Kpow's primary cluster, where Kpow's internal topic resides.</p>
124145
*
@@ -129,6 +150,28 @@ public static Properties filterProperties(Properties props) {
129150
* @throws IllegalArgumentException if the provided {@code props} are invalid or incomplete.
130151
*/
131152
public StreamsRegistry(Properties props, MetricFilter metricsFilter) {
153+
this(props, metricsFilter, TargetProduct.KPOW);
154+
}
155+
156+
/**
157+
* Constructs a {@code StreamsRegistry} instance using the specified Kafka properties and metrics filter.
158+
*
159+
* <p>This constructor initializes the registry, allowing Kafka Streams applications to be registered
160+
* for monitoring through Kpow's user interface and API. The provided {@link Properties} object is
161+
* used to configure the underlying Kafka producer, and the {@link MetricFilter} determines which metrics
162+
* are collected and sent to Kpow's internal Kafka topic.</p>
163+
*
164+
* <p><b>Important:</b> The Kafka producer properties provided in {@code props} must match the connection
165+
* details of Kpow's primary cluster, where Kpow's internal topic resides.</p>
166+
*
167+
* @param props the {@link Properties} object containing Kafka configuration.
168+
* Must include essential properties like {@code bootstrap.servers}.
169+
* @param metricsFilter the {@link MetricFilter} to customize which metrics are reported.
170+
* Use {@link MetricFilter#defaultMetricFilter()} for default behavior.
171+
* @param targetProduct the {@link TargetProduct} specifies which Factor House product should receive the agent's metrics.
172+
* @throws IllegalArgumentException if the provided {@code props} are invalid or incomplete.
173+
*/
174+
public StreamsRegistry(Properties props, MetricFilter metricsFilter, TargetProduct targetProduct) {
132175
IFn require = Clojure.var("clojure.core", "require");
133176
require.invoke(Clojure.read("io.factorhouse.kpow.agent"));
134177
IFn agentFn = Clojure.var("io.factorhouse.kpow.agent", "init-registry");
@@ -138,7 +181,7 @@ public StreamsRegistry(Properties props, MetricFilter metricsFilter) {
138181
Serializer valSerializer = (Serializer) serdesFn.invoke();
139182
Properties producerProps = filterProperties(props);
140183
KafkaProducer producer = new KafkaProducer<>(producerProps, keySerializer, valSerializer);
141-
agent = agentFn.invoke(producer, metricsFilter);
184+
agent = agentFn.invoke(producer, metricsFilter, targetProduct.getInternalTopic());
142185
}
143186

144187
/**

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)