Skip to content

Commit d679e2c

Browse files
authored
Move PrometheusServerProvider and PrometheusExporterPortProvider to oss (#2461)
1 parent 80233dc commit d679e2c

File tree

4 files changed

+154
-50
lines changed

4 files changed

+154
-50
lines changed

src/main/java/com/datastax/fallout/components/metrics/ExistingPromPushProvisioner.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ public class ExistingPromPushProvisioner extends NoRemoteAccessProvisioner
3333
{
3434
private static final String PREFIX = "fallout.configuration.management.existing_prompush.";
3535
private static final String NAME = "existing_prompush";
36-
private static final String DESCRIPTION = "For exporting metrics to an existing Prometheus PushGateway";
36+
private static final String DESCRIPTION = "For exporting metrics to an existing Prometheus server";
3737

3838
static final PropertySpec<String> hostUriSpec = PropertySpecBuilder
3939
.createStr(PREFIX)
4040
.name("host")
41-
.description("Host URI for the existing Prometheus PushGateway API")
41+
.description("Host URI for the existing Prometheus server")
4242
.required()
4343
.build();
4444

4545
static final PropertySpec<Integer> portSpec = PropertySpecBuilder
4646
.createInt(PREFIX)
4747
.name("port")
48-
.description("The port for the existing Prometheus PushGateway API")
48+
.description("The port for the existing Prometheus server")
4949
.required()
5050
.build();
5151

@@ -104,17 +104,17 @@ public void validateProperties(PropertyGroup properties) throws PropertySpec.Val
104104
@Override
105105
public void doSummarizeInfo(InfoConsumer infoConsumer)
106106
{
107-
getNodeGroup().findFirstProvider(PromPushProvider.class)
107+
getNodeGroup().findFirstProvider(PrometheusServerPushProvider.class)
108108
.ifPresent(p -> {
109-
infoConsumer.accept("host_uri", p.getHostUri());
110-
infoConsumer.accept("prompush_port", p.getPort());
109+
infoConsumer.accept("host", p.getHost());
110+
infoConsumer.accept("port", p.getPort());
111111
});
112112
}
113113

114114
@Override
115115
public Set<Class<? extends Provider>> getAvailableProviders(PropertyGroup properties)
116116
{
117-
return Set.of(PromPushProvider.class);
117+
return Set.of(PrometheusServerPushProvider.class);
118118
}
119119

120120
@Override
@@ -140,21 +140,18 @@ protected NodeGroup.State checkStateImpl(NodeGroup nodeGroup)
140140
{
141141
if (!createProviders(nodeGroup))
142142
return NodeGroup.State.FAILED;
143-
PromPushProvider provider = nodeGroup.findFirstRequiredProvider(PromPushProvider.class);
143+
PrometheusServerPushProvider provider = nodeGroup.findFirstRequiredProvider(PrometheusServerPushProvider.class);
144144
// fail fast if issues connecting to prom pushgateway
145-
String uri = String.format("%s:%d/metrics", provider.getHostUri(), provider.getPort());
145+
String uri = provider.getMetricsEndpoint();
146146
try
147147
{
148-
HttpUtils.httpGetString(
149-
uri,
150-
Optional.ofNullable(provider.getApiKey())
151-
);
152-
nodeGroup.logger().info("Successfully verified existing Prometheus PushGateway API");
148+
HttpUtils.httpGetString(uri, provider.getApiKey());
149+
nodeGroup.logger().info("Successfully verified existing Prometheus server");
153150
return NodeGroup.State.STARTED_SERVICES_CONFIGURED;
154151
}
155152
catch (IOException e)
156153
{
157-
nodeGroup.logger().error("Failed to connect to existing Prometheus PushGateway API");
154+
nodeGroup.logger().error("Failed to connect to existing Prometheus server");
158155
return NodeGroup.State.FAILED;
159156
}
160157
}
@@ -163,8 +160,8 @@ private boolean createProviders(NodeGroup nodeGroup)
163160
{
164161
String hostUri = hostUriSpec.value(nodeGroup.getProperties());
165162
Integer promPushPort = portSpec.value(nodeGroup.getProperties());
166-
String apiKey = apiKeySpec.value(nodeGroup.getProperties());
167-
new PromPushProvider(
163+
Optional<String> apiKey = apiKeySpec.optionalValue(nodeGroup.getProperties());
164+
new PrometheusServerPushProvider(
168165
getNodeGroup().getNodes().get(0),
169166
hostUri,
170167
promPushPort,
@@ -188,7 +185,7 @@ protected boolean stopImpl(NodeGroup nodeGroup)
188185
@Override
189186
protected boolean destroyImpl(NodeGroup nodeGroup)
190187
{
191-
nodeGroup.getNodes().get(0).maybeUnregister(PromPushProvider.class);
188+
nodeGroup.getNodes().get(0).maybeUnregister(PrometheusServerPushProvider.class);
192189
return true;
193190
}
194191

src/main/java/com/datastax/fallout/components/metrics/PromPushProvider.java renamed to src/main/java/com/datastax/fallout/components/metrics/PrometheusExporterPortProvider.java

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,30 @@
2020
import com.datastax.fallout.ops.Node;
2121
import com.datastax.fallout.ops.Provider;
2222

23-
public class PromPushProvider extends Provider
23+
public class PrometheusExporterPortProvider extends Provider
2424
{
25-
public static final String prompushKeySubdir = "prompush";
26-
private final String hostUri;
27-
private final Integer promPushPort;
28-
private final String apiKey;
25+
final int port;
2926

30-
public PromPushProvider(Node node, String hostUri, Integer promPushPort, String apiKey)
27+
public PrometheusExporterPortProvider(Node node, int port)
3128
{
3229
super(node);
33-
this.hostUri = hostUri;
34-
this.promPushPort = promPushPort;
35-
this.apiKey = apiKey;
30+
this.port = port;
3631
}
3732

3833
@Override
3934
public String name()
4035
{
41-
return "prompush";
36+
return "PrometheusExporterPortProvider";
4237
}
4338

44-
public String getHostUri()
39+
public int getPort()
4540
{
46-
return hostUri;
47-
}
48-
49-
public Integer getPort()
50-
{
51-
return promPushPort;
52-
}
53-
54-
public String getApiKey()
55-
{
56-
return apiKey;
41+
return port;
5742
}
5843

5944
@Override
6045
public Map<String, String> toInfoMap()
6146
{
62-
return Map.of(
63-
"host_uri", hostUri,
64-
"prompush_port", String.valueOf(promPushPort)
65-
);
66-
}
67-
68-
@Override
69-
public boolean isNodeGroupProvider()
70-
{
71-
return true;
47+
return Map.of("port", "" + port);
7248
}
7349
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2025 DataStax, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datastax.fallout.components.metrics;
17+
18+
import java.util.Map;
19+
import java.util.Optional;
20+
21+
import com.datastax.fallout.ops.Node;
22+
import com.datastax.fallout.ops.Provider;
23+
24+
// Represents a Prometheus server that scrapes metrics from source(s)
25+
public class PrometheusServerProvider extends Provider
26+
{
27+
protected final String host;
28+
protected final Integer port;
29+
protected final Optional<String> apiKey;
30+
31+
public PrometheusServerProvider(Node node, String host, Integer port)
32+
{
33+
this(node, host, port, Optional.empty());
34+
}
35+
36+
public PrometheusServerProvider(Node node, String host, Integer port, Optional<String> apiKey)
37+
{
38+
super(node);
39+
this.host = host;
40+
this.port = port;
41+
this.apiKey = apiKey;
42+
}
43+
44+
@Override
45+
public String name()
46+
{
47+
return "PrometheusServerProvider";
48+
}
49+
50+
@Override
51+
public Map<String, String> toInfoMap()
52+
{
53+
return Map.of(
54+
"host", host,
55+
"port", String.valueOf(port)
56+
);
57+
}
58+
59+
public String getHost()
60+
{
61+
return host;
62+
}
63+
64+
public Integer getPort()
65+
{
66+
return port;
67+
}
68+
69+
public Optional<String> getApiKey()
70+
{
71+
return apiKey;
72+
}
73+
74+
public String getMetricsEndpoint()
75+
{
76+
return String.format("%s:%d/metrics", host, port);
77+
}
78+
79+
public String getQueryEndpoint()
80+
{
81+
return String.format("%s:%d/api/v1/query", host, port);
82+
}
83+
84+
public String getQueryRangeEndpoint()
85+
{
86+
return String.format("%s:%d/api/v1/query_range", host, port);
87+
}
88+
89+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 DataStax, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.datastax.fallout.components.metrics;
17+
18+
import java.util.Optional;
19+
20+
import com.datastax.fallout.ops.Node;
21+
22+
// Represents a Prometheus server that can scrape as well as have metrics pushed to it
23+
public class PrometheusServerPushProvider extends PrometheusServerProvider
24+
{
25+
public static final String promPushKeySubdir = "prompush";
26+
27+
public PrometheusServerPushProvider(Node node, String host, Integer port, Optional<String> apiKey)
28+
{
29+
super(node, host, port, apiKey);
30+
}
31+
32+
@Override
33+
public String name()
34+
{
35+
return "PrometheusServerPush";
36+
}
37+
38+
public String getImportEndpoint()
39+
{
40+
return String.format("%s:%d/api/v1/import", host, port);
41+
}
42+
}

0 commit comments

Comments
 (0)