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 missing historical metrics in trino-jmx #12782

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xmuyoo
Copy link
Member

@xmuyoo xmuyoo commented Jun 10, 2022

Description

The historical metrics of resource groups in jmx.history are missing.

Here's the reasons:

  1. Some mbeans may be registered to MBeanServer after server launch,
    like metrics of resource groups. So that we must refresh the dynamic
    mbean tables regularly.

  2. It should use table name instead of object name to get records
    from JmxHistoricalData, since on mbeans with attribute name and type,
    the table name is different from object name.

See: #12781

Related issues, pull requests, and links

Documentation

( ) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

( ) No release notes entries required.
( ) Release notes entries required with the following suggested text:

# trino-jmx
* trino-jmx missing resource group metrics ({issue}`https://github.com/trinodb/trino/issues/12781`)

@xmuyoo
Copy link
Member Author

xmuyoo commented Jun 10, 2022

#12781

@xmuyoo xmuyoo added the bug Something isn't working label Jun 13, 2022
@xmuyoo xmuyoo requested a review from electrum June 13, 2022 06:43
@xmuyoo xmuyoo self-assigned this Jun 16, 2022
1) Some mbeans may be registered to MBeanServer after server launch,
like metrics of resource groups. So that we must refresh the dynamic
mbean tables regularly.

2) It should use table name instead of object name to get records
from JmxHistoricalData, since on mbeans with attribute name and type,
the table name is different from object name.
@xmuyoo xmuyoo force-pushed the fix-missing-history-metircs-trino-jmx branch from 1c810c8 to df9931d Compare June 16, 2022 09:53
@xmuyoo xmuyoo requested review from aakashnand and removed request for Praveen2112 and aakashnand July 1, 2022 02:59
@findepi findepi requested review from arhimondr and removed request for findepi August 2, 2022 18:32
Copy link
Member

@Praveen2112 Praveen2112 left a comment

Choose a reason for hiding this comment

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

Nice catch. Thanks for fixing this.

Comment on lines +96 to 103
public synchronized List<List<Object>> getRows(String tableName, List<Integer> selectedColumns)
{
String lowerCaseObjectName = objectName.toLowerCase(Locale.ENGLISH);
if (!tableData.containsKey(lowerCaseObjectName)) {
String lowerCaseTableName = tableName.toLowerCase(Locale.ENGLISH);
if (!tableData.containsKey(lowerCaseTableName)) {
return ImmutableList.of();
}
return projectRows(tableData.get(lowerCaseObjectName), selectedColumns);
return projectRows(tableData.get(lowerCaseTableName), selectedColumns);
}
Copy link
Member

Choose a reason for hiding this comment

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

Since we maintain the information for each JMXObject - I think objectName is a correct terminology here

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we need to maintain consistency with addRow


for (String tableName : tables) {
tableData.put(tableName, EvictingQueue.create(maxEntries));
}

MBeanServerNotificationFilter filter = new MBeanServerNotificationFilter();
filter.enableAllObjectNames();
Copy link
Member

Choose a reason for hiding this comment

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

Can we specify object name as filters ?

@@ -91,4 +114,42 @@ private List<List<Object>> projectRows(Collection<List<Object>> rows, List<Integ
}
return result.build();
}

public class AddDynamicTableListener
Copy link
Member

Choose a reason for hiding this comment

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

Can we unify this with mbeanServer#queryNames - so we could add an entry to the Map if it is matched and we could rewrite getTables to tableData#keySet.

@@ -54,16 +56,9 @@ public JmxPeriodicSampler(
this.jmxRecordSetProvider = requireNonNull(jmxRecordSetProvider, "jmxRecordSetProvider is null");
requireNonNull(jmxConfig, "jmxConfig is null");
this.period = jmxConfig.getDumpPeriod().toMillis();
this.jmxMetadata = jmxMetadata;
Copy link
Member

Choose a reason for hiding this comment

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

Can we add require non-null check here ?

rows = tableHandle.getObjectNames().stream()
.flatMap(objectName -> jmxHistoricalData.getRows(objectName, selectedColumns).stream())
.collect(toImmutableList());
rows = ImmutableList.copyOf(jmxHistoricalData.getRows(tableHandle.getTableName().getTableName(), selectedColumns));
Copy link
Member

Choose a reason for hiding this comment

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

I think - we don't need this change. A JMXTableName could be a regex and it could match with a bunch of JMXObjects to we need to do a flatmapping and fetch the information for all the objects which matches the query pattern.

Comment on lines +130 to +132
this.tableNames = tableNames;
this.tableData = tableData;
this.tables = tables;
Copy link
Member

Choose a reason for hiding this comment

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

rnn checks.

Comment on lines +91 to +93
if (tableData.containsKey(lowerCaseTableName)) {
tableData.get(lowerCaseTableName).add(row);
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we revert this ? We should throw an error if the table doesn't exist

assertEquals(jmxHistoricalData.getRows(TABLE_NAME, columns), ImmutableList.of());

StandardMBean newMBean = new StandardMBean(new ArrayList<>(), List.class);
mbeanServer.registerMBean(newMBean, ObjectName.getInstance(ON_FLY_TABLE_NAME));
Copy link
Member

Choose a reason for hiding this comment

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

Instead of injecting a new Bean can we try accessing the InternalResourceGroup - mentioned in the actual issue ?

@mosabua
Copy link
Member

mosabua commented Jan 15, 2024

👋 @xmuyoo - this PR has become inactive. We hope you are still interested in working on it. Please let us know, and we can try to get reviewers to help with that.

Cc @Praveen2112

We're working on closing out old and inactive PRs, so if you're too busy or this has too many merge conflicts to be worth picking back up, we'll be making another pass to close it out in a few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cla-signed
Development

Successfully merging this pull request may close these issues.

None yet

3 participants