Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: telemetry events from devtron #517

Merged
merged 13 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion App.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ func (app *App) Stop() {
}
nc.Close()
app.Logger.Infow("housekeeping done. exiting now")
}
}
29 changes: 27 additions & 2 deletions Gopkg.lock

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

8 changes: 8 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,11 @@ required = [
[[constraint]]
branch = "dev"
name = "github.com/microsoft/azure-devops-go-api"

[[constraint]]
branch = "master"
name = "github.com/posthog/posthog-go"

[[constraint]]
name = "gopkg.in/robfig/cron.v3"
version = "3.0.1"
7 changes: 7 additions & 0 deletions Wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
jClient "github.com/devtron-labs/devtron/client/jira"
"github.com/devtron-labs/devtron/client/lens"
pubsub2 "github.com/devtron-labs/devtron/client/pubsub"
"github.com/devtron-labs/devtron/client/telemetry"
"github.com/devtron-labs/devtron/internal/casbin"
"github.com/devtron-labs/devtron/internal/sql/repository"
appWorkflow2 "github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
Expand Down Expand Up @@ -651,6 +652,12 @@ func InitializeApp() (*App, error) {
wire.Bind(new(router.SsoLoginRouter), new(*router.SsoLoginRouterImpl)),
restHandler.NewSsoLoginRestHandlerImpl,
wire.Bind(new(restHandler.SsoLoginRestHandler), new(*restHandler.SsoLoginRestHandlerImpl)),
telemetry.NewPosthogClient,

telemetry.NewTelemetryEventClientImpl,
wire.Bind(new(telemetry.TelemetryEventClient), new(*telemetry.TelemetryEventClientImpl)),

telemetry.GetPosthogConfig,
)
return &App{}, nil
}
5 changes: 4 additions & 1 deletion api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/devtron-labs/devtron/api/restHandler"
"github.com/devtron-labs/devtron/api/router/pubsub"
pubsub2 "github.com/devtron-labs/devtron/client/pubsub"
"github.com/devtron-labs/devtron/client/telemetry"
"github.com/devtron-labs/devtron/pkg/terminal"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -72,6 +73,7 @@ type MuxRouter struct {
commonRouter CommonRouter
grafanaRouter GrafanaRouter
ssoLoginRouter SsoLoginRouter
telemetryWatcher telemetry.TelemetryEventClient
}

func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter HelmRouter, PipelineConfigRouter PipelineConfigRouter,
Expand All @@ -90,7 +92,7 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter HelmRouter, PipelineConf
ReleaseMetricsRouter ReleaseMetricsRouter, deploymentGroupRouter DeploymentGroupRouter, batchOperationRouter BatchOperationRouter,
chartGroupRouter ChartGroupRouter, testSuitRouter TestSuitRouter, imageScanRouter ImageScanRouter,
policyRouter PolicyRouter, gitOpsConfigRouter GitOpsConfigRouter, dashboardRouter DashboardRouter, attributesRouter AttributesRouter,
commonRouter CommonRouter, grafanaRouter GrafanaRouter, ssoLoginRouter SsoLoginRouter) *MuxRouter {
commonRouter CommonRouter, grafanaRouter GrafanaRouter, ssoLoginRouter SsoLoginRouter, telemetryWatcher telemetry.TelemetryEventClient) *MuxRouter {
r := &MuxRouter{
Router: mux.NewRouter(),
HelmRouter: HelmRouter,
Expand Down Expand Up @@ -134,6 +136,7 @@ func NewMuxRouter(logger *zap.SugaredLogger, HelmRouter HelmRouter, PipelineConf
commonRouter: commonRouter,
grafanaRouter: grafanaRouter,
ssoLoginRouter: ssoLoginRouter,
telemetryWatcher: telemetryWatcher,
}
return r
}
Expand Down
59 changes: 59 additions & 0 deletions client/telemetry/PosthogClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2020 Devtron Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package telemetry

import (
"github.com/caarlos0/env"
"github.com/posthog/posthog-go"
"go.uber.org/zap"
)

type PosthogClient struct {
Client posthog.Client
}

type PosthogConfig struct {
ApiKey string `env:"API_KEY" envDefault:""`
PosthogEndpoint string `env:"POSTHOG_ENDPOINT" envDefault:"https://app.posthog.com"`
SummaryInterval int `env:"SUMMARY_INTERVAL" envDefault:"24"`
HeartbeatInterval int `env:"HEARTBEAT_INTERVAL" envDefault:"3"`
}

func GetPosthogConfig() (*PosthogConfig, error) {
cfg := &PosthogConfig{}
err := env.Parse(cfg)
if err != nil {
return nil, err
}
return cfg, err
}

func NewPosthogClient(logger *zap.SugaredLogger) (*PosthogClient, error) {
cfg := &PosthogConfig{}
err := env.Parse(cfg)
if err != nil {
logger.Errorw("exception caught while parsing posthog config", "err", err)
return &PosthogClient{}, err
}
client, _ := posthog.NewWithConfig(cfg.ApiKey, posthog.Config{Endpoint: cfg.PosthogEndpoint})
//defer client.Close()
pgClient := &PosthogClient{
Client: client,
}
return pgClient, nil
}
Loading