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

fix(discovery): fix broken DISABLE_BUILTIN_DISCOVERY env var #1506

Merged
merged 6 commits into from
Jun 1, 2023

Conversation

andrewazores
Copy link
Member

Welcome to Cryostat! 👋

Before contributing, make sure you have:

  • Read the contributing guidelines
  • Linked a relevant issue which this PR resolves
  • Linked any other relevant issues, PR's, or documentation, if any
  • Resolved all conflicts, if any
  • Rebased your branch PR on top of the latest upstream main branch
  • Attached at least one of the following labels to the PR: [chore, ci, docs, feat, fix, test]
  • Signed the last commit: git commit --amend --signoff

Fixes: #1505

Description of the change:

This does some refactoring to ensure that the Custom Targets functionality is always available, even when the environment variable CRYOSTAT_DISABLE_BUILTIN_DISCOVERY is set, and so that setting that environment variable does not result in a startup-blocking exception.

Motivation for the change:

It may be useful in some situations to disable the built-in discovery mechanisms entirely. A Cryostat instance locked down in this way can be sure to never discover any target applications other than ones registered manually using Custom Targets, or ones configured using the Cryostat Agent.

How to manually test:

  1. CRYOSTAT_IMAGE=quay.io... CRYOSTAT_DISABLE_BUILTIN_DISCOVERY=true sh smoketest.sh
  2. Verify that the container started successfully
  3. https :8181/api/v2.1/discovery to ensure that only the Custom Targets Realm is reported

@mergify mergify bot added the safe-to-test label May 30, 2023
@andrewazores andrewazores requested a review from tthvo May 30, 2023 20:04
@andrewazores andrewazores changed the title fix(discovery): fix broken DISABLE_BUILT_DISCOVERY env var fix(discovery): fix broken DISABLE_BUILTIN_DISCOVERY env var May 30, 2023
@tthvo
Copy link
Member

tthvo commented May 30, 2023

Code looks good but I am not sure something is missing because the built-in discovery is still enabled with (using image built from this PR commit):

CRYOSTAT_DISABLE_BUILTIN_DISCOVERY=true sh smoketest.sh

image

now that multiple platforms can be used in parallel, they do not need to have a priority for checking availability
@andrewazores
Copy link
Member Author

$ CRYOSTAT_DISABLE_BUILTIN_DISCOVERY=true sh smoketest.sh

image

