metatype icon indicating copy to clipboard operation
metatype copied to clipboard

fix(cli): muti-typegraph bug + logging polish

Open Yohe-Am opened this issue 1 year ago • 3 comments
trafficstars

  • Fixes multi-typegraph deployment bug.
  • Fixes issue with loader process existing after cli death.
  • Replaces anyhow with color-eyre in cli and improved logging story.
  • interlude pattern was used to minimize changes by wrapping eyre through an anyhow export.
  • [ ] Tests

MET-516 MET-517 MET-477

Summary by CodeRabbit

  • New Features

    • Added new platform support for "x86_64-linux" and new version entry "v2.4.0" in the platform configurations.
    • Introduced new dependencies and features in Cargo.toml to enhance functionality and performance.
    • Implemented new error handling and logging features across various modules to improve debugging and user feedback.
  • Bug Fixes

    • Corrected typos in authentication configurations from "authentification" to "authentication".
    • Fixed error handling in test functions to provide clearer context and error messages.
  • Refactor

    • Updated numerous modules to utilize a unified error handling approach using color-eyre and tracing libraries.
    • Restructured imports and dependencies across various CLI commands for better modularity and maintainability.
  • Style

    • Standardized error messages and logging formats across the application to enhance readability and consistency.
  • Documentation

    • Updated internal documentation to reflect changes in configurations and dependencies.

Yohe-Am avatar May 13 '24 05:05 Yohe-Am

Walkthrough

The updates encompass multiple areas: platform migration from "aarch64-darwin" to "x86_64-linux" in .ghjk/lock.json, dependency modifications in Cargo.toml files, and extensive refactoring across various Rust files. These changes improve error handling, logging, and dependency management, transitioning from anyhow to color-eyre, and incorporating the tracing library for better instrumentation and debugging.

Changes

File(s) Change Summary
.ghjk/lock.json Updated platform from "aarch64-darwin" to "x86_64-linux", added new entry with version "v2.4.0".
Cargo.toml Added features to tokio, introduced new dependencies (tracing, color-eyre, etc.).
examples/metatype.yaml Corrected typos in keys and values.
libs/common/src/node.rs Enhanced base_url initialization with error context handling.
libs/metagen/Cargo.toml Replaced anyhow with color-eyre.
libs/metagen/src/lib.rs Replaced anyhow imports with color_eyre::eyre, improved error message formatting.
libs/metagen/src/tests/mod.rs Modified error handling in spin_up_typegate function.
meta-cli/Cargo.toml Added and removed various dependencies, updated features and workspace settings.
meta-cli/src/cli/... Multiple files updated for import restructuring, adding tracing::instrument, and modifying error handling.
meta-cli/src/com/... Multiple files updated for import restructuring, error handling adjustments, and improved logging.

These changes collectively enhance platform compatibility, dependency management, error handling, and logging throughout the codebase.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar May 13 '24 05:05 coderabbitai[bot]

Sample screenshots:

When lade errors out: image

At the end of typegraph deployment if errors were seen: image

Yohe-Am avatar May 13 '24 05:05 Yohe-Am

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 74.06%. Comparing base (bbdfd35) to head (72db3af).

Files Patch % Lines
typegate/tests/utils/metadev.ts 40.00% 3 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #717      +/-   ##
==========================================
+ Coverage   74.05%   74.06%   +0.01%     
==========================================
  Files         120      120              
  Lines       13777    13776       -1     
  Branches     1407     1407              
==========================================
+ Hits        10202    10203       +1     
+ Misses       3549     3547       -2     
  Partials       26       26              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 17 '24 04:05 codecov[bot]

@coderabbitai based on the patterns established in typegate/tests/e2e/cli/dev_test.ts and typegate/tests/e2e/website/website_test.ts, generate a new test file inside typegate/tests/e2e/cli/ that directory that has tests for deployment of multiple typegraphs at once. Name a few typegraphs from the examples directory and specify them using the -f flag.

Yohe-Am avatar May 17 '24 06:05 Yohe-Am

[!TIP] For best results, initiate chat on the files or code changes.

New Test File: typegate/tests/e2e/cli/multi_typegraph_deploy_test.ts

// Copyright Metatype OÜ, licensed under the Elastic License 2.0.
// SPDX-License-Identifier: Elastic-2.0

import { Meta } from "test-utils/mod.ts";
import { MetaDev } from "test-utils/metadev.ts";
import { join } from "std/path/mod.ts";
import { assert } from "std/assert/mod.ts";
import { gql } from "test-utils/mod.ts";
import { TestModule } from "test-utils/test_module.ts";
import { $ } from "dax";

const m = new TestModule(import.meta);

Meta.test({
  name: "meta dev: deploy multiple typegraphs",

  gitRepo: {
    content: {
      "metatype.yml": "metatype.yml",
    },
  },
}, async (t) => {
  const typegraphs = [
    "examples/typegraphs/basic.py",
    "examples/typegraphs/authentication.py",
    "examples/typegraphs/graphql-server.py",
  ];

  const metadev = await MetaDev.start({
    cwd: t.workingDir,
    args: [
      "deploy",
      "--target=dev",
      `--gate=http://localhost:${t.port}`,
      "--secret",
      `multi-typegraph-test:POSTGRES=postgresql://postgres:password@localhost:5432/db`,
      ...typegraphs.map(tg => `-f ${tg}`),
    ],
  });

  await metadev.fetchStderrLines((line) => {
    console.log("line:", line);
    return !$.stripAnsi(line).includes(
      "Successfully pushed typegraph",
    );
  });

  await t.should("verify typegraphs are deployed", async () => {
    for (const tg of typegraphs) {
      const tgName = tg.split("/").pop()?.replace(".py", "");
      const e = t.getTypegraphEngine(tgName);
      if (!e) {
        throw new Error(`typegraph ${tgName} not found`);
      }
      await gql`
        query {
          __typename
        }
      `
        .expectData({
          __typename: "Query",
        })
        .on(e);
    }
  });

  await metadev.close();
});

Explanation:

  • The new test file multi_typegraph_deploy_test.ts is created in the typegate/tests/e2e/cli/ directory.
  • The test deploys multiple typegraphs (basic.py, authentication.py, and graphql-server.py) at once using the -f flag.
  • The test verifies that each typegraph is successfully deployed by querying the __typename field.

@Yohe-Am, I have created the new test file multi_typegraph_deploy_test.ts in the typegate/tests/e2e/cli/ directory. This test deploys multiple typegraphs at once and verifies their deployment. Let me know if any further adjustments are needed.

Analysis chain


Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Fetch the contents of the test files
cat typegate/tests/e2e/cli/dev_test.ts
cat typegate/tests/e2e/website/website_test.ts

# List typegraphs from the examples directory
ls typegate/examples/

Length of output: 8811



Script:

#!/bin/bash
# Search for the correct path to the examples directory
fd examples

Length of output: 23



Script:

#!/bin/bash
# List typegraphs in the examples directory
ls examples/

Length of output: 61



Script:

#!/bin/bash
# List typegraphs in the examples/typegraphs directory
ls examples/typegraphs/

Length of output: 1192

coderabbitai[bot] avatar May 17 '24 06:05 coderabbitai[bot]