Skip to content

Commit

Permalink
Merge pull request #2862 from gravitl/release-v0.23.0
Browse files Browse the repository at this point in the history
Release v0.23.0
  • Loading branch information
abhishek9686 authored Mar 17, 2024
2 parents 194a900 + cfb28e2 commit ecd3408
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
46 changes: 34 additions & 12 deletions logic/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package logic

import (
"encoding/json"
"os"
"time"

"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/servercfg"
"github.com/posthog/posthog-go"
"golang.org/x/exp/slog"
)

// flags to keep for telemetry
Expand Down Expand Up @@ -39,14 +41,18 @@ func sendTelemetry() error {
// get telemetry data
d, err := FetchTelemetryData()
if err != nil {
return err
slog.Error("error fetching telemetry data", "error", err)
}
// get tenant admin email
adminEmail := os.Getenv("NM_EMAIL")
client, err := posthog.NewWithConfig(posthog_pub_key, posthog.Config{Endpoint: posthog_endpoint})
if err != nil {
return err
}
defer client.Close()

slog.Info("sending telemetry data to posthog", "data", d)

// send to posthog
return client.Enqueue(posthog.Capture{
DistinctId: telRecord.UUID,
Expand All @@ -67,7 +73,11 @@ func sendTelemetry() error {
Set("k8s", d.Count.K8S).
Set("version", d.Version).
Set("is_ee", d.IsPro). // TODO change is_ee to is_pro for consistency, but probably needs changes in posthog
Set("is_free_tier", isFreeTier),
Set("is_free_tier", isFreeTier).
Set("is_pro_trial", d.IsProTrial).
Set("pro_trial_end_date", d.ProTrialEndDate.In(time.UTC).Format("2006-01-02")).
Set("admin_email", adminEmail).
Set("is_saas_tenant", d.IsSaasTenant),
})
}

Expand All @@ -87,6 +97,15 @@ func FetchTelemetryData() (telemetryData, error) {
data.Nodes = len(nodes)
data.Count = getClientCount(nodes)
}
endDate, err := GetTrialEndDate()
if err != nil {
logger.Log(0, "error getting trial end date", err.Error())
}
data.ProTrialEndDate = endDate
if endDate.After(time.Now()) {
data.IsProTrial = true
}
data.IsSaasTenant = servercfg.DeployedByOperator()
return data, err
}

Expand Down Expand Up @@ -162,16 +181,19 @@ func getDBLength(dbname string) int {

// telemetryData - What data to send to posthog
type telemetryData struct {
Nodes int
Hosts int
ExtClients int
Users int
Count clientCount
Networks int
Servers int
Version string
IsPro bool
IsFreeTier bool
Nodes int
Hosts int
ExtClients int
Users int
Count clientCount
Networks int
Servers int
Version string
IsPro bool
IsFreeTier bool
IsProTrial bool
ProTrialEndDate time.Time
IsSaasTenant bool
}

// clientCount - What types of netclients we're tallying
Expand Down
22 changes: 4 additions & 18 deletions scripts/nm-quick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -470,23 +470,11 @@ set_install_vars() {

wait_seconds 1


unset GET_EMAIL
unset RAND_EMAIL
RAND_EMAIL="$(echo $RANDOM | md5sum | head -c 16)@email.com"
# suggest the prev email or a random one
EMAIL_SUGGESTED=${NM_EMAIL:-$RAND_EMAIL}
read -p "Email Address for Domain Registration (click 'enter' to use $EMAIL_SUGGESTED): " GET_EMAIL
if [ -z "$GET_EMAIL" ]; then
EMAIL="$EMAIL_SUGGESTED"
if [ "$EMAIL" = "$NM_EMAIL" ]; then
echo "using config email"
else
echo "using rand email"
fi
else
EMAIL="$GET_EMAIL"
fi
while [ -z "$GET_EMAIL" ]; do
read -p "Email Address for Domain Registration: " GET_EMAIL
done
EMAIL="$GET_EMAIL"

wait_seconds 1

Expand Down Expand Up @@ -592,8 +580,6 @@ install_netmaker() {

echo "Starting containers..."



# start docker and rebuild containers / networks
cd "${SCRIPT_DIR}"
docker-compose up -d --force-recreate
Expand Down

0 comments on commit ecd3408

Please sign in to comment.