$ https --auth-type=basic --auth=user:pass :8181/api/v2.1/discovery
HTTP/1.1 200 OK
content-encoding: gzip
content-length: 999
content-type: application/json
{
    "data": {
        "result": {
            "children": [
                {
                    "children": [
                        {
                            "id": -432439206,
                            "labels": {},
                            "name": "http://localhost:8910/",
                            "nodeType": "JVM",
                            "target": {
                                "alias": "vertx-fib-demo-1",
                                "annotations": {
                                    "cryostat": {
                                        "HOST": "cryostat",
                                        "JAVA_MAIN": "es.andrewazor.demo.Main -javaagent:/opt/jib-agents/cryostat-agent-0.2.2.jar",
                                        "PID": "1",
                                        "PORT": "8910",
                                        "REALM": "vertx-fib-demo-1",
                                        "START_TIME": "1685480129"
                                    },
                                    "platform": {}
                                },
                                "connectUrl": "http://localhost:8910/",
                                "jvmId": "OzsZcRCrIZo00q0VvVX_j_7XwBHQfzqw5MNmMiXSolc=",
                                "labels": {}
                            }
                        }
                    ],
                    "id": 622503342,
                    "labels": {
                        "REALM": "db441505-c3be-44b0-8be5-63c416ae9323"
                    },
                    "name": "vertx-fib-demo-1",
                    "nodeType": "Realm"
                },
                {
                    "children": [
                        {
                            "id": -2088431488,
                            "labels": {},
                            "name": "http://localhost:8911/",
                            "nodeType": "JVM",
                            "target": {
                                "alias": "vertx-fib-demo-2",
                                "annotations": {
                                    "cryostat": {
                                        "HOST": "cryostat",
                                        "JAVA_MAIN": "es.andrewazor.demo.Main -javaagent:/opt/jib-agents/cryostat-agent-0.2.2.jar",
                                        "PID": "1",
                                        "PORT": "8911",
                                        "REALM": "vertx-fib-demo-2",
                                        "START_TIME": "1685480129"
                                    },
                                    "platform": {}
                                },
                                "connectUrl": "http://localhost:8911/",
                                "jvmId": "M_nb6vAVZWFzpLF140qloFnzhYuOsWc-fS2nMWG0NQ4=",
                                "labels": {}
                            }
                        }
                    ],
                    "id": 1613802238,
                    "labels": {
                        "REALM": "a17a77ad-9ae3-4f14-97ba-b7c32e851e8a"
                    },
                    "name": "vertx-fib-demo-2",
                    "nodeType": "Realm"
                },
                {
                    "children": [
                        {
                            "id": 813146660,
                            "labels": {},
                            "name": "http://localhost:8912/",
                            "nodeType": "JVM",
                            "target": {
                                "alias": "vertx-fib-demo-3",
                                "annotations": {
                                    "cryostat": {
                                        "HOST": "cryostat",
                                        "JAVA_MAIN": "es.andrewazor.demo.Main -javaagent:/opt/jib-agents/cryostat-agent-0.2.2.jar",
                                        "PID": "1",
                                        "PORT": "8912",
                                        "REALM": "vertx-fib-demo-3",
                                        "START_TIME": "1685480129"
                                    },
                                    "platform": {}
                                },
                                "connectUrl": "http://localhost:8912/",
                                "jvmId": "idNwhKBD4Ow2iNZi3RHeqU_CMFTJrJhJmGQ3drFavTc=",
                                "labels": {}
                            }
                        }
                    ],
                    "id": 1754892022,
                    "labels": {
                        "REALM": "d14a044f-f794-4f2d-84a5-b31a333261e8"
                    },
                    "name": "vertx-fib-demo-3",
                    "nodeType": "Realm"
                },
                {
                    "children": [
                        {
                            "id": -163233355,
                            "labels": {},
                            "name": "service:jmx:rmi:///jndi/rmi://cryostat:9097/jmxrmi",
                            "nodeType": "JVM",
                            "target": {
                                "alias": "quarkus-test-agent",
                                "annotations": {
                                    "cryostat": {
                                        "HOST": "cryostat",
                                        "JAVA_MAIN": "/deployments/quarkus-run.jar",
                                        "PID": "1",
                                        "PORT": "-1",
                                        "REALM": "quarkus-test-agent",
                                        "START_TIME": "1685480129"
                                    },
                                    "platform": {}
                                },
                                "connectUrl": "service:jmx:rmi:///jndi/rmi://cryostat:9097/jmxrmi",
                                "jvmId": "kDJLGwATFCHKY_sTWZM_9vZ_mmBnNNGMvS_0_54FJB0=",
                                "labels": {}
                            }
                        }
                    ],
                    "id": 1827072391,
                    "labels": {
                        "REALM": "1b8c77ad-6e8f-44ab-8bba-bf4eac1f8372"
                    },
                    "name": "quarkus-test-agent",
                    "nodeType": "Realm"
                },
                {
                    "children": [
                        {
                            "id": -1576634802,
                            "labels": {},
                            "name": "http://localhost:9988/",
                            "nodeType": "JVM",
                            "target": {
                                "alias": "quarkus-test-agent",
                                "annotations": {
                                    "cryostat": {
                                        "HOST": "cryostat",
                                        "JAVA_MAIN": "/deployments/quarkus-run.jar",
                                        "PID": "1",
                                        "PORT": "9988",
                                        "REALM": "quarkus-test-agent",
                                        "START_TIME": "1685480130"
                                    },
                                    "platform": {}
                                },
                                "connectUrl": "http://localhost:9988/",
                                "jvmId": "do5_f7fTao7uU4V80FYlFt62RuMhiDaSIHmAZ_771Jw=",
                                "labels": {}
                            }
                        }
                    ],
                    "id": 1487758365,
                    "labels": {
                        "REALM": "54a8f2b1-3dbf-448c-bb37-e02cd45fcc58"
                    },
                    "name": "quarkus-test-agent",
                    "nodeType": "Realm"
                },
                {
                    "children": [],
                    "id": -511444528,
                    "labels": {
                        "REALM": "add51184-c47d-4d72-8131-41bab315802c"
                    },
                    "name": "Custom Targets",
                    "nodeType": "Realm"
                }
            ],
            "id": 1171029256,
            "labels": {},
            "name": "Universe",
            "nodeType": "Universe"
        }
    },
    "meta": {
        "status": "OK",
        "type": "application/json"
    }
}

