Skip to content

Commit 6e482ac

Browse files
committed
address proposal feedback -- all questions answered
1 parent bbe988a commit 6e482ac

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

proposals/2023/04-21_build-init-log.md

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ The name of this markdown file should:
1313
| Key | Value |
1414
| :-----------: | :----------------: |
1515
| **Author(s)** | Jacob Floyd |
16-
| **Reviewers** | |
16+
| **Reviewers** | @jbrockopp, @plyr4 |
1717
| **Date** | April 21st, 2023 |
18-
| **Status** | Waiting for Review |
18+
| **Status** | Reviewed |
1919

2020
<!--
2121
If you're already working with someone, please add them to the proper author/reviewer category.
@@ -141,14 +141,14 @@ No changes are needed in the `pipeline` or the `yaml` layers because there is no
141141
Adjust `CreateLog`, `UpdateLog`, and `DeleteLog` to handle the build `Log` (adding a `logger.Tracef` entry and an `Error` specific to the Build Log).
142142

143143
Add `database/log/get_build.go` with:
144-
```
144+
```go
145145
// GetLogForBuild gets a log by build ID from the database.
146146
func (e *engine) GetLogForBuild(b *library.Build) (*library.Log, error) {
147147
```
148148
149149
See if we can make the build log sort before the step logs in `ListLogsForBuild`:
150150
<!-- https://github.com/go-vela/server/blob/main/database/log/list_build.go#L37-L40 -->
151-
```
151+
```go
152152
err = e.client.
153153
Table(constants.TableLog).
154154
Where("build_id = ?", b.GetID()).
@@ -157,9 +157,26 @@ See if we can make the build log sort before the step logs in `ListLogsForBuild`
157157
158158
Sqlite sorts with `NULLS FIRST` by default, and Postgres sorts with `NULLS LAST` (see: [How Are NULLs Sorted by Default?](https://learnsql.com/blog/how-to-order-rows-with-nulls/)).
159159
So this query is inconsistent between databases. And, the service logs returned by this query are not sorted. It would be nice to have this method return the logs sorted in a consistent manner.
160-
I would like to see the Build Log, then Step Logs sorted by step_id, then Service Logs sorted by service_id. Any suggestions on how to do that with gorm?
160+
I would like to see the Build Log, then Step Logs sorted by step_id, then Service Logs sorted by service_id. GORM supports multiple [order](https://gorm.io/docs/query.html#Order) statements, so something like this should be possible:
161161
162-
We might need some kind of index or constraint on the `Log` table so that rows with NULL step_id and NULL service_id must have a unique build_id. But, I'm not sure how to create such an index/constraint.
162+
```go
163+
err = e.client.
164+
Table(constants.TableLog).
165+
Where("build_id = ?", b.GetID()).
166+
Order("(step_id IS NULL AND service_id IS NULL) DESC"). // the build init log
167+
Order("step_id ASC NULLS LAST").
168+
Order("service_id ASC").
169+
```
170+
171+
We might need some kind of index or constraint on the `Log` table so that rows with NULL step_id and NULL service_id must have a unique build_id. A partial unique index seems like the simplest way to do this:
172+
173+
```sql
174+
CREATE UNIQUE INDEX
175+
IF NOT EXISTS
176+
logs_build_init_log
177+
ON logs (build_id)
178+
WHERE step_id IS NULL AND service_id IS NULL;
179+
```
163180
164181
#### Server - API
165182
@@ -186,9 +203,7 @@ The compiler needs to deprecate and stop adding the `InitStage` and `InitStep`.
186203
- remove the `Init*()` calls from `compiler/native/compile.go`, and
187204
- remove the magic `"init"` string special-casing in `compiler/native/validate.go`.
188205
189-
Backwards compatibility is a concern with the compiler. Referencing old builds/pipelines should work just fine as it includes the "init" step and stage, thus preserving references to the underlying log. But, recompiling the pipeline will create a slightly different pipeline--one without the injected "init" stage and/or step. The worker will no longer handle the old pipeline with the injected "init" step, so any re-runs MUST re-compile the pipeline.
190-
191-
Does re-running a build ALWAYS re-compile the pipeline?
206+
Backwards compatibility is a concern with the compiler. Referencing old builds/pipelines should work just fine as it includes the "init" step and stage, thus preserving references to the underlying log. But, recompiling the pipeline will create a slightly different pipeline--one without the injected "init" stage and/or step. The worker will no longer handle the old pipeline with the injected "init" step, so any re-runs MUST re-compile the pipeline. Luckily re-runs always re-compile the pipeline.
192207
193208
#### Server - Queue
194209
@@ -198,24 +213,24 @@ Also, when upgrading, we need to ensure that:
198213
- the queue is empty, or
199214
- all queued builds get re-compiled (or more particularly `item.Pipeline` which is a `types.pipeline.Build` and includes the injected init step) before execution in the worker starts.
200215
201-
To make the worker backwards compatible, could we trigger the rebuild in `server.queue.redis.Pop()` after the item is created?
202-
Or perhaps we'll just need to include queued build migrations in the migration script.
216+
We need to gracefully handle any stale queued items in the queue after upgrading server and worker. Items are stale if they were queued with a previous version of Vela.
203217
204218
### Worker
205219
206220
Save init logs to the Build `Log` instead of the magic init step.
207221
Nothing in the worker should check for these magic strings any more: `"init"`, `"#init"`
208222
209-
We might need something that rejects an old build when popped off the queue if it is an older version that includes the injected "init" `Step`.
223+
Hopefully we can do this in one release, documenting any required queue flushing or similar. To make this work well, the queue item will need some kind of version number (TODO: create community issue for this).
224+
Then the worker should fail a build popped from the queue if that item was created by an earlier version of Vela.
210225
211-
We might need to spread this change over a couple of versions.
226+
If needed, we can also spread this change over a couple of versions:
212227
- In one version, we start logging to the Build `Log` and deprecate support for the magic "init" step.
213228
- In the next (or a future) version, we remove support for the magic string checking.
214229
215230
In my previous [`InitStep` proposal](https://github.com/go-vela/community/pull/771), I suggested logging to both places for at least one version while waiting for the UI to catch up.
216-
However, the primary objection to that proposal was increased database storage costs. So, this proposal recommends a hard break the worker will only create the init logs in one place.
217-
The backwards compatibility is achieved by continuing to ignore Stages/Steps with the magic "init" or "#init" strings. Even if those strings are present, the worker will still send
218-
the build init logs to the server via the new build init logs endpoints.
231+
However, the primary objection to that proposal was increased database storage costs. So, this proposal recommends a hard break--the worker will only create the init logs in one place.
232+
If we do spread this over two releases, then the worker will continue to ignore Stages/Steps with the magic "init" or "#init" strings. Even if those strings are present, the worker will
233+
still send the build init logs to the server via the new build init logs endpoints.
219234
220235
### SDK
221236
@@ -228,20 +243,18 @@ initstep logs without change by virue of re-using the `Log` types for this.
228243
229244
We also need a new command to retrieve the "init" logs for a Build.
230245
231-
One way to provide this would be an `--init` flag to specify we only want the build's init log, not all of the logs for the build:
246+
We will provide this with an `--init` flag to specify we only want the build's init log, not all of the logs for the build:
232247
```
233248
3. View init logs for a build.
234249
$ vela view log --org MyOrg --repo MyRepo --build 1 --init
235250
```
236251
237-
Another alternitve is adding a separate "initlog" subcommand:
252+
If anyone has issues with that method, an alternitve is adding a separate "initlog" subcommand:
238253
```
239254
3. View init logs for a build.
240255
$ vela view initlog --org MyOrg --repo MyRepo --build 1
241256
```
242257
243-
I have not used the vela CLI much, so I'm not sure which option would be more ergonomic, or if we need something else entirely.
244-
245258
### UI
246259
247260
The UI needs to stream the build init log just like it does for steps and services. This can be shown as a step that comes before any stages or steps.
@@ -266,7 +279,7 @@ NOTE: If there are no current plans for implementation, please leave this sectio
266279
267280
Yes for the go code in Types, Server, Worker, sdk-go, and CLI.
268281
269-
The UI, however, is beyond me at this point. I need someone familiar eith elm to handle the UI.
282+
@plyr4 will help out with the UI, beginning with mocking out some ideas on how to separate init logs in a backwards-compatible way (ie supporting builds with the magic init step).
270283
271284
2. What's the estimated time to completion?
272285
@@ -284,9 +297,4 @@ TBD
284297
285298
<!-- Answer here -->
286299
287-
This is a summary of the questions listed above:
288-
- How can we add an index or constraint to the database so that each build can only have one init Log? (see "Server" > "Server - Database" above)
289-
- Does re-running a build ALWAYS re-compile the pipeline? (see "Server" > "Server - Compiler" above)
290-
- Do we need to trigger a re-compile for old builds on the queue when the worker Pops them off the queue? (see "Server" > "Server - Queue" above)
291-
- Do we need to migrate / re-compile any builds on the queue in an upgrade migration script? (see "Server" > "Server - Queue" above)
292-
- Does anyone have bandwidth to help with the UI piece? (see "UI" above)
300+
All questions have been answered.

0 commit comments

Comments
 (0)