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

feat: Add autocomplete of metrics attributes #623

Open
wants to merge 5 commits into
base: warren/metrics-mvp
Choose a base branch
from

Conversation

teeohhem
Copy link

@teeohhem teeohhem commented Feb 20, 2025

Adds backend call to grab attributes for a metric + adds them to autocomplete suggestions.

Ref: HDX-1402

Copy link

changeset-bot bot commented Feb 20, 2025

⚠️ No Changeset found

Latest commit: 67f94dd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

import { getClickhouseClient } from '@/clickhouse';
import { formatAttributeClause } from '@/utils';

const METRIC_FETCH_LIMIT = 25;
Copy link
Author

Choose a reason for hiding this comment

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

just an arbitrary limit I chose. Happy to adjust as needed

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be able to safely set this into the thousands?

Copy link
Author

Choose a reason for hiding this comment

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

Ok cool. I started low to error on the side of caution. I also saw in V1 there was a top 10 suggestion limit of some sort.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure which limit but if it's something as low as 10 it's probably just a rendering limit to keep the DOM happy, we're usually relatively aggressive with these limits if the user can't tweak them on their own so it's less likely whatever they're looking for won't appear.

@@ -339,6 +317,7 @@ export function SQLInlineEditorControlled({
table={table}
value={field.value || props.defaultValue}
connectionId={connectionId}
additionalSuggestions={additionalSuggestions}
Copy link
Author

Choose a reason for hiding this comment

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

This adds the ability to arbitrarily add suggestions to autocomplete that aren't already based on a source. I didn't see a way to do this, but correct me if I'm wrong!

? `ResourceAttributes['${field}'] = '${value}'`
: `ResourceAttributes.${field}:"${value}"`;
}

Copy link
Author

Choose a reason for hiding this comment

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

Just moving this function into utils so it can be used in other places as well.

Copy link
Contributor

@MikeShi42 MikeShi42 left a comment

Choose a reason for hiding this comment

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

just a few nice to have improvements that we can follow up with later

import { getClickhouseClient } from '@/clickhouse';
import { formatAttributeClause } from '@/utils';

const METRIC_FETCH_LIMIT = 25;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be able to safely set this into the thousands?

const clickhouseClient = getClickhouseClient();

const sql = chSql`
SELECT
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to do select distinct?

Copy link
Author

Choose a reason for hiding this comment

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

updated in latest commit, as well as increasing the initial limit

query_params: sql.params,
format: 'JSON',
abort_signal: signal,
connectionId: tableSource!.connection,
Copy link
Contributor

Choose a reason for hiding this comment

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

it may be nice to also add a row scan limit

clickhouse_settings: {
max_rows_to_read: DEFAULT_SAMPLE_SIZE,
read_overflow_mode: 'break',
},

Copy link
Author

Choose a reason for hiding this comment

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

New ticket created: HDX-1410

@@ -17,6 +17,7 @@ export default function SearchInputV2({
connectionId,
enableHotkey,
onSubmit,
additionalSuggestions,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this works for now, though I wonder if the v1 pattern of having a separate metrics tag filter input would be cleaner? We can leave it as a follow up.

https://github.com/hyperdxio/hyperdx/blob/main/packages/app/src/MetricTagFilterInput.tsx

Copy link
Author

Choose a reason for hiding this comment

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

I like that idea. Will add a ticket to follow up on this and the other suggestions. Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

New ticket created: HDX-1410

Comment on lines 98 to 100
FROM ${tableName}
WHERE MetricName='${metricName}'
LIMIT ${METRIC_FETCH_LIMIT.toString()}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: we want to parameterize query like

FROM ${tableExpr({ database: databaseName, table: tableName })}
WHERE MetricName=${{ String: metricName }}
LIMIT ${{ Int32: METRIC_FETCH_LIMIT}}

Copy link
Author

Choose a reason for hiding this comment

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

Addressed in latest commit

abort_signal: signal,
connectionId: tableSource!.connection,
})
.then(res => res.json())) as ResponseJSON<{ Attributes: object }>;
Copy link
Contributor

@wrn14897 wrn14897 Feb 21, 2025

Choose a reason for hiding this comment

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

{
  ScopeAttributes?: Record<string, string>;
  ResourceAttributes?: Record<string, string>;
  Attributes?: Record<string, string>;
}

Copy link
Author

Choose a reason for hiding this comment

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

Good catch

Copy link
Author

Choose a reason for hiding this comment

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

Addressed in latest commit

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

Successfully merging this pull request may close these issues.

3 participants