Skip to content

Commit 90b9dd4

Browse files
[fix][fn] Make /version return correct version (#20047)
### Motivation The `/version` endpoint for functions currently returns `{"version":"version.number"}` instead of an actual version number. This PR fixes that. One observation is that the broker's `/version` endpoint returns a plain string: https://github.com/apache/pulsar/blob/82237d3684fe506bcb6426b3b23f413422e6e4fb/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java#L527-L535 ### Modifications * Return the actual version. * Use a static field to decrease the cost of this endpoint. ### Verifying this change This is a trivial change. ### Documentation - [x] `doc-not-needed` This fixes an endpoint, no docs are needed. ### Matching PR in forked repository PR in forked repository: Skipping PR since this is so trivial
1 parent 421d707 commit 90b9dd4

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/ConfigurationResource.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,25 @@
1919
package org.apache.pulsar.functions.worker.rest;
2020

2121
import com.fasterxml.jackson.core.JsonProcessingException;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import com.fasterxml.jackson.databind.node.ObjectNode;
2422
import javax.ws.rs.GET;
2523
import javax.ws.rs.Path;
2624
import javax.ws.rs.Produces;
2725
import javax.ws.rs.core.MediaType;
2826
import javax.ws.rs.core.Response;
29-
import org.apache.pulsar.common.util.ObjectMapperFactory;
27+
import org.apache.pulsar.PulsarVersion;
3028

3129
@Path("/")
3230
public class ConfigurationResource {
31+
32+
private static final String VERSION = "{\"version\":\"" + PulsarVersion.getVersion() + "\"}";
33+
3334
@Path("version")
3435
@GET
3536
@Produces(MediaType.APPLICATION_JSON)
3637
public Response release() throws JsonProcessingException {
37-
final ObjectMapper mapper = ObjectMapperFactory.getMapper().getObjectMapper();
38-
final ObjectNode node = mapper.createObjectNode();
39-
node.put("version", "version.number");
40-
4138
return Response.ok()
4239
.type(MediaType.APPLICATION_JSON)
43-
.entity(mapper
44-
.writerWithDefaultPrettyPrinter()
45-
.writeValueAsString(node))
40+
.entity(VERSION)
4641
.build();
4742
}
4843
}

0 commit comments

Comments
 (0)