Skip to content

Make configurable via environment variable & fix typos in profiler trace filenames #2742

Description

@iamfaham

Make profiling_directory configurable via environment variable & fix typos in profiler trace filenames

Search Before Asking


Feature Description

Following the merge of PR #2732 (which addressed the read-only filesystem crash from #1110), the profiling subsystem now gracefully handles OSError when writing traces. However, the output directory itself is still hardcoded as "./inference_profiling" in two separate locations with no environment variable override — making it the only pipeline/profiling setting that can't be configured at deploy time.

Current state

In inference/core/env.py (lines 1036–1037), the profiling feature already has two env vars:

ENABLE_WORKFLOWS_PROFILING = str2bool(os.getenv("ENABLE_WORKFLOWS_PROFILING", "False"))
WORKFLOWS_PROFILER_BUFFER_SIZE = int(os.getenv("WORKFLOWS_PROFILER_BUFFER_SIZE", "64"))

And the sibling pipeline configs all follow the env-var pattern:

Setting Env Var Default
Predictions queue size INFERENCE_PIPELINE_PREDICTIONS_QUEUE_SIZE 512
Restart attempt delay INFERENCE_PIPELINE_RESTART_ATTEMPT_DELAY 1
Video source buffer size VIDEO_SOURCE_BUFFER_SIZE 64
Profiling enabled ENABLE_WORKFLOWS_PROFILING False
Profiler buffer size WORKFLOWS_PROFILER_BUFFER_SIZE 64
Profiling directory ❌ none hardcoded "./inference_profiling"

The hardcoded default appears in:

  1. inference/core/interfaces/stream/inference_pipeline.py line 503 — init() method parameter default
  2. inference_sdk/http/entities.py line 150 — InferenceConfiguration dataclass field default

Proposed change

Add a new environment variable WORKFLOWS_PROFILING_DIRECTORY to inference/core/env.py:

WORKFLOWS_PROFILING_DIRECTORY = os.getenv("WORKFLOWS_PROFILING_DIRECTORY", "./inference_profiling")

Then import and use it as the default in both locations above instead of the hardcoded string.

Why this matters

  1. Containerised deployments (Docker, K8s): The working directory inside a container is often read-only or ephemeral. While PR fix: handle OSError on read-only filesystem during profiling #2732 made the crash non-fatal, users still can't direct profiling output to a writable mounted volume without modifying the source code or passing the directory through the Python API every time.

  2. Consistency: Every other profiling/pipeline knob has an env var. The directory is the sole exception — an easy oversight to fix.

  3. SDK usage: InferenceConfiguration in the SDK also hardcodes the same path. An env var gives a single, code-free control point for both the HTTP server and SDK clients.

  4. Observability pipelines: In production, teams often want traces written to a shared volume (e.g. /data/profiling) for collection by a sidecar. An env var makes this a one-line Docker Compose / Helm values change.


Bonus: Typo fixes in profiler trace filenames

Two typos exist in the profiler trace output that produce malformed filenames:

1. Missing 'r' in track — inference/core/interfaces/stream/utils.py line 142

# Current (typo):
f"inference_pipeline_workflow_execution_tack_{formatted_time}.json"
# Should be:
f"inference_pipeline_workflow_execution_track_{formatted_time}.json"

2. Same typo in the SDK — inference_sdk/http/utils/profilling.py line 21

# Current (typo):
f"workflow_execution_tack_{formatted_time}.json"
# Should be:
f"workflow_execution_track_{formatted_time}.json"

3. missmatch → mismatch — inference/core/interfaces/stream/utils.py line 43

# Current (typo):
error_description="Cannot apply `video_source_properties` to video sources due to missmatch in "
# Should be:
error_description="Cannot apply `video_source_properties` to video sources due to mismatch in "

Note: missmatch appears in several other files across the codebase (stream_manager, workflows, inference_models). Those could be addressed in a follow-up cleanup PR if desired, but the two above are directly in the profiling code path.


Example Usage

Docker

docker run \
  -e ENABLE_WORKFLOWS_PROFILING=True \
  -e WORKFLOWS_PROFILING_DIRECTORY=/data/profiling \
  -v /host/profiling:/data/profiling \
  roboflow/inference:latest

Docker Compose

services:
  inference:
    image: roboflow/inference:latest
    environment:
      ENABLE_WORKFLOWS_PROFILING: "True"
      WORKFLOWS_PROFILING_DIRECTORY: "/data/profiling"
    volumes:
      - ./profiling:/data/profiling

Helm / K8s

env:
  - name: ENABLE_WORKFLOWS_PROFILING
    value: "True"
  - name: WORKFLOWS_PROFILING_DIRECTORY
    value: "/mnt/profiling"

Suggested implementation (happy to submit a PR)

  1. inference/core/env.py — add after line 1037:

    WORKFLOWS_PROFILING_DIRECTORY = os.getenv("WORKFLOWS_PROFILING_DIRECTORY", "./inference_profiling")
  2. inference/core/interfaces/stream/inference_pipeline.py line 503 — change default:

    profiling_directory: str = WORKFLOWS_PROFILING_DIRECTORY,
  3. inference_sdk/http/entities.py line 150 — change default:

    profiling_directory: str = WORKFLOWS_PROFILING_DIRECTORY,
  4. Fix typos in utils.py (lines 43, 142) and profilling.py (line 21) as described above.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions