Skip to content

[sight] feat: bridge ilogtail SLS_LOG_PATH into agentsight config via /etc/anolisa/enable_token_collector switch #838

@chengshuyi

Description

@chengshuyi

Component

sight

Problem Statement

agentsight currently reads its SLS log upload path from runtime.sls_logtail_path in agentsight.json, but ilogtail is the canonical source of the cloud-distributed log path (SLS_LOG_PATH in /etc/anolisa/ilogtail.cfg). Operators need a switch that opts agentsight into ilogtail's path without manually editing the JSON config.

Proposed Solution

Add a background watcher thread that polls /etc/anolisa/enable_token_collector once per second:

  • When the trigger file exists, parse SLS_LOG_PATH from /etc/anolisa/ilogtail.cfg (INI key=value, supports single/double quotes) and write it to runtime.sls_logtail_path of the agentsight config file.
  • When the trigger file is removed, clear runtime.sls_logtail_path (write empty string).

The existing config-watcher detects the resulting IN_CLOSE_WRITE and activates the SLS LogtailExporter. This commit only adds the bridging layer — SLS activation logic is unchanged.

Implementation highlights:

  • Enable serde_json preserve_order so JSON field order stays stable across rewrites.
  • State machine caches last applied state to skip redundant disk writes.
  • write_runtime_sls_path() is idempotent (no-op when value unchanged).
  • Hardcoded production paths and 1s poll interval (no extra public API).

Alternatives Considered

  • Embedding ilogtail.cfg parsing into the existing config-watcher: rejected — keeps watcher responsibilities mixed and forces tighter coupling to ilogtail's INI format.
  • Inotify-only watch on the enable_file: rejected — file deletion + recreation cycles are simpler and more reliable to handle via 1s polling; deletions still propagate within 1 polling window.

Additional Context

  • Tests:
    • 13 unit tests in src/unified.rs (read parsing + JSON rewriting + state-machine simulation).
    • scripts/int-test-token-collector.sh integration script: 9/9 PASS on a non-ECS host (phase 2 auto-skipped) and 10/10 PASS on a real ECS host with valid metadata where the disable→clear path is exercised end-to-end.
  • Compatibility: Existing SLS uid validation guard at AgentSight::new() is unchanged; bridging cannot loosen the safety check.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions