@@ -12,7 +12,7 @@ import (
1212
1313 "github.com/honeycombio/libhoney-go"
1414 "github.com/honeycombio/libhoney-go/transmission"
15- "github.com/zoidbergwill /gitlab-honeycomb-buildevents-webhooks-sink/internal/hook/types"
15+ "github.com/zoidyzoidzoid /gitlab-honeycomb-buildevents-webhooks-sink/internal/hook/types"
1616)
1717
1818type Listener struct {
@@ -48,7 +48,7 @@ func New(cfg Config) (*Listener, error) {
4848 mux .HandleFunc ("/" , l .Home )
4949
5050 srv := & http.Server {
51- Addr : fmt . Sprintf ( cfg .ListenAddr ) ,
51+ Addr : cfg .ListenAddr ,
5252 Handler : mux ,
5353 ReadTimeout : 5 * time .Second ,
5454 WriteTimeout : 10 * time .Second ,
@@ -129,6 +129,13 @@ func (l *Listener) HandleRequest(w http.ResponseWriter, r *http.Request) {
129129 }
130130}
131131
132+ func SendEvent (e * libhoney.Event ) {
133+ err := e .Send ()
134+ if err != nil {
135+ fmt .Printf ("failed to send event: %s" , err )
136+ }
137+ }
138+
132139func (l * Listener ) handlePipeline (p types.PipelineEventPayload ) error {
133140 if p .ObjectAttributes .Duration == 0 || p .ObjectAttributes .Status == "running" {
134141 return nil
@@ -140,7 +147,7 @@ func (l *Listener) handlePipeline(p types.PipelineEventPayload) error {
140147 return err
141148 }
142149
143- defer ev . Send ( )
150+ defer SendEvent ( ev )
144151 buildURL := fmt .Sprintf ("%s/-/pipelines/%d" , p .Project .WebURL , p .ObjectAttributes .ID )
145152 err = ev .Add (map [string ]interface {}{
146153 // Basic trace information
@@ -194,14 +201,14 @@ func (l *Listener) handleJob(j types.JobEventPayload) error {
194201 return err
195202 }
196203
197- defer ev . Send ( )
204+ defer SendEvent ( ev )
198205 err = ev .Add (map [string ]interface {}{
199206 // Basic trace information
200207 "service_name" : "job" ,
201208 "trace.span_id" : spanID ,
202209 "trace.trace_id" : parentTraceID ,
203210 "trace.parent_id" : parentTraceID ,
204- "name" : fmt . Sprintf ( j .BuildName ) ,
211+ "name" : j .BuildName ,
205212
206213 // CI information
207214 "ci_provider" : "GitLab-CI" ,
@@ -210,12 +217,14 @@ func (l *Listener) handleJob(j types.JobEventPayload) error {
210217 "build_id" : j .BuildID ,
211218 "repo" : j .Repository .Homepage ,
212219 // TODO: Something with job status
213- "status" : j .BuildStatus ,
220+ "status" : j .BuildStatus ,
221+ "queued_duration_ms" : j .BuildQueuedDuration * 1000 ,
222+ "queued_duration_min" : j .BuildQueuedDuration / 60 ,
214223
215224 // Runner information
216225 "ci_runner" : j .Runner .Description ,
217226 "ci_runner_id" : j .Runner .ID ,
218- //"ci_runner_tags": strings.Join(j.Runner.Tags, ","),
227+ // "ci_runner_tags": strings.Join(j.Runner.Tags, ","),
219228
220229 "duration_ms" : j .BuildDuration * 1000 ,
221230 })
0 commit comments