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 3 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"
5 changes: 5 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,10 @@ func InitializeApp() (*App, error) {
wire.Bind(new(router.SsoLoginRouter), new(*router.SsoLoginRouterImpl)),
restHandler.NewSsoLoginRestHandlerImpl,
wire.Bind(new(restHandler.SsoLoginRestHandler), new(*restHandler.SsoLoginRestHandlerImpl)),
pubsub2.NewPosthogClient,

telemetry.NewTelemetryEventClientImpl,
wire.Bind(new(telemetry.TelemetryEventClient), new(*telemetry.TelemetryEventClientImpl)),
)
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
51 changes: 51 additions & 0 deletions client/pubsub/PosthogClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 pubsub
nishant-d marked this conversation as resolved.
Show resolved Hide resolved

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:""`
}

func NewPosthogClient(logger *zap.SugaredLogger) (*PosthogClient, error) {
cfg := &PosthogConfig{}
err := env.Parse(cfg)
if err != nil {
logger.Error("err", err)
return &PosthogClient{}, err
}
client, _ := posthog.NewWithConfig(cfg.ApiKey, posthog.Config{Endpoint: "https://app.posthog.com"})
nishant-d marked this conversation as resolved.
Show resolved Hide resolved
//defer client.Close()
pgClient := &PosthogClient{
Client: client,
}
/*pgClient.Client.Enqueue(posthog.Capture{
nishant-d marked this conversation as resolved.
Show resolved Hide resolved
DistinctId: "localhost-user",
Event: fmt.Sprintf("event sent from orchestrator on startup userid=%d,time=%s", 1, time.Now()),
})*/
return pgClient, nil
}
Loading