Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/sdk-compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
dockerfile: sdk_compliance_adapter/Dockerfile.socket
- consumer: fork_curl
dockerfile: sdk_compliance_adapter/Dockerfile.fork_curl
uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@6414114501396d96aadf2412fdd8054a03076782
uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@dde638562d33572b5c8ac3a2eafc98b92ffa2261
with:
adapter-dockerfile: ${{ matrix.dockerfile }}
adapter-context: "."
test-harness-version: "1.0.0"
test-harness-version: "1.32.0"
report-name: sdk-compliance-${{ matrix.consumer }}
sdk-type: server
concurrency: 1
Expand Down
13 changes: 8 additions & 5 deletions sdk_compliance_adapter/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# PostHog PHP SDK compliance adapter

The adapter runs the repository's `PostHog\Client` with production capture consumers
and production `HttpClient` feature-flag requests. Harness 1.0.0 selects **30 server
and production `HttpClient` feature-flag requests. Harness 1.32.0 selects **30 server
capture V0 tests and 17 flag tests per profile**, including UTC timestamp overrides
and gzip. No tests are filtered; compliance assertions remain advisory in CI.

Expand All @@ -15,7 +15,7 @@ and gzip. No tests are filtered; compliance assertions remain advisory in CI.

CI runs all three profiles with distinct report artifacts. An independent
`report-completeness` job checks each artifact against `expected_inventory.json`
(the harness 1.0.0 server V0 and flags IDs). Missing, empty, incomplete, duplicate,
(the harness 1.32.0 server V0 and flags IDs). Missing, empty, incomplete, duplicate,
or unexpected results and inconsistent summary counts fail this gate. Complete
reports with failing assertions still pass the inventory gate; SDK compliance
assertions remain advisory. The checker reads the pinned harness's Markdown result
Expand All @@ -28,9 +28,12 @@ uncompressed HTTP client even when capture compression is enabled.

The adapter maps `flush_at` to `batch_size` and `flush_interval_ms` to
`flush_interval_seconds` (SDK default: 5 seconds, enforced on enqueue, not an idle
timer). `max_retries` maps to the existing backoff-duration option: for three
retries, 801 ms for HttpClient and 800 ms for Socket and foreground ForkCurl,
reflecting their different limit checks. Socket's connection
timer). When `max_retries` is omitted, the SDK's native 10000 ms maximum
backoff duration is preserved, including for Retry-After. An explicit `max_retries`
maps to the existing backoff-duration option: for three retries, 801 ms for
HttpClient and 800 ms for Socket and foreground ForkCurl, reflecting their different
limit checks. This mapping also caps Retry-After at that duration; the SDK has no
independent ingestion retry-count option. Socket's connection
timeout is expressed in seconds; the PHP worker's `default_socket_timeout=1`
bounds reads, including idle retry connections. This is a configured runtime
profile, not certification of default PHP socket timing.
Expand Down
6 changes: 4 additions & 2 deletions sdk_compliance_adapter/adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function handleRequest(array $request, AdapterState $state): array
[$normalizedHost, $useSsl] = normalizeHost($host);
$flushAt = max(1, (int) ($data['flush_at'] ?? 100));
$flushIntervalMs = max(0, (int) ($data['flush_interval_ms'] ?? 5000));
$maxRetries = max(0, (int) ($data['max_retries'] ?? 3));
$enableCompression = (bool) ($data['enable_compression'] ?? false);
$timeoutMs = max(1000, (int) ($data['timeout_ms'] ?? 10000));

Expand All @@ -98,7 +97,10 @@ function handleRequest(array $request, AdapterState $state): array
throw new InvalidArgumentException('Unsupported consumer: ' . $consumer);
}

$maximumBackoffDuration = maxBackoffDurationForRetries($maxRetries, $consumer);
// Do not lower the SDK's native Retry-After ceiling when no retry count was requested.
$maximumBackoffDuration = isset($data['max_retries'])
? maxBackoffDurationForRetries(max(0, (int) $data['max_retries']), $consumer)
: 10000;
$state->client = new Client($apiKey, [
'host' => $normalizedHost,
'ssl' => $useSsl,
Expand Down
2 changes: 1 addition & 1 deletion sdk_compliance_adapter/check_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Check inventory completeness in harness 1.0.0 Markdown; assertions stay advisory."""
"""Check inventory completeness in harness 1.32.0 Markdown; assertions stay advisory."""

import argparse
import json
Expand Down
2 changes: 1 addition & 1 deletion sdk_compliance_adapter/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
- test-network

test-harness:
image: ghcr.io/posthog/sdk-test-harness:1.0.0
image: ghcr.io/posthog/sdk-test-harness:1.32.0
command: ["run", "--adapter-url", "http://sdk-adapter:8080", "--mock-url", "http://test-harness:8081"]
networks:
- test-network
Expand Down
19 changes: 19 additions & 0 deletions sdk_compliance_adapter/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import socket
import threading
import time
import unittest
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from unittest.mock import patch
Expand All @@ -20,10 +21,13 @@ class MockHandler(BaseHTTPRequestHandler):
def do_POST(self):
body = self.rfile.read(int(self.headers["Content-Length"]))
self.server.requests.append((self.path, dict(self.headers), body))
self.server.request_times.append(time.monotonic())
status = self.server.statuses.pop(0) if self.server.statuses else 200
response = b'{"featureFlags":{"test-flag":"variant-a"}}' if "/flags/" in self.path else b'{}'
self.send_response(status)
self.send_header("Content-Length", str(len(response)))
for name, value in self.server.response_headers.items():
self.send_header(name, value)
self.end_headers()
self.wfile.write(response)

Expand All @@ -39,7 +43,9 @@ def setUp(self):
self.mock = ThreadingHTTPServer(("127.0.0.1", MOCK_PORT), MockHandler)
self.addCleanup(self.mock.server_close)
self.mock.requests = []
self.mock.request_times = []
self.mock.statuses = []
self.mock.response_headers = {}
self.thread = threading.Thread(target=self.mock.serve_forever, daemon=True)
self.thread.start()
self.addCleanup(self.thread.join)
Expand All @@ -55,7 +61,9 @@ def call(self, path, data=None):
def init(self, consumer="lib_curl", **options):
os.environ["POSTHOG_CONSUMER"] = consumer
self.mock.requests.clear()
self.mock.request_times.clear()
self.mock.statuses.clear()
self.mock.response_headers.clear()
self.call("/init", {"host": f"http://127.0.0.1:{self.mock.server_address[1]}",
"api_key": "phc_local_test", **options})

Expand Down Expand Up @@ -129,6 +137,17 @@ def test_production_retry_attempts_are_observed(self):
self.assertTrue(all(r["uuid_list"] == [captured["uuid"]] for r in requests))
self.assertTrue(all(r[2] == self.mock.requests[0][2] for r in self.mock.requests))

def test_default_backoff_honors_retry_after(self):
for consumer in ("lib_curl", "socket", "fork_curl"):
with self.subTest(consumer=consumer):
self.init(consumer)
self.mock.statuses = [429, 200]
self.mock.response_headers = {"Retry-After": "3"}
self.capture()
self.assertTrue(self.call("/flush", {})["success"])
self.assertEqual(len(self.mock.requests), 2)
self.assertGreaterEqual(self.mock.request_times[1] - self.mock.request_times[0], 2.5)

def test_terminal_response_exposes_sdk_boolean_not_observer_success(self):
for consumer in ("lib_curl", "socket", "fork_curl"):
with self.subTest(consumer=consumer):
Expand Down
Loading