acouvreur / traefik-ondemand-service

Traefik ondemand service for the traefik ondemand plugin

Home Page:https://pilot.traefik.io/plugins/605afbdba5f67ab9a1b0e53a/containers-on-demand

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weird behaviors with state recovery

Nastaliss opened this issue · comments

Hi !
I'm facing a weird behavior with the tinyKV used as state management
I am currently adding prometheus metrics, testing by injecting a dummy state in state.json, and starting with go run main.go -storagePath=./state.json.
The state.json contains the following :

{
  "my_service": {
    "value": {
      "state": "started",
      "name": "my_service"
    },
    "expiresAt": "2022-09-14T10:33:00.0000000000Z",
    "expiresAfter": 1,
    "isSliding": false
  }
}

, the expiresAt is in the future.
After starting the service, the json is changed to :

{
  "my_service": {
    "value": {
      "state": "started",
      "name": "my_service"
    },
    "expiresAt": "2022-09-14T12:33:00.00000425+02:00",
    "expiresAfter": 7224223610783,
    "isSliding": false
  }
}

I'm having a hard time to make sense of the values in expiresAt and expiresAfter.
Why are the miliseconds part changed in expiresAt and the expiresAfter set to an seemingly arbitrary value ?

Also, if the expiresAt value is in the past, once ingested, I get the following :

{"my_service":{"value":{"state":"","name":""}}}

Basically ExpiresAfter exists for storage purposes.

If an entry that is loaded has expired, then it is ignored and not loaded to the runtime.

Otherwise, it will compute ExpiresAfter from that time in the future.

If you put an entry (by loading a service) and say that it expires in 10 mins. If during that 10 mins, you close the app for 2 or 3 minutes, you want those minutes to be taken into count, and not just adding them.

So when it will load 3 minutes later, it will uses ExpiresAt as reference to create ExpriesAfter.

https://github.com/acouvreur/tinykv/blob/45fc921a4a8313a075e6a2559f464fce4f2f1816/tinykv.go#L308-L313

However, you do have a weird behavior. The fact that expiresAt has 2 different formats, and that expiresAt has a value of 1. Which would be incredibly lucky to load 1ms before expiring.

And if a service is loaded "in the past" it should be deleted.

Alright ! Looks clear to me, thanks.

And if a service is loaded "in the past" it should be deleted.
I agree with you, however I think it's weird that the key itself is not deleted, only its values.