naver / scavenger

A runtime dead code analysis tool
Apache License 2.0
400 stars 43 forks source link

Fix H2 in-memory set up #133

Closed kusalk closed 1 week ago

kusalk commented 2 weeks ago

Currently, Scavenger does not work with the default run configuration as the Collector and Web UI create their own independent in-memory databases. Thus, new workspaces/customers created on the Web UI are not present in the Collector.

This results in the following error when the Java Agent tries to connect to the Collector with a seemingly valid API key: sc.io.grpc.StatusRuntimeException: UNAUTHENTICATED

The jdbc:h2:mem url will only refer to the same database when connected to from the same classloader, as explained in the H2 documentation. When trying to connect to the same database across independent processes, the database should be accessed over TCP instead.

This PR implements this change.

sohyun-ku commented 1 week ago

@kusalk Thank you for your contribution :) But I think using h2 profile will solve the problem that you mentioned. please refer follows,

https://github.com/naver/scavenger/blob/develop/doc/installation.md#install-collector The collector uses in-memory H2 in local profile. This means that the data is initialised every time the collector application starts. If you want to work around this using file mode, you can enable the h2 profile.

kusalk commented 1 week ago

Hi @sohyun-ku

The h2 profile is for enabling file persistence of the database. This PR is for fixing the in-memory db (local profile) set up. Currently it doesn't work unless both the Collector and WebUI are run within the same JVM, otherwise it will create 2 independent in-memory databases.

In my testing, the following occurs:

Is this not your experience when using the default local profile to run both the WebUI and Collector?

sohyun-ku commented 1 week ago

@kusalk It needs order to run collector and api in local profile, but it seems good to me :) Could you also add an explanation for this?

@taeyeon-Kim @kojandy what do you think?

kusalk commented 1 week ago

@sohyun-ku

It needs order to run collector and api in local profile, but it seems good to me :) Could you also add an explanation for this?

And you are able to create a new workspace and connect the Java agent?