Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #449 from ZupIT/feature/metrics
Browse files Browse the repository at this point in the history
Collect Product Metrics
  • Loading branch information
kaduartur authored Aug 21, 2020
2 parents e85c6be + fd12cd1 commit 838aaa7
Show file tree
Hide file tree
Showing 476 changed files with 80,381 additions and 98,344 deletions.
9 changes: 9 additions & 0 deletions .circleci/scripts/ritchie_metric_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if expr "$VERSION" : '.*qa.*' >/dev/null; then
echo "https://ritchie-metrics.itiaws.dev/metrics"
elif expr "$VERSION" : '^[0-9]\+' >/dev/null; then
echo "https://ritchie-metrics.zup.io/metrics"
else
echo ""
fi
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/improvement.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
name: Improvement
about: Suggest a improvement for this project
about: Suggest an improvement for this project
labels: improvement
assignees: ''

---

<!-- Please only use this template for submitting improvement suggesion-->
<!-- Please only use this template for submitting improvement suggestion-->

**What would you like to be added**:


**Why is this needed**:
**Why is this needed**:
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/support_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ assignees: ''

<!--
Use this template when requesting support or to ask questions.
Please include useful information for understanding your question.
Thanks!
-->

Expand All @@ -23,4 +25,4 @@ assignees: ''
- Ritchie version (use `rit --version`):
- Operating System:
- Network plugin / Tool and version (if this is a network-related / tool bug):
- Others:
- Others:
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ IS_QA=$(shell echo $(VERSION) | egrep "*qa.*")
IS_NIGHTLY=$(shell echo $(VERSION) | egrep "*.nightly.*")
GONNA_RELEASE=$(shell ./.circleci/scripts/gonna_release.sh)
NEXT_VERSION=$(shell ./.circleci/scripts/next_version.sh)
METRIC_SERVER_URL=$(shell VERSION=$(VERSION) ./.circleci/scripts/ritchie_metric_server.sh)

build-linux:
mkdir -p $(DIST_LINUX)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO_BUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_LINUX)/$(BINARY_NAME) -v $(CMD_PATH)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO_BUILD) -ldflags '-X $(MODULE)/pkg/metric.ServerRestURL=$(METRIC_SERVER_URL) -X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_LINUX)/$(BINARY_NAME) -v $(CMD_PATH)

build-mac:
mkdir -p $(DIST_MAC)
GOOS=darwin GOARCH=amd64 $(GO_BUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_MAC)/$(BINARY_NAME) -v $(CMD_PATH)
GOOS=darwin GOARCH=amd64 $(GO_BUILD) -ldflags '-X $(MODULE)/pkg/metric.ServerRestURL=$(METRIC_SERVER_URL) -X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_MAC)/$(BINARY_NAME) -v $(CMD_PATH)

build-windows:
mkdir -p $(DIST_WIN)
GOOS=windows GOARCH=amd64 $(GO_BUILD) -ldflags '-X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_WIN)/$(BINARY_NAME).exe -v $(CMD_PATH)
GOOS=windows GOARCH=amd64 $(GO_BUILD) -ldflags '-X $(MODULE)/pkg/metric.ServerRestURL=$(METRIC_SERVER_URL) -X $(MODULE)/pkg/cmd.Version=$(VERSION) -X $(MODULE)/pkg/cmd.BuildDate=$(DATE)' -o ./$(DIST_WIN)/$(BINARY_NAME).exe -v $(CMD_PATH)

