Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/loadgen/pkg/observer/log.go
2499 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package observer
6
7
import (
8
log "github.com/sirupsen/logrus"
9
10
"github.com/gitpod-io/gitpod/loadgen/pkg/loadgen"
11
)
12
13
// NewLogObserver produces a new observer that logs using logrus
14
func NewLogObserver(errorOnly bool) chan<- *loadgen.SessionEvent {
15
res := make(chan *loadgen.SessionEvent, defaultCapacity)
16
go func() {
17
for evt := range res {
18
if errorOnly && evt.Kind != loadgen.SessionError {
19
continue
20
}
21
22
switch evt.Kind {
23
case loadgen.SessionStart:
24
log.Info("session started")
25
case loadgen.SessionWorkspaceStart:
26
log.WithField("instanceID", evt.WorkspaceStart.Spec.Id).Info("workspace started")
27
case loadgen.SessionError:
28
log.WithError(evt.Error).Error("error")
29
case loadgen.SessionWorkspaceUpdate:
30
up := evt.WorkspaceUpdate.Update
31
log.WithField("instanceID", up.InstanceID).WithField("failed", up.Failed).WithField("phase", up.Phase).Info("workspace update")
32
case loadgen.SessionDone:
33
log.Info("session done")
34
}
35
}
36
}()
37
return res
38
}
39
40