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: Handles operation arguments imported as strings #546

Closed
wants to merge 1 commit into from

Conversation

phantomjinx
Copy link
Member

  • Some Operation Arguments retrieved by jolokia are surrounded with quotes hence are handled internally as strings.

  • Using the current mechanism only populates the arg.name parameter, leaving arg.type null, resulting in some ugly errors when OperationArgument is constructed.

  • By checking whether the arg is an Object and if not parsing it mitigates the problem of the quotes

@github-actions
Copy link

github-actions bot commented Sep 11, 2023

Test Results

    8 files  +  1      8 suites  +1   59m 39s ⏱️ + 9m 27s
  57 tests  -   2    54 ✔️ ±  0  1 💤  -   4    2 +  2 
452 runs  +56  428 ✔️ +53  8 💤  - 13  16 +16 

For more details on these failures, see this check.

Results for commit 69be64f. ± Comparison against base commit 03ea6c9.

This pull request removes 4 and adds 2 tests. Note that renamed tests count towards both.
Check whether all data is presented and displayed correctly in About modal window. ‑ Check that the titles are presented in Quarkus About modal window - Names of Hawtio's Components - Example #1.1
Check whether all data is presented and displayed correctly in About modal window. ‑ Check that the titles are presented in Quarkus About modal window - Names of Hawtio's Components - Example #1.2
Check whether all data is presented and displayed correctly in About modal window. ‑ Check that the titles are presented in Spring Boot About modal window - Names of Hawtio's Components - Example #1.1
Check whether all data is presented and displayed correctly in About modal window. ‑ Check that the titles are presented in Spring Boot About modal window - Names of Hawtio's Components - Example #1.2
Check whether all data is presented and displayed correctly in About modal window. ‑ Check that the titles are presented in About modal window - Names of Hawtio's Components - Example #1.1
Check whether all data is presented and displayed correctly in About modal window. ‑ Check that the titles are presented in About modal window - Names of Hawtio's Components - Example #1.2

♻️ This comment has been updated with latest results.

@hawtio-ci
Copy link

hawtio-ci bot commented Sep 11, 2023

Test results

Run attempt: 361
Detailed summary

NAME TESTS PASSED ✅ SKIPPED 💤 FAILED ❌ ERRORS 🚫 TIME 🕖
results-quarkus-node(16)-java(11)-firefox 57 54 1 2 0 408.648
results-quarkus-node(16)-java(17)-firefox 57 54 1 2 0 450.69
results-quarkus-node(18)-java(11)-firefox 57 54 1 2 0 473.637
results-quarkus-node(18)-java(17)-firefox 57 54 1 2 0 424.454
results-springboot-node(16)-java(11)-firefox 56 53 1 2 0 478.121
results-springboot-node(16)-java(17)-firefox 56 53 1 2 0 432.535
results-springboot-node(18)-java(11)-firefox 56 53 1 2 0 487.948
results-springboot-node(18)-java(17)-firefox 56 53 1 2 0 423.877

Copy link
Member

@tadayosi tadayosi left a comment

Choose a reason for hiding this comment

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

Can you provide us with an example of Jolokia requests that you want to address with the fix? I wonder how it happens in the first place.

