Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable/Disable Endpoint should show duration

See original GitHub issue

Both if it were disable and if it is still active. Seeing something like: durationMinutes: 180 makes for some simple math so the caller doesn’t have to worry about when something was enabled (regardless of timezone).

Duration Is probably a poor name. minutesActive might be clearer. It would keep counting up if it hasn’t been disabled.

Feel free to ignore this idea though if it distracts from the endpoint’s purpose.

_Originally posted by @checketts in

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

checkettscommented, Oct 27, 2021

To fix the failing test, it looks like it works fine if you convert it to millis:


I not particularly opposed to the Duration in the ednpoint. More just annoyed with its toString() in general. 😉 So feel free to ignore my comment in that regard.

However, if you were curious, here is how you could change the DTO:

public class ChaosMonkeyDisabledDto {
  private final String status = "Chaos Monkey is disabled";
  private final ZonedDateTime disabledAt =;
  private final Duration timeActive;
  private Duration timeInactive;

  public ChaosMonkeyDisabledDto(ChaosMonkeyEnabledDto chaosMonkeyEnabledDto) {
    this.timeActive = chaosMonkeyEnabledDto.getTimeActive();

  public Duration getTimeActive() {
    return timeActive;

  public String getTimeActiveMS() {
    return formatDuration(timeActive.toMillis());

  public Duration getTimeInactive() {
    timeInactive = Duration.between(disabledAt,;
    return timeInactive;

  public String getTimeInactiveMS() {
    return formatDuration(timeActive.toMillis());

  private String formatDuration(long durationMs) {
    DecimalFormat df = new DecimalFormat();

    if(durationMs >  3_600_000) {
      return df.format(durationMs / 3_600_000.0) + " hours";
    } else if (durationMs > 60_000) {
      return df.format(durationMs / 60_000.0) + " minutes";
    } else {
      return df.format(durationMs / 1_000.0) + " seconds";


And the test:

  @SuppressWarnings({"rawtypes", "unchecked"})
  void postToDisableChaosMonkey() {
    ZonedDateTime disabledAt =;
    ResponseEntity<Map> result = testRestTemplate.postForEntity(baseUrl + "/disable", null, Map.class);

    assertEquals(HttpStatus.OK, result.getStatusCode());
    assertThat(result.getBody()).containsEntry("status", "Chaos Monkey is disabled");
    assertThat(result.getBody()).containsEntry("timeInactive", "0.0 seconds");
    assertThat(result.getBody()).containsEntry("timeActive", "0.0 seconds");
checkettscommented, Oct 26, 2021

I’m not a huge fan of the Duration.toString(). It never is very intuitive for me. A simple method to write out a decimal of total second/minutes/hours wouldn’t take much and would make it much easier to read.

if(durationMs >  3_600_000) {
  return fmtTo2Decimal(durationMs / 3_600_000.0) + " hours"
} else if () {
   return fmtTo2Decimal(durationMs / 60_000.0) + " minutes"
} else {
    return fmtTo2Decimal(durationMs / 1_000.0) + " seconds"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable and Disable Endpoints at Runtime With Spring Boot
In this tutorial, we'll learn to enable and disable endpoints at runtime in a Spring Boot application using a few popular libraries, ...
Read more >
Enable and disable endpoints at runtime with Spring boot
Now if you want the above controller to work, you need to add following in file. my.controller.enabled=true.
Read more >
51. Endpoints - Spring
Each individual endpoint can be enabled or disabled. This controls whether or not the endpoint is created and its bean exists in the...
Read more >
Manage endpoints in Azure Traffic Manager - Microsoft Learn
This article will help you add, remove, enable and disable endpoints from Azure Traffic Manager.
Read more >
Spring Boot Actuator: Health check, Auditing, Metrics ...
It will show DOWN if the application gets unhealthy due to any issue like ... You can enable or disable an actuator endpoint...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found