Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
40f8164
code change 1
Ashish-devtron Feb 21, 2023
dc81462
code change 2
Ashish-devtron Feb 21, 2023
bbe73fd
code-change-3
Ashish-devtron Feb 22, 2023
576047d
code change 4
Ashish-devtron Feb 23, 2023
1d11900
add-expose-flag
Ashish-devtron Feb 23, 2023
226eb31
code change 5
Ashish-devtron Feb 24, 2023
6fc03f6
Merge branch 'main' into add-timer-telemetry-for-cd-operation
Ashish-devtron Feb 24, 2023
baeb8b7
code change 6
Ashish-devtron Feb 24, 2023
bdb2e5c
change-cd-telemetry-trigger-function
Ashish-devtron Feb 24, 2023
61ca29f
add-deployment-type
Ashish-devtron Feb 24, 2023
2acf68f
server-mode-change
Ashish-devtron Feb 24, 2023
dd1953c
remove-loop-import
Ashish-devtron Feb 24, 2023
a3862e1
fix-merge-conflicts
Ashish-devtron Feb 28, 2023
101172f
Merge branch 'main' into add-timer-telemetry-for-cd-operation
Ashish-devtron Feb 28, 2023
4c07c29
add-wire-gen
Ashish-devtron Feb 28, 2023
1ca3974
Update AppService function name
Ashish-devtron Feb 28, 2023
41f7e13
remove finished on
Ashish-devtron Feb 28, 2023
53e9f12
Merge branch 'main' into add-timer-telemetry-for-ci-operation
Ashish-devtron Mar 1, 2023
dd93feb
ci-telemetry
Ashish-devtron Mar 1, 2023
aa42596
add-flag-and-appName
Ashish-devtron Mar 3, 2023
6b7d00b
add-flag-and-appName
Ashish-devtron Mar 3, 2023
ce69c91
add-app-name
Ashish-devtron Mar 3, 2023
b22f41b
improve-ci-metrics-struct
Ashish-devtron Mar 6, 2023
80ab760
improve-ci-metrics-struct
Ashish-devtron Mar 6, 2023
7fb89e7
improve-ci-metrics-struct
Ashish-devtron Mar 6, 2023
0ebbf34
Merge branch 'main' into add-timer-telemetry-for-ci-operation
Ashish-devtron Mar 7, 2023
fe0976e
add-ci-pipeline
Ashish-devtron Mar 9, 2023
69e67a5
Add check to Cache Upload
Ashish-devtron Mar 9, 2023
69df5d0
Code-refactor
Ashish-devtron Mar 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ func InitializeApp() (*App, error) {
pubsub.NewApplicationStatusHandlerImpl,
wire.Bind(new(pubsub.ApplicationStatusHandler), new(*pubsub.ApplicationStatusHandlerImpl)),

pubsub.GetCiEventConfig,
pubsub.NewCiEventHandlerImpl,
wire.Bind(new(pubsub.CiEventHandler), new(*pubsub.CiEventHandlerImpl)),

Expand Down
19 changes: 18 additions & 1 deletion api/router/pubsub/CiEventHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@ package pubsub
import (
"encoding/json"
"fmt"
"github.com/caarlos0/env/v6"
pubsub "github.com/devtron-labs/common-lib/pubsub-lib"
"github.com/devtron-labs/devtron/internal/sql/repository"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"github.com/devtron-labs/devtron/pkg/pipeline"
"github.com/devtron-labs/devtron/util"
"go.uber.org/zap"
)

type CiEventConfig struct {
ExposeCiMetrics bool `env:"EXPOSE_CI_METRICS" envDefault:"false"`
}

func GetCiEventConfig() (*CiEventConfig, error) {
cfg := &CiEventConfig{}
err := env.Parse(cfg)
return cfg, err
}

type CiEventHandler interface {
Subscribe() error
BuildCiArtifactRequest(event CiCompleteEvent) (*pipeline.CiArtifactWebhookRequest, error)
Expand All @@ -37,6 +49,7 @@ type CiEventHandlerImpl struct {
logger *zap.SugaredLogger
pubsubClient *pubsub.PubSubClientServiceImpl
webhookService pipeline.WebhookService
ciEventConfig *CiEventConfig
}

type CiCompleteEvent struct {
Expand All @@ -49,13 +62,16 @@ type CiCompleteEvent struct {
PipelineName string `json:"pipelineName"`
DataSource string `json:"dataSource"`
MaterialType string `json:"materialType"`
Metrics util.CIMetrics `json:"metrics"`
AppName string `json:"appName"`
}

func NewCiEventHandlerImpl(logger *zap.SugaredLogger, pubsubClient *pubsub.PubSubClientServiceImpl, webhookService pipeline.WebhookService) *CiEventHandlerImpl {
func NewCiEventHandlerImpl(logger *zap.SugaredLogger, pubsubClient *pubsub.PubSubClientServiceImpl, webhookService pipeline.WebhookService, ciEventConfig *CiEventConfig) *CiEventHandlerImpl {
ciEventHandlerImpl := &CiEventHandlerImpl{
logger: logger,
pubsubClient: pubsubClient,
webhookService: webhookService,
ciEventConfig: ciEventConfig,
}
err := ciEventHandlerImpl.Subscribe()
if err != nil {
Expand All @@ -71,6 +87,7 @@ func (impl *CiEventHandlerImpl) Subscribe() error {
//defer msg.Ack()
ciCompleteEvent := CiCompleteEvent{}
err := json.Unmarshal([]byte(string(msg.Data)), &ciCompleteEvent)
util.TriggerCIMetrics(ciCompleteEvent.Metrics, impl.ciEventConfig.ExposeCiMetrics, ciCompleteEvent.PipelineName, ciCompleteEvent.AppName)
if err != nil {
impl.logger.Error("error while unmarshalling json data", "error", err)
return
Expand Down
1 change: 0 additions & 1 deletion api/router/pubsub/WorkflowStatusUpdateHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
"github.com/devtron-labs/devtron/api/bean"
client "github.com/devtron-labs/devtron/client/events"
//"github.com/devtron-labs/devtron/client/pubsub"
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
"github.com/devtron-labs/devtron/pkg/pipeline"
util "github.com/devtron-labs/devtron/util/event"
Expand Down
38 changes: 37 additions & 1 deletion internal/middleware/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ var CdDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Help: "Duration of CD process",
}, []string{"appName", "status", "envName", "deploymentType"})

var CiDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "ci_duration_seconds",
Help: "Duration of CI process",
Buckets: prometheus.LinearBuckets(20, 20, 5),
}, []string{"pipelineName", "appName"})

var CacheDownloadDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "cache_download_duration_seconds",
Help: "Duration of Cache Download process",
Buckets: prometheus.LinearBuckets(20, 20, 5),
}, []string{"pipelineName", "appName"})

var PreCiDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "pre_ci_duration_seconds",
Help: "Duration of Pre CI process",
Buckets: prometheus.LinearBuckets(20, 20, 5),
}, []string{"pipelineName", "appName"})

var BuildDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "build_duration_seconds",
Help: "Duration of Build process",
Buckets: prometheus.LinearBuckets(20, 20, 5),
}, []string{"pipelineName", "appName"})

var PostCiDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "post_ci_duration_seconds",
Help: "Duration of Post CI process",
Buckets: prometheus.LinearBuckets(20, 20, 5),
}, []string{"pipelineName", "appName"})

var CacheUploadDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "cache_upload_duration_seconds",
Help: "Duration of Cache Upload process",
Buckets: prometheus.LinearBuckets(20, 20, 5),
}, []string{"pipelineName", "appName"})

var requestCounter = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "orchestrator_http_requests_total",
Expand All @@ -60,7 +96,7 @@ var CdTriggerCounter = promauto.NewCounterVec(prometheus.CounterOpts{

var CiTriggerCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "ci_trigger_counter",
}, []string{"appName"})
}, []string{"appName", "pipelineName"})

// prometheusMiddleware implements mux.MiddlewareFunc.
func PrometheusMiddleware(next http.Handler) http.Handler {
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipeline/CiService.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (impl *CiServiceImpl) TriggerCiPipeline(trigger Trigger) (int, error) {
}
impl.Logger.Debugw("ci triggered", "wf name ", createdWf.Name, " pipeline ", trigger.PipelineId)

middleware.CiTriggerCounter.WithLabelValues(pipeline.App.AppName).Inc()
middleware.CiTriggerCounter.WithLabelValues(pipeline.App.AppName, pipeline.Name).Inc()
go impl.WriteCITriggerEvent(trigger, pipeline, workflowRequest)
return savedCiWf.Id, err
}
Expand Down
32 changes: 32 additions & 0 deletions util/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ type CDMetrics struct {
Time float64
}

type CIMetrics struct {
CacheDownDuration float64 `json:"cacheDownDuration"`
PreCiDuration float64 `json:"preCiDuration"`
BuildDuration float64 `json:"buildDuration"`
PostCiDuration float64 `json:"postCiDuration"`
CacheUpDuration float64 `json:"cacheUpDuration"`
TotalDuration float64 `json:"totalDuration"`
CacheDownStartTime time.Time `json:"cacheDownStartTime"`
PreCiStartTime time.Time `json:"preCiStart"`
BuildStartTime time.Time `json:"buildStartTime"`
PostCiStartTime time.Time `json:"postCiStartTime"`
CacheUpStartTime time.Time `json:"cacheUpStartTime"`
TotalStartTime time.Time `json:"totalStartTime"`
}

func ContainsString(list []string, element string) bool {
if len(list) == 0 {
return false
Expand Down Expand Up @@ -223,3 +238,20 @@ func TriggerCDMetrics(wfr CDMetrics, exposeCDMetrics bool) {
middleware.CdDuration.WithLabelValues(wfr.AppName, wfr.Status, wfr.EnvironmentName, wfr.DeploymentType).Observe(wfr.Time)
}
}

func TriggerCIMetrics(Metrics CIMetrics, exposeCIMetrics bool, PipelineName string, AppName string) {
if exposeCIMetrics {
middleware.CacheDownloadDuration.WithLabelValues(PipelineName, AppName).Observe(Metrics.CacheDownDuration)
middleware.CiDuration.WithLabelValues(PipelineName, AppName).Observe(Metrics.TotalDuration)
if Metrics.CacheUpDuration != 0 {
middleware.CacheUploadDuration.WithLabelValues(PipelineName, AppName).Observe(Metrics.CacheUpDuration)
}
if Metrics.PostCiDuration != 0 {
middleware.PostCiDuration.WithLabelValues(PipelineName, AppName).Observe(Metrics.PostCiDuration)
}
if Metrics.PreCiDuration != 0 {
middleware.PreCiDuration.WithLabelValues(PipelineName, AppName).Observe(Metrics.PreCiDuration)
}
middleware.BuildDuration.WithLabelValues(PipelineName, AppName).Observe(Metrics.BuildDuration)
}
}
6 changes: 5 additions & 1 deletion wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.