const args: OperationArgument[] = []
for (const arg of op.args) {
let argObj = arg
if (!isObject(arg)) {
Copy link
Member

Choose a reason for hiding this comment

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

It's still not clear to me why this check is needed. The arg type is defined like this:
https://github.com/hawtio/jolokia.js/blob/dc6bb0c8c8c1f1904b58630c8a1aab9e69ac2f36/index.d.ts#L65-L69
Maybe you can provide us with an example of Jolokia requests that are irregular to the defined type, then we can modify the type definition accordingly. Or it could be a bug in Jolokia that should rather be raised to Jolokia project.

try {
argObj = JSON.parse(arg as string)
} catch (error) {
log.error(`Cannot parse argument ${arg} in operation ${op.desc}`, error)
Copy link
Member

Choose a reason for hiding this comment

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

Oftentimes op.desc doesn't provide enough information, so it's better to use name here.

@tadayosi
Copy link
Member

Also, the code hasn't been changed so much from v2. I wonder why it wasn't a case with the old Hawtio v2. (Or it was?)
https://github.com/hawtio/hawtio-integration/blob/c7d814d3cdd087384a8b3d09cfd6514da9052b81/plugins/jmx/ts/operations/operations.service.ts#L58-L66

    private addOperation(operations: Operation[], operationMap: { [name: string]: Operation },
      opName: string, op: { args: any[], desc: string }): void {
      let operation = new Operation(
        opName,
        op.args.map((arg) => _.assign(new OperationArgument(), arg)),
        op.desc);
      operations.push(operation);
      operationMap[operation.name] = operation;
    }

@phantomjinx
Copy link
Member Author

Screenshot_20230912_102622

I added some console log messages to the existing source to diagnose the problem - see screenshot.

  1. Click on the route node in the camel plugin tree - display the Attributes view;
  2. Click on the Operations view and the result is an exception being thrown;

The reason for the exception is that arg.type is null because arg.name assumes the whole value when the arg is a string.

The console log confirms displays (see 1) that the arg array normally contains properties objects. However, in the case of 'Dumps the route as XML' operation, the arg value is defined as a string (see 2). It seems to be the only arg that is in this form so it may be an error in the dependencies.

If it is a bug further down the stack, then it is probably worth investigating and fixing. However, I think it cautious to check the arguments rather than assume. That was my thinking here.

@phantomjinx
Copy link
Member Author

operation-bug.mp4

Thought a quick video might clarify the process.

@tadayosi
Copy link
Member

@phantomjinx Can you reproduce the issue with the old Hawtio as well?

@tadayosi
Copy link
Member

tadayosi commented Sep 13, 2023

@phantomjinx I cannot reproduce the issue at my end, with either the current 3.x branch of hawtio standalone project or the main branch of hawtio-next and the Spring Boot example.

I added some console log messages to the existing source to diagnose the problem - see screenshot.

Actually, you don't need to insert console.log to just inspect the received mbean tree. Just turn on hawtio-shared-workspace logger to DEBUG level and you'll get the mbean tree loaded in the browser console.

In my case, both dumpStatsAsXml and dumpRouteAsXml operations get the args correctly as objects. I'd suspect the issue is specific to your Camel application setup. We should check which versions of Camel and Jolokia are needed to replicate it.

image

And talking about the fix, if this issue indeed happens in some case and needs to be fixed, I think we should rather fix it earlier than when an operation object is instantiated, somewhere like here:

private unwindResponseWithRBACCache(value: unknown): OptimisedJmxDomains {
if (is(value, object({ domains: object(), cache: object() }))) {
// post process cached RBAC info
for (const domainName in value.domains) {
const domain = value.domains[domainName] as OptimisedJmxDomain | MBeanCache
for (const mbeanName in domain) {
const mbeanOrCache = domain[mbeanName]
if (isString(mbeanOrCache)) {
domain[mbeanName] = value.cache[mbeanOrCache] as OptimisedJmxMBean
}
}
}
return value.domains as OptimisedJmxDomains
}
return value as OptimisedJmxDomains
}

@phantomjinx
Copy link
Member Author

@phantomjinx Can you reproduce the issue with the old Hawtio as well?

Curiously no. The Operation args seem to come through correctly.
Screenshot_20230913_104659

@phantomjinx
Copy link
Member Author

The test application, forked from the main quick-starts, is located here -> https://github.com/phantomjinx/spring-boot-camel/tree/fuse-7.x.redhat

* Some Operation Arguments retrieved by jolokia are surrounded with quotes
  hence are handled internally as strings.

* Using the current mechanism only populates the arg.name parameter, leaving
  arg.type null, resulting in some ugly errors when OperationArgument is
  constructed.

* By checking whether the arg is an Object and if not parsing it mitigates
  the problem of the quotes
@tadayosi
Copy link
Member

The test application, forked from the main quick-starts, is located here -> https://github.com/phantomjinx/spring-boot-camel/tree/fuse-7.x.redhat

@phantomjinx I don't reproduce the issue even with the quickstart you use. I guess you're deploying it to OpenShift and trying to connect to it from hawtio-online, aren't you? Then it should be the issue with the way hawtio-online processes the returned mbeans at its in-the-middle nginx server. See: https://github.com/hawtio/hawtio-online/blob/2.x/docker/nginx.js

If that's the case, let's close this one and instead file this issue to hawtio-online and fix it there.

@phantomjinx
Copy link
Member Author

Closing as discussed. Has not proven to be the case elsewhere and if it occurs again on hawtio-online will investigate with the target being how the latter provides the network data rather than hawtio-next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants