Skip to content

Commit

Permalink
[fix][fn] Make /version return correct version (#20047)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
michaeljmarshall authored Apr 8, 2023
1 parent 421d707 commit 90b9dd4
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,25 @@
package org.apache.pulsar.functions.worker.rest;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.pulsar.common.util.ObjectMapperFactory;
import org.apache.pulsar.PulsarVersion;

@Path("/")
public class ConfigurationResource {

private static final String VERSION = "{\"version\":\"" + PulsarVersion.getVersion() + "\"}";

@Path("version")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response release() throws JsonProcessingException {
final ObjectMapper mapper = ObjectMapperFactory.getMapper().getObjectMapper();
final ObjectNode node = mapper.createObjectNode();
node.put("version", "version.number");

return Response.ok()
.type(MediaType.APPLICATION_JSON)
.entity(mapper
.writerWithDefaultPrettyPrinter()
.writeValueAsString(node))
.entity(VERSION)
.build();
}
}

0 comments on commit 90b9dd4

Please sign in to comment.