Skip to content

feat: Add charts API #811

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

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open

feat: Add charts API #811

wants to merge 2 commits into from

Conversation

teeohhem
Copy link
Contributor

@teeohhem teeohhem commented May 13, 2025

  • Utilizes renderChartConfig and CH client to query for chart data
  • Implements API input schema
  • Adds lots of tests

Testing Notes:

  • To use swagger, go to localhost:8000/api/v2/docs
  • Authorize using your access key found in localhost:8000/me
  • Under the charts route, click "Try it out"
  • Use example payload:
{
  "startTime": <insert valid timestamp ms>,
  "endTime": <insert valid timestamp ms>,
  "granularity": "1h",
  "series": [
    {
      "sourceId": "<insert valid sourceid>",
      "aggFn": "count",
      "where": "SeverityText:error",
      "groupBy": []
    }
  ]
}

It was easiest for me to go to the UI, create a new chart and grab the sourceid and start/end timestamps from the URL, plug it in and profit.

Note: It was apparent to me that we will need to provide at least GET support for sources, otherwise that ID is not easily obtained.

Ref: HDX-1651

Copy link

changeset-bot bot commented May 13, 2025

⚠️ No Changeset found

Latest commit: cba16e6

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

Copy link

vercel bot commented May 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hyperdx-v2-oss-app ❌ Failed (Inspect) May 15, 2025 4:48pm


// Convert first letter to lowercase to match common-utils expectations
return metricType.charAt(0).toLowerCase() + metricType.slice(1);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will clean this up.

TL;DR zod schema uses MetricDataType from the clickhouse package which has values that are title cased. Everywhere else, we use MetricDataType from common-utils which has values that are lowercase.

'1d',
'2d',
'7d',
'30d',
Copy link

Choose a reason for hiding this comment

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

is it possible to use the keys from the record above to produce this list? it seems funny that it's the same set of strings in both.

Copy link

Choose a reason for hiding this comment

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

I guess the only difference is that the test set allows 1 second of granularity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeahhhh def will clean that up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

@@ -44,12 +43,15 @@ export const numberFormatSchema = z.object({
export const timeChartSeriesSchema = z.object({
table: z.optional(sourceTableSchema),
type: z.literal('time'),
aggFn: aggFnSchema,
aggFn: AggregateFunctionSchema,
level: z.number().optional(),
Copy link

Choose a reason for hiding this comment

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

Not sure if it matters but level represents a percentile value so it's more than just a number, it also needs to be between [0, 1]. Not sure if we want to try to bake that into the schema or not. I don't believe it is in common-utils either but doesn't seem like it holds up to user input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good callout ty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

groupBy: z.array(z.string()).max(10),
numberFormat: numberFormatSchema.optional(),
metricDataType: z.optional(z.nativeEnum(MetricsDataType)),
metricName: z.optional(z.string()),
Copy link

Choose a reason for hiding this comment

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

Does this do something different that z.string().optional()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same difference. I'll make it consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

@teeohhem teeohhem marked this pull request as ready for review May 15, 2025 16:51
@teeohhem teeohhem requested a review from dhable May 15, 2025 16:51
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