mirrord Documentation

repository·main·Indexed 26 days ago

https://github.com/metalbear-co/mirrord

mirrord allows developers to run local processes inside a live Kubernetes cluster by mirroring traffic, files, and environment variables from a target pod. The documentation covers the mirrord CLI, the mirrord-agent, the mirrord-layer, and the MirrordConfig derive macro. It also provides installation and usage guides for VS Code and IntelliJ plugins, Prometheus metrics configuration for the agent, and build instructions using xtask.

Tokens
17.8K
Snippets
31
Records
133
Agent score
90%

What's inside mirrord

  1. Understand the mirrord exec execution flow

    main

    When running mirrord exec, the CLI performs several steps: parsing configuration, resolving the target, and initializing the connection.

    Depending on your setup:

    • If an Operator is enabled: The CLI requests the mirrord Operator to create the mirrord Agent.
    • If no Operator is enabled: The CLI creates the mirrord Agent directly via the Kubernetes API.

    Once the agent is ready, an internal proxy is started. On macOS, the binary is patched before execution. The user binary then communicates through the internal proxy, which forwards messages to the mirrord Agent.

  2. Review external contributions with increased scrutiny

    main

    Code from external contributors (those not currently under contract with the company) requires higher caution than internal contributions.

    • No Trust-Based Approvals: Do not approve external PRs based on trust or use the 'approving with unresolved comments' pattern used for internal staff.
    • Independent Verification: The reviewer is responsible for independently verifying the correctness of the code and performing active quality control.
  3. Review code for correctness and clarity

    main

    When reviewing code, ensure you can fully understand it to guarantee maintainability and extensibility. If the code is unclear, ask the author to refactor it or add comments.

    Key questions to ask during review:

    • What is the code change supposed to achieve? (Authors should link an issue or provide clear context).
    • How is the goal achieved? (The solution and logic should be clear even without reading the code).
    • Is the code doing what it is supposed to do? (Verify via tests and ensure complex processes are broken into simple, testable components).
  4. Understand mirrord Wizard Modes

    main

    The mirrord Wizard allows users to generate a mirrord.json configuration file using one of three primary modes:

    • Filtering Mode (steal): Performs selective traffic stealing using HTTP header or path filters.
    • Mirror Mode: Copies traffic to the local environment without disrupting the remote service.
    • Replace Mode: Completely substitutes the remote service by combining copy_target (enabled + scale down) with steal mode.

    Business Rules for Modes:

    • Replace Mode: Sets copy_target.enabled=true, copy_target.scale_down=true, and `incoming.mode=
  5. Handle QA requests during code review

    main

    Reviewers are not responsible for performing active Quality Assurance (QA) of new code.

    If an author requires a reviewer to run the code (e.g., for UI changes that are difficult to test automatically), the author must:

    1. Ask specifically for the review to include running the code.
    2. Provide exact, step-by-step instructions for execution.
  6. Uphold code standards and style guidelines

    main

    Reviewers should ensure new code follows the repository's current standards and best practices.

    • Style Requirements: If a style change is required, point to the relevant documented style guide. If no guide exists, the reviewer should propose one and seek team approval.
    • Avoiding Blockers: Style discussions should not block a merge if users or releases are waiting. If a consensus isn't reached, allow the merge, but open an issue for the author to address the style improvement later once a team decision is made.
    • Suggestions vs. Requirements: Clearly distinguish between comments that require resolution and those that are merely suggestions/matters of taste.
  7. Use the mirrord CLI to execute processes

    main

    The mirrord-cli is the primary binary used to run mirrord. It facilitates process execution by injecting mirrord into the target binary using LD_PRELOAD on Linux or DYLD_INSERT_LIBRARIES on macOS.

    To execute a process within a specific Kubernetes pod, use the mirrord exec command followed by the --pod-name flag and the binary you wish to run.

    mirrord exec --pod-name <POD_NAME> <BINARY> [BINARY_ARGS..]
  8. Install the mirrord VS Code Extension

    main

    You can install the mirrord extension for VS Code via the Visual Studio Marketplace to run local processes inside a live Kubernetes cluster.

    https://marketplace.visualstudio.com/items?itemName=MetalBear.mirrord
  9. Avoid using 'local' in agent code naming

    main
    To prevent ambiguity between the agent's scope and the user's system scope, do not use the term local in variable or struct names within agent code. Instead, use specific scope identifiers such as agent, cluster, pod, container, layer, or user_application.
  10. Install the mirrord CLI Tool

    main

    Depending on your operating system or package manager, use one of the following commands to install the mirrord CLI:

    macOS (Homebrew):

    brew install metalbear-co/mirrord/mirrord

    Shell Script:

    curl -fsSL https://raw.githubusercontent.com/metalbear-co/mirrord/main/scripts/install.sh | bash

    Nix (Recommended):

    nix profile install nixpkgs#mirrord

    Nix (Legacy):

    nix-env -iA nixpkgs.mirrord

    Windows (Chocolatey):

    choco install --pre mirrord
    brew install metalbear-co/mirrord/mirrord