The latest commit does some cleanup which should also fix a conflict between Custom Targets and JDP that existed before. Though, I don't think that should have caused the builtins to still appear for you.

@tthvo
Copy link
Member

tthvo commented May 30, 2023

Hmm weird. I built the image with mvn clean package -DskipTests=true and ran the same scripts :((

@andrewazores
Copy link
Member Author

Maybe try sh smoketest.sh h2mem? Maybe the old entries are just hanging out in the database still?

@tthvo
Copy link
Member

tthvo commented May 30, 2023

Ohh totally forgot about that again. Worked fine with h2mem. We don't yet have any handler to prune discovery database right?

@andrewazores
Copy link
Member Author

I'll give it some thought. I think what I should do is set it up so that any disabled builtins have their subtrees automatically pruned from the discovery tree, ie drop the whole Realm. There is no ongoing whole-tree pruning that happens, that is expected to be done by each plugin at the Realm level, or by the plugins themselves registering and deregistering (or failing to respond to heartbeat pings).

@tthvo
Copy link
Member

tthvo commented May 30, 2023

I think what I should do is set it up so that any disabled builtins have their subtrees automatically pruned from the discovery tree, ie drop the whole Realm.

Sounds good! Makes sense to me! I guess other things just gonna be intergration test is failing as it expects more targets than actual.

@andrewazores
Copy link
Member Author

It looks like I already thought of that mechanism:

        unselectedStrategies.stream()
                .map(PlatformDetectionStrategy::getPlatformClient)
                .forEach(
                        platform ->
                                storage.getBuiltInPluginByRealm(
                                                platform.getDiscoveryTree().getName())
                                        .map(PluginInfo::getId)
                                        .ifPresent(storage::deregister));

That's in the startup for the BuiltInDiscovery. Not sure why it didn't work.

@github-actions
Copy link
Contributor

Test image available:

$ CRYOSTAT_IMAGE=ghcr.io/cryostatio/cryostat:pr-1506-f60092314eb66e0cd9d5254c54134468b8773d7c sh smoketest.sh

@andrewazores
Copy link
Member Author

That's in the startup for the BuiltInDiscovery. Not sure why it didn't work.

The last refactoring probably fixed this, and also fixed the broken integration test. The earlier refactoring I did in this PR broke some of how the DI setup was put together, so things were not all @Singleton as they should have been, so the determination of which platforms were selected and which were not selected was broken.

@github-actions
Copy link
Contributor

Test image available:

$ CRYOSTAT_IMAGE=ghcr.io/cryostatio/cryostat:pr-1506-5cb0e49b5c09e70cdaf71201184df76b754c0f7a sh smoketest.sh

Copy link
Member

@tthvo tthvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Fixed the issue!

@andrewazores andrewazores merged commit dda9672 into cryostatio:main Jun 1, 2023
@andrewazores andrewazores deleted the disabled-discovery-bug branch June 1, 2023 13:05
mergify bot pushed a commit that referenced this pull request Jun 1, 2023
* fix(discovery): fix broken DISABLE_BUILT_DISCOVERY env var

* remove no longer necessary 'priority' for platforms

(cherry picked from commit dda9672)
andrewazores added a commit that referenced this pull request Jun 1, 2023
…1509)

* fix(discovery): fix broken DISABLE_BUILT_DISCOVERY env var

* remove no longer necessary 'priority' for platforms

(cherry picked from commit dda9672)

Co-authored-by: Andrew Azores <aazores@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

[Bug] CRYOSTAT_DISABLE_BUILTIN_DISCOVERY environment variable does not work
2 participants