Skip to content

Commit 7589fc6

Browse files
committed
feat(tibuild-v2): add ingest event method
1 parent a821b7d commit 7589fc6

File tree

20 files changed

+3170
-2285
lines changed

20 files changed

+3170
-2285
lines changed

experiments/tibuild-v2/internal/service/design/design.go

+70
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,27 @@ var _ = Service("devbuild", func() {
179179
Response("InternalServerError", StatusInternalServerError)
180180
})
181181
})
182+
183+
Method("ingestEvent", func() {
184+
Description("Ingest a CloudEvent for build events")
185+
Payload(CloudEvent, func() {
186+
Required("id", "source", "type", "specversion", "time", "data")
187+
})
188+
Result(CloudEventResponse)
189+
HTTP(func() {
190+
POST("/events")
191+
PUT("/events")
192+
Header("datacontenttype:Content-Type")
193+
Header("id:ce-id")
194+
Header("source:ce-source")
195+
Header("type:ce-type")
196+
Header("specversion:ce-specversion")
197+
Header("time:ce-time")
198+
Response(StatusOK)
199+
Response("BadRequest", StatusBadRequest)
200+
Response("InternalServerError", StatusInternalServerError)
201+
})
202+
})
182203
})
183204

184205
var ImageSyncRequest = Type("ImageSyncRequest", func() {
@@ -332,3 +353,52 @@ var HTTPError = Type("HTTPError", func() {
332353
Attribute("message", String)
333354
Required("code", "message")
334355
})
356+
357+
var CloudEvent = Type("CloudEvent", func() {
358+
Attribute("id", String, "Unique identifier for the event", func() {
359+
Example("f81d4fae-7dec-11d0-a765-00a0c91e6bf6")
360+
})
361+
Attribute("source", String, "Identifies the context in which an event happened", func() {
362+
Example("/jenkins/build")
363+
})
364+
Attribute("type", String, "Describes the type of event related to the originating occurrence", func() {
365+
Example("com.pingcap.build.complete")
366+
})
367+
Attribute("datacontenttype", String, "Content type of the data value")
368+
Attribute("specversion", String, "The version of the CloudEvents specification which the event uses", func() {
369+
Example("1.0")
370+
})
371+
Attribute("dataschema", String, "Identifies the schema that data adheres to", func() {
372+
Example("https://example.com/registry/schemas/build-event.json")
373+
})
374+
Attribute("subject", String, "Describes the subject of the event in the context of the event producer", func() {
375+
Example("tidb-build-123")
376+
})
377+
Attribute("time", String, "Timestamp of when the occurrence happened", func() {
378+
Format(FormatDateTime)
379+
Example("2022-10-01T12:00:00Z")
380+
})
381+
Attribute("data", Any, "Event payload", func() {
382+
Example(map[string]any{
383+
"buildId": "123",
384+
"status": "success",
385+
"version": "v6.1.0",
386+
"duration": 3600,
387+
})
388+
})
389+
})
390+
391+
var CloudEventResponse = Type("CloudEventResponse", func() {
392+
Attribute("id", String, "The ID of the processed CloudEvent", func() {
393+
Example("f81d4fae-7dec-11d0-a765-00a0c91e6bf6")
394+
})
395+
Attribute("status", String, "Processing status", func() {
396+
Enum("accepted", "processing", "error")
397+
Example("accepted")
398+
})
399+
Attribute("message", String, "Additional information about processing result", func() {
400+
Example("Event successfully queued for processing")
401+
})
402+
403+
Required("id", "status")
404+
})

experiments/tibuild-v2/internal/service/gen/devbuild/client.go

+27-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

experiments/tibuild-v2/internal/service/gen/devbuild/endpoints.go

+22-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

experiments/tibuild-v2/internal/service/gen/devbuild/service.go

+37-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

experiments/tibuild-v2/internal/service/gen/http/artifact/client/cli.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)