-
Notifications
You must be signed in to change notification settings - Fork 32
Feat/telemetry export clean #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
theap06
wants to merge
16
commits into
facebookresearch:main
Choose a base branch
from
theap06:feat/telemetry-export-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a6e5845
feat: add telemetry exporter for structured JSON/CSV export (#87)
theap06 d16392f
fix: correct expected UTC timestamp in telemetry exporter tests
theap06 e3f37d8
fix: satisfy nox format and typecheck
theap06 4f00cf7
changed to supporting csv
theap06 3f82227
added the shutdown for the nox checking
theap06 1b51ad7
Update gcm/exporters/file.py
theap06 184a18e
fixed the telemetry file and added the final else
theap06 961b5b7
feat: add CSV format support to file exporter
theap06 dc4c714
Merge branch 'feat/telemetry-export-clean' of https://github.com/thea…
theap06 20ec9d8
fixed the logic in file.py
theap06 f659f0a
Update gcm/exporters/file.py
theap06 c8ec6a2
fixed the issues with style checker
theap06 67af3df
Clean PR scope and clarify CSV docs
theap06 489555d
Fix file exporter CSV test expectations
theap06 a151464
Roll CSV output to new file on schema change
theap06 a2dec03
Reuse CSV writer buffer per batch
theap06 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| import csv | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
|
|
||
| from gcm.exporters.file import File | ||
| from gcm.monitoring.sink.protocol import DataIdentifier, SinkAdditionalParams | ||
| from gcm.schemas.log import Log | ||
|
|
||
|
|
||
| @dataclass | ||
| class SamplePayload: | ||
| job_id: int | ||
| state: str | ||
| user: str | ||
|
|
||
|
|
||
| @dataclass | ||
| class OtherSamplePayload: | ||
| gpu_uuid: str | ||
| memory_used_mb: int | ||
|
|
||
|
|
||
| def test_file_exporter_csv(tmp_path: Path) -> None: | ||
| path = tmp_path / "data.csv" | ||
| sink = File(file_path=str(path), format="csv") | ||
| sink.write( | ||
| Log(ts=1000, message=[SamplePayload(job_id=1, state="RUNNING", user="alice")]), | ||
| SinkAdditionalParams(data_identifier=DataIdentifier.GENERIC), | ||
| ) | ||
| sink.write( | ||
| Log(ts=2000, message=[SamplePayload(job_id=2, state="PENDING", user="bob")]), | ||
| SinkAdditionalParams(data_identifier=DataIdentifier.GENERIC), | ||
| ) | ||
| with open(path) as f: | ||
| rows = list(csv.DictReader(f)) | ||
| assert len(rows) == 2 | ||
| assert rows[0]["state"] == "RUNNING" | ||
| assert rows[0]["user"] == "alice" | ||
| assert rows[1]["state"] == "PENDING" | ||
| assert rows[1]["user"] == "bob" | ||
|
|
||
|
|
||
| def test_file_exporter_csv_rolls_over_on_schema_change(tmp_path: Path) -> None: | ||
| path = tmp_path / "data.csv" | ||
| sink = File(file_path=str(path), format="csv") | ||
|
|
||
| sink.write( | ||
| Log(ts=1000, message=[SamplePayload(job_id=1, state="RUNNING", user="alice")]), | ||
| SinkAdditionalParams(data_identifier=DataIdentifier.GENERIC), | ||
| ) | ||
| sink.write( | ||
| Log( | ||
| ts=2000, | ||
| message=[OtherSamplePayload(gpu_uuid="GPU-123", memory_used_mb=2048)], | ||
| ), | ||
| SinkAdditionalParams(data_identifier=DataIdentifier.GENERIC), | ||
| ) | ||
|
|
||
| lines = path.read_text().splitlines() | ||
| assert lines == [ | ||
| "job_id,state,user", | ||
| "1,RUNNING,alice", | ||
| ] | ||
|
|
||
| path_rollover = tmp_path / "data_1.csv" | ||
| rollover_lines = path_rollover.read_text().splitlines() | ||
| assert rollover_lines == [ | ||
| "gpu_uuid,memory_used_mb", | ||
| "GPU-123,2048", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.