@stackone/olap 1.66.1 → 1.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,3 +48,116 @@ $ pnpm lint
48
48
  # run linter and try to fix any error
49
49
  $ pnpm lint:fix
50
50
  ```
51
+
52
+ ## Platform logs
53
+
54
+ Platform logs are the audit trail of operations on StackOne itself — creating an account, deleting
55
+ an integration, minting a session — as opposed to requests proxied to a provider.
56
+
57
+ They are read through `getPlatformLogs` and **only** through it. It takes no `engine` argument,
58
+ because there is nothing to choose: the `platform` table lives in ClickHouse and has no Tinybird
59
+ datasource, so the client is resolved here rather than by the caller.
60
+
61
+ They are also deliberately **not** part of the combined `getLogs` feed. That feed still serves orgs
62
+ on Tinybird, so including platform rows meant classifying every filter and dimension the platform
63
+ table lacks, per arm, and quietly rerouting such queries to ClickHouse behind the caller's back.
64
+ `CombinedLogType` is therefore `action | unified`, and it stays that way at least until Tinybird is
65
+ gone.
66
+
67
+ ### `isRead`
68
+
69
+ Each row carries `isRead`: whether the operation only retrieved state, changing nothing and sending
70
+ nothing onwards. It is a `UInt8` in ClickHouse and a boolean on the way out, filterable through
71
+ `PlatformQuery`.
72
+
73
+ The value comes from the emitting route and nothing else, and an absent value means `false` — "not
74
+ known to be a pure read", which is where anything with a side effect belongs. Neither the HTTP
75
+ method nor the verb can stand in for it: a read is often a `POST` carrying filters, and plenty of
76
+ `get`-shaped operations write.
77
+
78
+ ## Advanced log truncation
79
+
80
+ Advanced logs hold the full request and response of a call. When one is too large to store, what the
81
+ sink does is chosen **per call** by `advanced.truncation`, so the behaviour can be driven by a feature
82
+ flag outside this package.
83
+
84
+ ### Modes
85
+
86
+ | Mode | An oversized log becomes | Budget |
87
+ | --- | --- | --- |
88
+ | `drop` (default) | its whole `data` object replaced by `{ "outputs": { "error": "Error.TOO_LARGE" } }` | `maxItemSizeBytes` |
89
+ | `truncate` | its payload fields cut to fit, envelope intact | `maxItemSizeBytes`, ×`errorSizeMultiplier` for failures |
90
+ | `complete` | stored whole, at any size | none |
91
+
92
+ `drop` is the default and is what the sink has always done, so an unset flag changes nothing. Note
93
+ that it discards the envelope along with the payload — method, URL, status code and the run
94
+ identifiers all go — which is exactly what `truncate` exists to fix. Prefer `truncate`; `drop` is
95
+ there to roll back to.
96
+
97
+ ```ts
98
+ await olapClient.recordAction(input, result, {
99
+ advanced: { enabled: true, truncation: 'truncate' },
100
+ });
101
+ ```
102
+
103
+ **Platform logs are never truncated, in any mode.** They are audit records of events we generate
104
+ ourselves, so losing part of one is worse than storing a large object, and their `data` has no fixed
105
+ payload paths to cut. Their size is still recorded.
106
+
107
+ ### Budgets, in `truncate` mode
108
+
109
+ - `maxItemSizeBytes` (default `MAX_LOG_SIZE_BYTES`, 10MB) is the target size for a log. It is a
110
+ **soft** target: the per-field floor below means a stored log can slightly exceed it.
111
+ - A failed result — non-2xx/3xx status, `success: false`, `hasStepErrors: true`, or recorded errors —
112
+ gets `maxItemSizeBytes * errorSizeMultiplier` (default `5`), because a failure is the payload most
113
+ worth keeping in full. At the defaults that is `MAX_EXTENDED_LOG_SIZE_BYTES`, 50MB. The multiplier
114
+ is a `truncate`-mode allowance only: `drop` measures against the flat limit, so it discards a large
115
+ failure exactly as it always has.
116
+ - Only payload fields are ever truncated: `data.request.body`, `data.response.body`, `data.input`,
117
+ `data.outputs` and `data.errors`. Method, URL, headers, status code and the run identifiers survive
118
+ verbatim at any size.
119
+ - Bodies we sent (`data.request.body`, `data.input`) bid to be kept whole first, so a call stays as
120
+ replayable as possible. A body too large to keep whole loses that priority and competes for an
121
+ equal share like any other field.
122
+ - No field is ever allocated less than 64KB, so a 30MB array is stored truncated rather than as `[]`.
123
+
124
+ ### Metadata
125
+
126
+ Size information sits flat on `metadata`:
127
+
128
+ ```json
129
+ {
130
+ "metadata": {
131
+ "expirationTime": 1750000000,
132
+ "sizeBytes": 24117248,
133
+ "maxSizeBytes": 10485760,
134
+ "truncated": true
135
+ }
136
+ }
137
+ ```
138
+
139
+ - `sizeBytes` — the estimated size of the log before truncation. Present on **every** advanced log,
140
+ in **every** mode, so the effect of a mode change can be measured before making it.
141
+ - `maxSizeBytes` and `truncated` — present **only** when a budget was applied and exceeded. They are
142
+ absent, not `false`, on a log that fitted or that was stored whole, so `metadata.truncated` is the
143
+ single signal a reader needs.
144
+
145
+ ### What a truncated field looks like, in `truncate` mode
146
+
147
+ Truncation is structural — serialized JSON is never sliced, so a partial record is never emitted.
148
+
149
+ - **Arrays** keep their leading elements whole and drop the rest. No marker element is appended: the
150
+ retained elements stay valid for element-wise consumers and typed deserializers.
151
+ - **Objects** keep the entries that fit, smallest-first, and truncate the rest recursively. No key is
152
+ ever dropped, so a reader still finds the field it was looking for.
153
+ - **Strings** are sliced and suffixed with ` [truncated]`, so a raw render can never look complete.
154
+ - **Numbers, booleans and dates** are kept whole. They have nothing to cut, they cost at most 8 bytes
155
+ — fewer than the marker that would replace them — and replacing them would change the field's type.
156
+ - **A container with no budget at all** for its contents becomes
157
+ `{ "truncated": true, "sizeBytes": <n> }`, because an empty array or object would read as real data.
158
+
159
+ So truncation never changes the type of a stored field: arrays stay arrays of whole elements, objects
160
+ keep their keys, strings stay strings, scalars are untouched.
161
+
162
+ A log that cannot be serialized at all — one carrying a value `JSON.stringify` refuses, such as a
163
+ BigInt — is stored with its payload fields dropped and its envelope intact, rather than being lost.