mujx / hakatime

Wakatime server implementation & analytics dashboard
https://hakatime.mtx-dev.xyz
The Unlicense
610 stars 45 forks source link

Forwarding heartbeats to Wakapi #86

Closed BLACK4585 closed 5 months ago

BLACK4585 commented 10 months ago

Hey, I'm trying to forward all received heartbeats to wakapi. For this, I set HAKA_REMOTE_WRITE_URL first to http://localhost:3000/api, then to http://localhost:3000/api/compat/wakatime/v1 after the first option didn't work. Also, I added the HAKA_REMOTE_WRITE_TOKEN. But when I send heartbeats to hakatime, I get this error in the console:

192.168.178.207 - - [31/Aug/2023:21:33:12 +0000] "POST /api/v1/users/current/heartbeats.bulk HTTP/1.1" 202 - "" "wakatime/v1.78.0 (windows-10.0.22621.2215-unknown) go1.21.0 Unknown/0"
 (ConnectionFailure Network.Socket.connect: <socket: 18>: unsupported operation (Address not available)))
}
  redirectCount        = 10
  proxy                = Nothing
  host                 = "localhost"
ts=2023-08-31T21:33:11.075630069Z level=Info host=7847b516cb93 msg=received 1 heartbeats 
VanillaHttpException (HttpExceptionRequest Request {
  secure               = False
  port                 = 3000
  requestHeaders       = [("Authorization","<REDACTED>"),("X-Machine-Name","JonathanPC"),("Content-Type","application/json; charset=utf-8")]
  path                 = "/api"
  queryString          = ""
  method               = "POST"
  rawBody              = False
  responseTimeout      = ResponseTimeoutDefault
  requestVersion       = HTTP/1.1
  proxySecureMode      = ProxySecureWithConnect

All containers are in the bridge network.

Maybe somebody can help me, thank you!

BLACK4585 commented 10 months ago

Update: I changed the HAKA_REMOTE_WRITE_URL to a numerical IP, so just the IP of the machine and now I'm getting this:

ts=2023-08-31T21:42:08.8857236Z level=Info host=80eb58f7ad13 msg=received 1 heartbeats 
VanillaHttpException (HttpExceptionRequest Request {
  host                 = "192.168.178.216"
  port                 = 3000
  secure               = False
  requestHeaders       = [("Authorization","<REDACTED>"),("X-Machine-Name","JonathanPC"),("Content-Type","application/json; charset=utf-8")]
  path                 = "/api"
  queryString          = ""
  method               = "POST"
  proxy                = Nothing
  rawBody              = False
  responseTimeout      = ResponseTimeoutDefault
  redirectCount        = 10
  requestVersion       = HTTP/1.1
  proxySecureMode      = ProxySecureWithConnect
}
 (StatusCodeException (Response {responseStatus = Status {statusCode = 404, statusMessage = "Not Found"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","text/plain; charset=utf-8"),("X-Content-Type-Options","nosniff"),("Date","Thu, 31 Aug 2023 21:42:08 GMT"),("Content-Length","19")], responseBody = (), responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose, responseOriginalRequest = Request {
}) "404 page not found\n"))
192.168.178.207 - - [31/Aug/2023:21:42:08 +0000] "POST /api/v1/users/current/heartbeats.bulk HTTP/1.1" 202 - "" "wakatime/v1.78.0 (windows-10.0.22621.2215-unknown) go1.21.0 Unknown/0"

Is this now an error by Wakapi? Normally the API should be the same, shouldn't it?

grovolis commented 9 months ago

Did you get to the bottom of this @BLACK4585? I'm trying to do the same thing but doesn't work for me either.

BLACK4585 commented 9 months ago

Nope sadly not..

mujx commented 9 months ago

Sorry for the delay on this folks. This seems to be a compatibility issue between the Wakatime server and Wakapi.

@BLACK4585 Could you confirm that you're able to forward the heartbeats to the Wakatime server? If yes then relevant endpoint is not the same between wakapi and wakatime.

BLACK4585 commented 5 months ago

I solved it now by changing HAKA_REMOTE_WRITE_URL to https://wakapi.domain.tld/api/compat/wakatime/v1/users/current/heartbeats.bulk. Maybe you can add this to the Readme.

grovolis commented 5 months ago

I solved it now by changing HAKA_REMOTE_WRITE_URL to https://wakapi.domain.tld/api/compat/wakatime/v1/users/current/heartbeats.bulk. Maybe you can add this to the Readme.

Thanks for the update, I'm going to try it later today, did you need to set a token too?

It works great and of course it needs the token!

mujx commented 5 months ago

Thanks a lot @BLACK4585 for the find. I've added this on the README.