mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 09:32:32 +08:00
feat(NET-1034): add trial data to telemetry
This commit is contained in:
parent
6f61f8abcc
commit
ddb7879396
2 changed files with 38 additions and 30 deletions
|
@ -2,6 +2,7 @@ package logic
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/database"
|
||||
|
@ -9,6 +10,7 @@ import (
|
|||
"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
|
||||
|
@ -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,
|
||||
|
@ -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),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -592,8 +580,6 @@ install_netmaker() {
|
|||
|
||||
echo "Starting containers..."
|
||||
|
||||
|
||||
|
||||
# start docker and rebuild containers / networks
|
||||
cd "${SCRIPT_DIR}"
|
||||
docker-compose up -d --force-recreate
|
||||
|
|
Loading…
Reference in a new issue