Skip to content

fix: send a device connection outcome only when it changes - #2170

Merged
yansfil merged 1 commit into
mainfrom
fix/device-analytics-retries
Nov 6, 2026
Merged

yansfil merged 1 commit into
mainfrom
fix/device-analytics-retries

Conversation

@yansfil

@yansfil yansfil commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Summary

등록된 원격 기기가 꺼져 있으면 앱은 1분마다 다시 접속하는데, 그 재시도 하나하나가 hide_device_connected 실패 이벤트로 나갔습니다.
그래서 PostHog의 기기 이벤트 20,270건 중 약 19,000건이 꺼진 기기 몇 대의 재시도였고, 한 설치본은 62시간 동안 2,853건을 보냈습니다.
이제 기기마다 마지막으로 보낸 결과를 기억해 두고, 결과가 바뀔 때만 보냅니다: 계속 꺼져 있는 기기는 실패 한 건, 잠들었다 다시 붙은 기기는 추가 성공 없음.

스크린샷 없음: 화면이 아닌 사용 통계 전송만 바뀝니다.

Review

  • 판단해 주세요: 같은 결과의 반복은 이 데몬이 켜져 있는 동안 한 번만 셉니다. 사용자가 다시 연결을 눌러 같은 이유로 또 실패해도 새로 세지 않습니다. "기기 상태가 바뀐 횟수"로 읽는 게 맞는지.
  • 조심해서 볼 파일: herdr-core/src/runtime/device_analytics.rs - runtime mutex 안에서 도는 경로. 추가 작업은 기기 id로 찾는 BTreeMap 한 번이고, 기기 128대에서 상한(넘으면 진단 로그 남기고 매번 전송).
  • 조심해서 볼 파일: herdr-core/src/runtime/devices.rs - 기기를 지우면 기억한 결과도 지웁니다.

Evidence

  • 확인한 것: PostHog에서 실패 이벤트 간격을 재니 15,316건이 30~90초 간격, 상위 설치본은 시간당 약 113건. 운영자 맥의 로그로 같은 패턴(win 기기 SSH 시간 초과 반복) 확인.
  • 확인한 것: 새 테스트 device_connect_statistics_send_only_a_changed_outcome(실패 3회 -> 성공 -> 실패 2회 = 이벤트 3건), 기존 재연결 테스트는 성공 1건으로 바뀜. herdr-core의 device/analytics 테스트 311개 통과, fmt-check, clippy -D warnings 통과.
  • 확인하지 못한 것: 설치된 앱에서 실제 PostHog로 나가는 건수는 재지 않았습니다. 배포 후 PostHog에서 설치본별 실패 건수가 수천에서 한 자릿수로 줄어드는지 봐야 합니다.
Verification record
  • base: fae16bf1d (origin/main)
  • scripts/verify-cargo.sh nextest -p herdr-core --lib -E 'test(/device/) | test(/analytics/)': 311 passed
  • scripts/verify-cargo.sh fmt-check, scripts/verify-cargo.sh clippy -p herdr-core --all-targets -- -D warnings: pass

A device that stays unreachable is retried every minute, and each retry
sent its own failed event: a few offline devices produced about 19,000
of the 20,000 device events. The runtime now remembers the outcome last
sent per device and sends the next one only when it differs, so a
retry streak counts as one failure and a reconnect after sleep sends
nothing.
@yansfil
yansfil added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 2df79f5 Nov 6, 2026
74 of 76 checks passed
@yansfil
yansfil deleted the fix/device-analytics-retries branch November 6, 2026 15:13
HyunjunJeon pushed a commit to HyunjunJeon/hide that referenced this pull request Nov 9, 2026
…with-hide#2172)

Related: with-hide#2170 (이 PR의 base, 먼저 머지)

## Summary

기기 연결 실패 이벤트가 `install`/`download` 단계만 알려 줘서, 기기를 한 번도 연결하지 못한 설치본 17대가
왜 실패했는지 PostHog로 알 수 없었습니다.
이제 실패 이벤트에 `failure` 속성을 붙입니다: 기기 행이 이미 쓰는 SSH 분류(`ssh_unreachable`,
`ssh_sign_in_refused`, `ssh_host_key_changed` 등 13가지)나 실패한
단계(`no_transport`, `helper_lost`, `kit_refused`, `kit_failed` 등).
닫힌 목록만 보내고 오류 원문은 보내지 않습니다: 원문에는 호스트 이름, 주소, 경로가 들어 있어 로컬 로그에만 남습니다.

스크린샷 없음: 화면이 아닌 사용 통계 전송만 바뀝니다.

## Review

- **판단해 주세요**: 개인정보 안내에 적힌 전송 항목에 `failure`(닫힌 분류)가 하나 늘어납니다. 안내 문서를 고쳐야
하는지.
- **판단해 주세요**: `failed_step`은 PostHog의 기존 대시보드를 위해 남겼고, 이제 `failure`에서
계산됩니다(`download`만 `download`, 나머지는 `install`).
- **조심해서 볼 파일**: `herdr-core/src/product_analytics.rs` - 전송 어휘의 유일한 주인.
SSH 분류는 `SshProblem`을 match로 하나씩 적어서, 분류가 늘면 컴파일이 막힙니다.
- **조심해서 볼 파일**: `herdr-core/src/runtime/device_analytics.rs`,
`hosts.rs`, `devices.rs`, `kit.rs` - 실패 경로마다 분류를 붙였습니다. 이유가 다르면 #2170의
"같은 결과는 한 번만" 비교에서도 다른 결과로 셉니다.

## Evidence

- **확인한 것**: `a_device_failure_names_its_class_and_never_its_text`(전송
속성), 꺼진 기기 재시도 테스트가 `ssh_unreachable` 실패 한 건만 보냄, SSH 설정에 없는 별칭 등록은
`no_transport`, 키트 실패는 `kit_failed`. herdr-core device/analytics 테스트
312개와 hided analytics 테스트 2개 통과, fmt-check, clippy `-D
warnings`(herdr-core, hided) 통과.
- **확인하지 못한 것**: 실제 PostHog 수신은 확인하지 않았습니다. 배포 후 `failure`별 분포를 보면 됩니다.

<details><summary>Verification record</summary>

- base: `5c0530a87` (with-hide#2170 head), head: `2f3a3ae82`
- `scripts/verify-cargo.sh nextest -p herdr-core --lib -E
'test(/device/) | test(/analytics/)'`: 312 passed
- `scripts/verify-cargo.sh nextest -p hided -E 'test(/analytics/)'`: 2
passed
- `scripts/verify-cargo.sh fmt-check`, `clippy -p herdr-core -p hided
--all-targets -- -D warnings`: pass

</details>
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.

1 participant