Skip to content

Commit

Permalink
fix: config db (keploy#1688)
Browse files Browse the repository at this point in the history
* fix: linter github action and issues

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: linter github action and issues

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: linter github action and issues

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: linter issues

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: add only-new-issues in linter

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: keploy-config name in workflows

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: sudo issue

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: yaml to yml

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: Remove print statements

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: golang workflow

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: golang workflow

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: golang workflow

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: golang workflow

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: debug

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: golang workflow

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: debug

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: config

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: remove debug

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: python-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: python-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: python-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: node-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: node-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: node-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: node-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: node-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: node-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: node-on-linux

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: enable telemetry

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

* fix: add testReports backward compatability

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>

---------

Signed-off-by: charankamarapu <kamarapucharan@gmail.com>
  • Loading branch information
charankamarapu authored Mar 14, 2024
1 parent a954131 commit 84dcd57
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cli/provider/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (n *ServiceProvider) GetTelemetryService(ctx context.Context, config config
return nil, errors.New("failed to get installation id")
}
return telemetry.NewTelemetry(n.logger, telemetry.Options{
Enabled: config.DisableTele,
Enabled: !config.DisableTele,
Version: utils.Version,
GlobalMap: map[string]interface{}{},
InstallationID: installtionID,
Expand Down Expand Up @@ -74,7 +74,7 @@ func (n *ServiceProvider) GetService(ctx context.Context, cmd string, config con
if err != nil {
return nil, err
}
tel.Ping(ctx)
tel.Ping()
switch cmd {
case "config", "update":
return tools.NewTools(n.logger, tel), nil
Expand Down
38 changes: 19 additions & 19 deletions pkg/platform/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package telemetry

import (
"bytes"
"context"
"net/http"
"runtime"
"time"
Expand Down Expand Up @@ -33,6 +32,7 @@ type Options struct {

func NewTelemetry(logger *zap.Logger, opt Options) *Telemetry {
return &Telemetry{
Enabled: opt.Enabled,
logger: logger,
KeployVersion: opt.Version,
GlobalMap: opt.GlobalMap,
Expand All @@ -41,50 +41,50 @@ func NewTelemetry(logger *zap.Logger, opt Options) *Telemetry {
}
}

func (tel *Telemetry) Ping(ctx context.Context) {
func (tel *Telemetry) Ping() {
if !tel.Enabled {
return
}
go func() {
for {
tel.SendTelemetry(ctx, "Ping")
tel.SendTelemetry("Ping")
time.Sleep(5 * time.Minute)
}
}()
}

func (tel *Telemetry) TestSetRun(ctx context.Context, success int, failure int, testSet string, runStatus string) {
go tel.SendTelemetry(ctx, "TestRun", map[string]interface{}{"Passed-Tests": success, "Failed-Tests": failure, "Test-Set": testSet, "Run-Status": runStatus})
func (tel *Telemetry) TestSetRun(success int, failure int, testSet string, runStatus string) {
go tel.SendTelemetry("TestSetRun", map[string]interface{}{"Passed-Tests": success, "Failed-Tests": failure, "Test-Set": testSet, "Run-Status": runStatus})
}

func (tel *Telemetry) TestRun(ctx context.Context, success int, failure int, testSets int, runStatus string) {
go tel.SendTelemetry(ctx, "TestRun", map[string]interface{}{"Passed-Tests": success, "Failed-Tests": failure, "Test-Sets": testSets, "Run-Status": runStatus})
func (tel *Telemetry) TestRun(success int, failure int, testSets int, runStatus string) {
go tel.SendTelemetry("TestRun", map[string]interface{}{"Passed-Tests": success, "Failed-Tests": failure, "Test-Sets": testSets, "Run-Status": runStatus})
}

// MockTestRun is Telemetry event for the Mocking feature test run
func (tel *Telemetry) MockTestRun(ctx context.Context, utilizedMocks int) {
go tel.SendTelemetry(ctx, "MockTestRun", map[string]interface{}{"Utilized-Mocks": utilizedMocks})
func (tel *Telemetry) MockTestRun(utilizedMocks int) {
go tel.SendTelemetry("MockTestRun", map[string]interface{}{"Utilized-Mocks": utilizedMocks})
}

// RecordedTestSuite is Telemetry event for the tests and mocks that are recorded
func (tel *Telemetry) RecordedTestSuite(ctx context.Context, testSet string, testsTotal int, mockTotal map[string]int) {
go tel.SendTelemetry(ctx, "RecordedTestSuite", map[string]interface{}{"test-set": testSet, "tests": testsTotal, "mocks": mockTotal})
func (tel *Telemetry) RecordedTestSuite(testSet string, testsTotal int, mockTotal map[string]int) {
go tel.SendTelemetry("RecordedTestSuite", map[string]interface{}{"test-set": testSet, "tests": testsTotal, "mocks": mockTotal})
}

func (tel *Telemetry) RecordedTestAndMocks(ctx context.Context) {
go tel.SendTelemetry(ctx, "RecordedTestAndMocks", map[string]interface{}{"mocks": make(map[string]int)})
func (tel *Telemetry) RecordedTestAndMocks() {
go tel.SendTelemetry("RecordedTestAndMocks", map[string]interface{}{"mocks": make(map[string]int)})
}

// RecordedMocks is Telemetry event for the mocks that are recorded in the mocking feature
func (tel *Telemetry) RecordedMocks(ctx context.Context, mockTotal map[string]int) {
go tel.SendTelemetry(ctx, "RecordedMocks", map[string]interface{}{"mocks": mockTotal})
func (tel *Telemetry) RecordedMocks(mockTotal map[string]int) {
go tel.SendTelemetry("RecordedMocks", map[string]interface{}{"mocks": mockTotal})
}

func (tel *Telemetry) RecordedTestCaseMock(ctx context.Context, mockType string) {
go tel.SendTelemetry(ctx, "RecordedTestCaseMock", map[string]interface{}{"mock": mockType})
func (tel *Telemetry) RecordedTestCaseMock(mockType string) {
go tel.SendTelemetry("RecordedTestCaseMock", map[string]interface{}{"mock": mockType})
}

func (tel *Telemetry) SendTelemetry(ctx context.Context, eventType string, output ...map[string]interface{}) {
func (tel *Telemetry) SendTelemetry(eventType string, output ...map[string]interface{}) {
if tel.Enabled {
event := models.TeleEvent{
EventType: eventType,
Expand All @@ -109,7 +109,7 @@ func (tel *Telemetry) SendTelemetry(ctx context.Context, eventType string, outpu
return
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, teleURL, bytes.NewBuffer(bin))
req, err := http.NewRequest(http.MethodPost, teleURL, bytes.NewBuffer(bin))
if err != nil {
tel.logger.Debug("failed to create request for analytics", zap.Error(err))
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/yaml/configdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewConfigDb(logger *zap.Logger) *ConfigDb {
func (cdb *ConfigDb) GetInstallationID(ctx context.Context) (string, error) {
var id string
id = getInstallationFromFile(cdb.logger)
if id != "" {
if id == "" {
id = primitive.NewObjectID().String()
err := cdb.setInstallationID(ctx, id)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func ReadSessionIndices(_ context.Context, path string, Logger *zap.Logger) ([]s
}

for _, v := range files {
if v.Name() != "reports" {
if v.Name() != "reports" || v.Name() != "testReports" {
indices = append(indices, v.Name())
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/record/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *recorder) Start(ctx context.Context) error {
defer func() {
select {
case <-ctx.Done():
r.telemetry.RecordedTestSuite(ctx, newTestSetID, testCount, mockCountMap)
r.telemetry.RecordedTestSuite(newTestSetID, testCount, mockCountMap)
default:
err := utils.Stop(r.logger, stopReason)
if err != nil {
Expand Down Expand Up @@ -150,7 +150,7 @@ func (r *recorder) Start(ctx context.Context) error {
insertTestErrChan <- err
} else {
testCount++
r.telemetry.RecordedTestAndMocks(ctx)
r.telemetry.RecordedTestAndMocks()
}
}
return nil
Expand All @@ -175,7 +175,7 @@ func (r *recorder) Start(ctx context.Context) error {
insertMockErrChan <- err
} else {
mockCountMap[mock.GetKind()]++
r.telemetry.RecordedTestCaseMock(ctx, mock.GetKind())
r.telemetry.RecordedTestCaseMock(mock.GetKind())
}
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/record/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type MockDB interface {
}

type Telemetry interface {
RecordedTestSuite(ctx context.Context, testSet string, testsTotal int, mockTotal map[string]int)
RecordedTestCaseMock(ctx context.Context, mockType string)
RecordedMocks(ctx context.Context, mockTotal map[string]int)
RecordedTestAndMocks(ctx context.Context)
RecordedTestSuite(testSet string, testsTotal int, mockTotal map[string]int)
RecordedTestCaseMock(mockType string)
RecordedMocks(mockTotal map[string]int)
RecordedTestAndMocks()
}
4 changes: 2 additions & 2 deletions pkg/service/replay/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (r *replayer) Start(ctx context.Context) error {
if testRunResult {
testRunStatus = "pass"
}
r.telemetry.TestRun(ctx, totalTestPassed, totalTestFailed, len(testSetIDs), testRunStatus)
r.telemetry.TestRun(totalTestPassed, totalTestFailed, len(testSetIDs), testRunStatus)

if !abortTestRun {
r.printSummary(ctx, testRunResult)
Expand Down Expand Up @@ -471,7 +471,7 @@ func (r *replayer) RunTestSet(ctx context.Context, testSetID string, testRunID s
totalTestPassed += testReport.Success
totalTestFailed += testReport.Failure

r.telemetry.TestSetRun(runTestSetCtx, testReport.Success, testReport.Failure, testSetID, string(testSetStatus))
r.telemetry.TestSetRun(testReport.Success, testReport.Failure, testSetID, string(testSetStatus))
return testSetStatus, nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/service/replay/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type ReportDB interface {
}

type Telemetry interface {
TestSetRun(ctx context.Context, success int, failure int, testSet string, runStatus string)
TestRun(ctx context.Context, success int, failure int, testSets int, runStatus string)
MockTestRun(ctx context.Context, utilizedMocks int)
TestSetRun(success int, failure int, testSet string, runStatus string)
TestRun(success int, failure int, testSets int, runStatus string)
MockTestRun(utilizedMocks int)
}

0 comments on commit 84dcd57

Please sign in to comment.