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: migration parser #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat: migration parser #1

wants to merge 4 commits into from

Conversation

skl
Copy link
Member

@skl skl commented Aug 7, 2024

First attempt at a migration tool, see unit tests for usage.

  • Uses the lezer PromQL parser with full access to the AST
  • Uses the TypeScript Compiler API to generate TypeScript code
    • I did first create the source file using the full Compiler API but that added hundreds of lines of code. So I simplified and went with plain old template strings instead. However, to proceed further with the tool, may need to revert back to the full Compiler API. Ran out of time to take this further in the Hackathon though.

Example

Input PromQL string:

foo{bar="baz",qux!~"quux"}

Output TypeScript code:

const foo = (values: {
    bar?: string;
    qux?: string;
}) => new Expression({
    metric: "foo",
    values,
    defaultOperator: MatchingOperator.equal,
    defaultSelectors: [{ label: "bar", operator: MatchingOperator.equal, value: "" }, { label: "qux", operator: MatchingOperator.notRegexMatch, value: "" }],
}).toString();

@skl skl self-assigned this Aug 9, 2024
@skl skl requested a review from jewbetcha August 9, 2024 18:11
@skl skl marked this pull request as ready for review August 9, 2024 18:11
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.

1 participant