Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk heartbeat error #203

Closed
k4rli opened this issue May 18, 2021 · 7 comments
Closed

Bulk heartbeat error #203

k4rli opened this issue May 18, 2021 · 7 comments
Labels
bug Something isn't working discussion prio a

Comments

@k4rli
Copy link

k4rli commented May 18, 2021

Description

Wakatime with VSCode fails to sync data with Wakapi. It keeps attempting POST /api/heartbeat/v1/users/current/heartbeats.bulk but it fails. This has suddenly happened, no errors before yesterday.

{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:16:51+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:16:55+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:17:00+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:18:28+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:18:48+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:19:40+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:20:31+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:20:48+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/pkg/language/language.go:41","func":"1","level":"warning","message":"failed to detect language on file entity \"/home/waves/.wakatime.log\": could not detect the language of file \"/home/waves/.wakatime.log\"","now":"2021-05-19T00:22:01+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:22:01+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:24:20+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/today/today.go:42","func":"Run","level":"error","message":"failed fetching summaries from api: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/summaries\". got: 404, want: 200. body: \"404 page not found\\n\"","now":"2021-05-19T00:24:28+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/pkg/heartbeat/heartbeat.go:65","func":"New","level":"warning","message":"failed to resolve the real path of \"/home/waves/projects/work/holm/tasks\": lstat /home/waves/projects/work/holm/tasks: no such file or directory","now":"2021-05-19T00:24:29+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:24:33+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/pkg/language/language.go:41","func":"1","level":"warning","message":"failed to detect language on file entity \"/home/waves/.wakatime.log\": could not detect the language of file \"/home/waves/.wakatime.log\"","now":"2021-05-19T00:24:38+03:00","version" for me:"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.g for meo:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:24:38+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:26:59+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/pkg/language/language.go:41","func":"1","level":"warning","message":"failed to detect language on file entity \"/home/waves/.wakatime.log\": could not detect the language of file \"/home/waves/.wakatime.log\"","now":"2021-05-19T00:28:19+03:00","version":"v1.6.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/legacy/heartbeat/heartbeat.go:45","func":"Run","level":"error","message":"failed to send heartbeat(s): failed to send heartbeats via api client: invalid response status from \"http://hawaii:3000/api/heartbeat/v1/users/current/heartbeats.bulk\". got: 404, want: 201/202. body: \"404 page not found\\n\"","now":"2021-05-19T00:28:19+03:00","version":"v1.6.0"}

Expected result

Worklogs are synced with Wakapi successfully.

@muety
Copy link
Owner

muety commented May 19, 2021

Thanks for bringing this up! From what I found, you'll probably not be the only one to have this issue in the future. The problem is that the above URL is indeed invalid. It's supposed to be /api/v1/users/current/heartbeats.bulk instead.

Possible solution

Change api_url in ~/.wakatime.cfg from https://wakapi.dev/api/hearbeat to https://wakapi.dev/api and everything should be fine again.

Problem cause

My assumption on how this came to happen is this. WakaTime is currently migrating from their "legacy" Python-based CLI (wakatime/wakatime) to a Go-rewrite (wakatime/wakatime-cli) of it. I'm not sure how the rollout is done (would be interesting to know, though!), but probably you already got the new CLI, while other users (including me) still have the old one. It looks like there was a change to what the API's base URL has to look like. I think it used to be meant only for heartbeats, so was previously called /api/heartbeat, but is more generally used now (see https://github.com/wakatime/wakatime/issues/260), so the new prefix must be /api.

This is quite problematic, as any Wakapi user's setup would stop working the moment the update to the new CLI and until they manually change their config.

Maybe @alamhamlett has more details on the problem and an idea how to overcome this?

@muety
Copy link
Owner

muety commented May 19, 2021

Update: I pushed a workaround so the old URL format still keeps working. I'd still recommend to update your config.

@muety muety closed this as completed May 19, 2021
@k4rli
Copy link
Author

k4rli commented May 19, 2021

Nice job, very quick response 👍 Thanks.

@alanhamlett
Copy link
Contributor

The launch happens for all VSCode users currently, unless you have legacy_python_cli = false in your ~/.wakatime.cfg file. However, we've been rolling back the launch when finding bugs so at this moment it's still using the Python wakatime-cli.

Before we launch again, we'll fix this without any changes to your cfg or wakapi. The fix will be adding api_base_url and keeping api_url as a legacy config for backwards compatibility.

@alanhamlett
Copy link
Contributor

@muety can you release an update to wakapi that adds endpoint:

/api/v1/users/current/heartbeats.bulk

We're changing wakatime-cli to strip /heartbeat from end of api_url for backwards compatibility without needing any change in users' ~/.wakatime.cfg files, but it still appends /v1/users/current/heartbeats.bulk to the base url. Together with adding this wakapi endpoint and wakatime/wakatime-cli#451, we can pave the way to fix #153 by adding a Summaries endpoint to wakapi.

@muety
Copy link
Owner

muety commented Jun 9, 2021

@alanhamlett The requested endpoint should be present already.

r.PathPrefix("/v1/users/{user}/heartbeats").Methods(http.MethodPost).HandlerFunc(h.Post)

This is a prefix matcher, i.e. any request with a path starting with /v1/users/{user}/heartbeats (which includes /v1/users/{user}/heartbeats.bulk) is matched by this route. This might not be the most elegant solution, but it works for the moment. Did you try accessing the endpoint?

@krishnans2006
Copy link

krishnans2006 commented Feb 22, 2022

Update: Happened to me on PyCharm (and I'm assuming any JetBrains IDEs). A similar fix worked.

First, went to .wakatime.log to see a similar error:

{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:246","func":"runCmd","level":"error","message":"failed to run command: today fetch failed: api error: failed fetching today from api: invalid response status from \"https://wakatime.com/api/users/current/statusbar/today\". got: 404, want: 200. body: \"{\\\"error\\\":\\\"Not found\\\"}\\n\"","now":"2022-02-21T19:43:20-05:00","version":"v1.37.0"}
{"caller":"/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:246","func":"runCmd","level":"error","message":"failed to run command: sending heartbeat(s) later due to api error: won't send heartbeat due to backoff","now":"2022-02-21T19:44:00-05:00","version":"v1.37.0"}

Updated .wakatime.cfg to change api_url from https://wakatime.com/api/ to https://wakatime.com/api/v1/.

On IDE restart, saw a bunch of offline scripts run on the log file, and all my activity in the past that wasn't synced showed up on the dashboard. All was resolved!

Edit: This worked until updating the plugin just today - worked all of yesterday and today morning. So although it probably isn't caused by the same update, the same fix worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discussion prio a
Projects
None yet
Development

No branches or pull requests

4 participants