Implement user-specified target definitions #472
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Initial backend support for #468.
Perhaps there should also be some metadata added to
ServiceRef
s to mark their source, ex. platform detection vs manually added, but that is currently not implemented.Here we have two new V2 API handlers, for
POST /api/v2/targets
andDELETE /api/v2/targets/:targetId
.The
POST
request checks if there are any existing targets with an identical service URL and fails if so. If not, then a newServiceRef
is created using the service URL and alias provided (byPOST
form attributes) and tracked by the newCustomTargetPlatformClient
.The
DELETE
request simply removes anyServiceRef
from theCustomTargetPlatformClient
which matches the specifiedtargetId
path parameter.The
CustomTargetPlatformClient
simply maintains an internal sorted set ofServiceRef
s withadd
/remove
methods to mutate this state. It also persists the state to disk on each write operation, and loads this state from disk whenstart()
ed. This allows the user's custom target definitions to survive service restarts (assuming the configuration directory is mounted somewhere that will survive a restart - this is not the case by default inrun.sh
/smoketest.sh
).Results from the
CustomTargetPlatformClient
are combined with the pre-existing platform-specific client by the newMergingPlatformClient
, which is pretty self-explanatory.Frontend support for this feature will come later.
To test, use websocat and curl or httpie. The following steps use httpie.
Start container.
CRYOSTAT_IMAGE=quay.io/andrewazores/cryostat:custom-targets
Connect to notification channel.
$ websocat -kE wss://0.0.0.0:8181/api/v1/command
Create a new custom target definition.
$ http --verify=false -f POST https://0.0.0.0:8181/api/v2/targets connectUrl="service:jmx:rmi:///jndi/rmi://cryostat:9099/jmxrmi" alias="Fake"
Observe that this target is
FOUND
in the notification channel stream.Check that it is reflected in the API results - it should be listed first.
$ http --verify=false https://0.0.0.0:8181/api/v1/targets
Delete the custom target definition.
$ http --verify=false DELETE https://0.0.0.0:8181/api/v2/targets/service%3Ajmx%3Armi%3A%2F%2F%2Fjndi%2Frmi%3A%2F%2Fcryostat%3A9099%2Fjmxrmi
Again observe that the target is
LOST
in the notification channel stream.Check that it is no longer reflected in the API result.
$ http --verify=false https://0.0.0.0:8181/api/v1/targets
The web-client UI already has support for the notification events emitted since they reuse the existing platform discovery notification category and type information, so the
POST
/DELETE
effects can also be seen in the graphical target list.