Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 7, 2025

Summary

This PR implements the --record (or -r) command line option for crank-agent to enable recording custom measurements that are automatically added to every benchmark job the agent runs.

Motivation

Agents often need to record system-specific information like OpenSSL version, kernel version, or environment configuration for every benchmark. Previously, there was no way to automatically capture this information without modifying each benchmark. This feature allows administrators to configure custom measurements once at agent startup, which then apply to all benchmarks.

Usage

The new option accepts name=value pairs and can be specified multiple times. Command substitution is handled by the shell before the arguments reach the agent:

# Simple values
crank-agent --record "environment=production" --record "region=us-west"

# Command substitution on Linux/macOS (shell expands before agent receives)
crank-agent --record "system/openssl=$(openssl version)" \
            --record "system/kernel=$(uname -r)" \
            --record "system/hostname=$(hostname)"

# Command substitution on Windows PowerShell
crank-agent --record "system/dotnet=$(dotnet --version)" `
            --record "system/os=$(systeminfo | Select-String 'OS Name')"

# Short form
crank-agent -r "test=value" -r "other=$(date)"

Implementation Details

Format:

  • Name and value are separated by the first = character
  • Names must be non-empty
  • Values can be empty strings

Command Substitution:

  • Handled by the shell before arguments reach the agent
  • The agent receives the already-expanded values
  • No command execution is performed by the agent itself

Automatic Addition:

  • Custom measurements are added to job.Measurements when each job starts
  • Metadata is automatically created with sensible defaults (Operation.First for Aggregate/Reduce)
  • Duplicate metadata is prevented

Error Handling:

  • Invalid formats (missing =, empty name): logged as warnings and skipped
  • All errors are non-fatal to agent startup

Example Output

When a job runs on an agent started with --record "system/openssl=$(openssl version)", the results will include:

Measurement:

{
  "name": "system/openssl",
  "timestamp": "2024-02-23T13:01:56.12Z",
  "value": "OpenSSL 3.0.13 30 Jan 2024"
}

Metadata:

{
  "source": "Agent",
  "name": "system/openssl",
  "aggregate": "First",
  "reduce": "First",
  "format": "",
  "longDescription": "Custom measurement: system/openssl",
  "shortDescription": "system/openssl"
}

Changes

  • Added _recordOption command line option with -r|--record flags
  • Added _customMeasurements dictionary to store parsed measurements
  • Enhanced MarkAsRunning() to add custom measurements and metadata to each job
  • Added comprehensive documentation in docs/measurements.md

Security Considerations

The agent reads values directly from command line arguments provided by the administrator. Command substitution is handled by the shell, not by the agent, following standard Unix conventions. The database should not record sensitive information per the issue requirements.

Fixes #847

Original prompt

This section details on the original issue you should resolve

<issue_title>Record specific measurements from the agent</issue_title>
<issue_description>The agent application should accept a custom command line argument to define custom measurements. For instance we could record the openssl version, or the kernel version, ...

We shouldn't be concerned about sensitive information since the db should not record these. Hence we can just pass the values to the command line even if they come from ENV.

A possible usage would be:

crank-agent --record "system/openssl=$(openssl version -v)"
  • The name and value are separated by the first = char.
  • Switches could be -r|--record.
  • For each benchmark that this agent runs the value would be added automatically.
  • The argument usage should be repeatable.
    </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #847

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits October 7, 2025 14:25
Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
Copilot AI changed the title [WIP] Record specific measurements from the agent Add --record option to crank-agent for custom measurements Oct 7, 2025
Copilot AI requested a review from sebastienros October 7, 2025 14:41
@sebastienros
Copy link
Member

@copilot The agent should not do command substitution. This should be handled by the shell itself. Just read the raw value from the argument.

Co-authored-by: sebastienros <1165805+sebastienros@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 7, 2025

@copilot The agent should not do command substitution. This should be handled by the shell itself. Just read the raw value from the argument.

Done. Removed the ProcessCommandSubstitution method and related logic. The agent now reads the raw value from the argument, and the shell handles command substitution before the arguments reach the agent. Updated documentation to clarify this behavior. (7782a75)

continue;
}

var separatorIndex = recordValue.IndexOf('=');
Copy link
Member

Choose a reason for hiding this comment

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

By splitting the string with recordValue.Split('=', 2) there is no need to do substring after.

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.

Record specific measurements from the agent

2 participants