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

Open
#2,742 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
75/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
backend, devops

Research direction

Start with the profiling settings in inference/core/env.py, then trace their defaults through inference/core/interfaces/stream/inference_pipeline.py and inference_sdk/http/entities.py. Review the profiler filename construction in inference/core/interfaces/stream/utils.py and inference_sdk/http/utils/profilling.py; done means the directory can be selected through WORKFLOWS_PROFILING_DIRECTORY and the listed profiler typos are corrected.

Written by the indexing model from the issue text.

Description

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

Search Before Asking

  • I searched the Issues and did not find a duplicate.
  • Related: #1110 (read-only filesystem profiling crash, fixed by PR #2732)

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 #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.

Dominant language
Python
Stars
2.5k
Forks
340
Avg merge
2d 11h
Merged PRs (30d)
92

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from roboflow/inference

All issues in roboflow/inference

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.