build: build-linux build-mac build-windows
ifneq "$(BUCKET)" ""
Expand Down
31 changes: 24 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (
"os"
"time"

"github.com/ZupIT/ritchie-cli/pkg/git/github"
"github.com/ZupIT/ritchie-cli/pkg/git/gitlab"

"k8s.io/kubectl/pkg/util/templates"

"github.com/ZupIT/ritchie-cli/pkg/credential"
Expand All @@ -34,6 +31,9 @@ import (
"github.com/ZupIT/ritchie-cli/pkg/formula/repo"
"github.com/ZupIT/ritchie-cli/pkg/formula/runner"
"github.com/ZupIT/ritchie-cli/pkg/formula/tree"
"github.com/ZupIT/ritchie-cli/pkg/git/github"
"github.com/ZupIT/ritchie-cli/pkg/git/gitlab"
"github.com/ZupIT/ritchie-cli/pkg/metric"
"github.com/ZupIT/ritchie-cli/pkg/rtutorial"

"github.com/ZupIT/ritchie-cli/pkg/upgrade"
Expand All @@ -57,10 +57,14 @@ import (

func main() {
rootCmd := buildCommands()
if err := rootCmd.Execute(); err != nil {
err := rootCmd.Execute()
if err != nil {
sendMetric(err.Error())
_, _ = fmt.Fprintf(os.Stderr, "Error: %+v\n", err)
os.Exit(1)
}

sendMetric()
}

func buildCommands() *cobra.Command {
Expand Down Expand Up @@ -116,7 +120,6 @@ func buildCommands() *cobra.Command {
tutorialFinder := rtutorial.NewFinder(ritchieHomeDir, fileManager)
tutorialSetter := rtutorial.NewSetter(ritchieHomeDir, fileManager)
tutorialFindSetter := rtutorial.NewFindSetter(ritchieHomeDir, tutorialFinder, tutorialSetter)

formBuildMake := builder.NewBuildMake()
formBuildBat := builder.NewBuildBat(fileManager)
formBuildDocker := builder.NewBuildDocker()
Expand Down Expand Up @@ -147,14 +150,14 @@ func buildCommands() *cobra.Command {
addCmd := cmd.NewAddCmd()
createCmd := cmd.NewCreateCmd()
deleteCmd := cmd.NewDeleteCmd()
initCmd := cmd.NewInitCmd(repoAdder, githubRepo, tutorialFinder, inputBool)
initCmd := cmd.NewInitCmd(repoAdder, githubRepo, tutorialFinder, inputList, fileManager)
listCmd := cmd.NewListCmd()
setCmd := cmd.NewSetCmd()
showCmd := cmd.NewShowCmd()
updateCmd := cmd.NewUpdateCmd()
buildCmd := cmd.NewBuildCmd()
upgradeCmd := cmd.NewUpgradeCmd(defaultUpgradeResolver, upgradeManager, defaultUrlFinder)

metricsCmd := cmd.NewMetricsCmd(fileManager, inputList)
tutorialCmd := cmd.NewTutorialCmd(ritchieHomeDir, inputList, tutorialFindSetter)

// level 2
Expand Down Expand Up @@ -216,6 +219,7 @@ func buildCommands() *cobra.Command {
buildCmd,
upgradeCmd,
tutorialCmd,
metricsCmd,
},
},
}
Expand Down Expand Up @@ -246,3 +250,16 @@ func buildCommands() *cobra.Command {

return rootCmd
}

func sendMetric(err ...string) {
metricEnable := metric.NewChecker(stream.NewFileManager())
if metricEnable.Check() {
var collectData metric.APIData
metricManager := metric.NewHttpSender(metric.ServerRestURL, http.DefaultClient)
userIdManager := metric.NewUserIdGenerator()
data := metric.NewDataCollector(userIdManager)

collectData, _ = data.Collect(cmd.Version, err...)
metricManager.Send(collectData)
}
}
5 changes: 5 additions & 0 deletions functional/init/init_feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
"value":"init",
"action":"main"
},
{
"key":"and feature use statistics and crash reports?\u001B[0m \u001B[36m[Use arrows to move, type to filter]\u001B[0m",
"value":"Yes, I agree to contribute with data anonymously",
"action":"select"
},
{
"key":"Would you like to add the community repository? [https://github.com/ZupIT/ritchie-formulas]",
"value":"yes",
Expand Down
13 changes: 10 additions & 3 deletions functional/runner_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ func setUpRitSingleUnix() {

fmt.Println("Running INIT")
initStepRit := Step{Key: "", Value: "init", Action: "rit"}
initAddRepo := Step{Key: "Would you like to add the community repository? [https://github.com/ZupIT/ritchie-formulas]", Value: "yes", Action: "select"}

init := Scenario{Entry: "Running Init", Result: "", Steps: []Step{initStepRit, initAddRepo}}
initAcceptsMetrics := Step{
Key: "and feature use statistics and crash reports?\u001B[0m \u001B[36m[Use arrows to move, type to filter]\u001B[0m",
Value: "Yes, I agree to contribute with data anonymously",
Action: "select"}
initAddRepo := Step{
Key: "Would you like to add the community repository? [https://github.com/ZupIT/ritchie-formulas]",
Value: "yes",
Action: "select"}

init := Scenario{Entry: "Running Init", Result: "", Steps: []Step{initStepRit, initAcceptsMetrics, initAddRepo}}

err, _ := init.runStepsForUnix()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ go 1.14

require (
github.com/AlecAivazis/survey/v2 v2.0.7
github.com/denisbrodbeck/machineid v1.0.1
github.com/fatih/color v1.9.0 // indirect
github.com/golang/protobuf v1.4.1
github.com/google/uuid v1.1.1
github.com/gookit/color v1.2.5
github.com/gosuri/uitable v0.0.4
Expand All @@ -17,5 +19,8 @@ require (
github.com/pkg/errors v0.9.1
github.com/radovskyb/watcher v1.0.7
github.com/spf13/cobra v1.0.0
golang.org/x/sys v0.0.0-20200806125547-5acd03effb82 // indirect
google.golang.org/grpc v1.27.0
google.golang.org/protobuf v1.25.0
k8s.io/kubectl v0.18.4
)
Loading

0 comments on commit 838aaa7

Please sign in to comment.