spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.96k stars 1.29k forks source link

How to fetch latest git commit version along with /refresh Actuator call. #1016

Closed batarayappa closed 6 years ago

batarayappa commented 6 years ago

Hi , I want to fetch the latest git commit version along with /refresh Actuator call . Can you please help me sample code or java class to modify to fetch commit version.

springCloudVersion=Edgware.SR3 springBootVersion=1.5.10.RELEASE

Thanks in advance. Harinath.

ryanjbaxter commented 6 years ago

Not sure what you mean, are asking how to fetch a specific commit when calling /refresh?

batarayappa commented 6 years ago

Thanks for your reply ,Ryan.

I want to fetch latest commit version number from Git repository when config server query git repository(during /refresh call) to load latest properties. I want to display this git latest commit version number in our applications meta data to know the version being by application.

Harinath.

ryanjbaxter commented 6 years ago

Everytime a GET request is made to the config server it will execute a pull on the remote git repo to pull in the latest changes. The /refresh call will cause the GET to be made so you should be served the latest changes from the remote Git repo.

batarayappa commented 6 years ago

Thanks for Reply,Ryan. /refresh call will return version value along with updated property values?If yes, How can i extract version value from config refresh call?

Harinath.

ryanjbaxter commented 6 years ago

I believe the version is returned in the JSON response from the config server, however there is not API in the config client that exposes that information

{
    "name": "application",
    "profiles": [
        "default"
    ],
    "label": null,
    "version": "b70e3220f238a0631052b2d18e3e5859eccf12fd",
    "state": null,
    "propertySources": [{
        "name": "https://github.com/ryanjbaxter/ocr-config-repo/application.yml",
        "source": {
            "eureka.client.serviceUrl.defaultZone": "${vcap.services.ocr-eureka.credentials.uri:http://localhost:8761/eureka/}",
            "eureka.instance.hostname": "${vcap.application.uris[0]:localhost}",
            "eureka.instance.metadataMap.instanceId": "${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}",
            "management.endpoints.web.exposure.include": "*"
        }
    }]
}
harinathbk commented 6 years ago

Hi ryan,

Thanks for your reply. Sorry for late reply. May i know value contains in "version" field? version is mapped to latest Git commit-id of application.yml?

{ "name": "application", "profiles": [ "default" ], "label": null, "version": "b70e3220f238a0631052b2d18e3e5859eccf12fd", "state": null, "propertySources": [{ "name": "https://github.com/ryanjbaxter/ocr-config-repo/application.yml", "source": { "eureka.client.serviceUrl.defaultZone": "${vcap.services.ocr-eureka.credentials.uri:http://localhost:8761/eureka/}", "eureka.instance.hostname": "${vcap.application.uris[0]:localhost}", "eureka.instance.metadataMap.instanceId": "${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${server.port}}}", "management.endpoints.web.exposure.include": "*" } }] }

Harinath.

ryanjbaxter commented 6 years ago

It is the git commit version

harinathbk commented 6 years ago

Thanks you so much,Ryan. "version" and "config.client.version" both are same? or config.client.version used only during config refresh?

2018-07-02 12:29:18.667 INFO [xx-xxx,8c1372a2b04e0339,57497f82a05812f6,false] 1 --- [springCloudBus.anonymous.50HPMTx5Si-CddVtGE30Ng-1] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed [config.client.version, fusion.edge.testproperty, fusion.edge.test.property]

ryanjbaxter commented 6 years ago

I believe they are different

harinathbk commented 6 years ago

Hi Ryan,

I have one doubt in config server fetch process. here is the use-case:

use-case: I want deploy my applications into 2 containers(container1 and conatiner2) .Application will fetch config properties from Git repo. initially, i'm going to bring up container1 , so application running in container1 will connect configserver and configserver will fetch properties from Git Repo.After container1 is up, then i will change Git repo url to invalid url or assume git Repo server is down.Now, i will bring up container2 . here is my doubt, How configserver return properties for container2? will it take from local cache or it will try fetch from Git repo and fail with error ?

Thanks in advance.

Harinath.

ryanjbaxter commented 6 years ago

For questions like this we would prefer you use StackOverflow or Gitter in the future.

By default it will try and reach out to git but there is a property that can control how often this happen. spring.cloud.config.server.git.refresh-rate

harinathbk commented 6 years ago

Thanks Ryan.

Harinath.

cforce commented 6 years ago

Following your thread the relevant question is still open. If i start my boot app with spring cloud cfg client embedded with myapp.jar --spring.application.json='{"spring.cloud.config.label":"master"}'...and the wanna do a refresh but using spring.cloud.config.label=mybranach or spring.cloud.config.label=otherTagThanHead .. how can i do that without a restart .. at least so my @RefreshScope antated props are sourced from the new origin?