mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-13 00:24:31 +08:00
commit
3784efaa9b
2 changed files with 38 additions and 30 deletions
|
@ -2,6 +2,7 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gravitl/netmaker/database"
|
"github.com/gravitl/netmaker/database"
|
||||||
|
@ -9,6 +10,7 @@ import (
|
||||||
"github.com/gravitl/netmaker/models"
|
"github.com/gravitl/netmaker/models"
|
||||||
"github.com/gravitl/netmaker/servercfg"
|
"github.com/gravitl/netmaker/servercfg"
|
||||||
"github.com/posthog/posthog-go"
|
"github.com/posthog/posthog-go"
|
||||||
|
"golang.org/x/exp/slog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// flags to keep for telemetry
|
// flags to keep for telemetry
|
||||||
|
@ -39,14 +41,18 @@ func sendTelemetry() error {
|
||||||
// get telemetry data
|
// get telemetry data
|
||||||
d, err := FetchTelemetryData()
|
d, err := FetchTelemetryData()
|
||||||
if err != nil {
|
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})
|
client, err := posthog.NewWithConfig(posthog_pub_key, posthog.Config{Endpoint: posthog_endpoint})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
|
slog.Info("sending telemetry data to posthog", "data", d)
|
||||||
|
|
||||||
// send to posthog
|
// send to posthog
|
||||||
return client.Enqueue(posthog.Capture{
|
return client.Enqueue(posthog.Capture{
|
||||||
DistinctId: telRecord.UUID,
|
DistinctId: telRecord.UUID,
|
||||||
|
@ -67,7 +73,11 @@ func sendTelemetry() error {
|
||||||
Set("k8s", d.Count.K8S).
|
Set("k8s", d.Count.K8S).
|
||||||
Set("version", d.Version).
|
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_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.Nodes = len(nodes)
|
||||||
data.Count = getClientCount(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
|
return data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,16 +181,19 @@ func getDBLength(dbname string) int {
|
||||||
|
|
||||||
// telemetryData - What data to send to posthog
|
// telemetryData - What data to send to posthog
|
||||||
type telemetryData struct {
|
type telemetryData struct {
|
||||||
Nodes int
|
Nodes int
|
||||||
Hosts int
|
Hosts int
|
||||||
ExtClients int
|
ExtClients int
|
||||||
Users int
|
Users int
|
||||||
Count clientCount
|
Count clientCount
|
||||||
Networks int
|
Networks int
|
||||||
Servers int
|
Servers int
|
||||||
Version string
|
Version string
|
||||||
IsPro bool
|
IsPro bool
|
||||||
IsFreeTier bool
|
IsFreeTier bool
|
||||||
|
IsProTrial bool
|
||||||
|
ProTrialEndDate time.Time
|
||||||
|
IsSaasTenant bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// clientCount - What types of netclients we're tallying
|
// clientCount - What types of netclients we're tallying
|
||||||
|
|
|
@ -470,23 +470,11 @@ set_install_vars() {
|
||||||
|
|
||||||
wait_seconds 1
|
wait_seconds 1
|
||||||
|
|
||||||
|
|
||||||
unset GET_EMAIL
|
unset GET_EMAIL
|
||||||
unset RAND_EMAIL
|
while [ -z "$GET_EMAIL" ]; do
|
||||||
RAND_EMAIL="$(echo $RANDOM | md5sum | head -c 16)@email.com"
|
read -p "Email Address for Domain Registration: " GET_EMAIL
|
||||||
# suggest the prev email or a random one
|
done
|
||||||
EMAIL_SUGGESTED=${NM_EMAIL:-$RAND_EMAIL}
|
EMAIL="$GET_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
|
|
||||||
|
|
||||||
wait_seconds 1
|
wait_seconds 1
|
||||||
|
|
||||||
|
@ -592,8 +580,6 @@ install_netmaker() {
|
||||||
|
|
||||||
echo "Starting containers..."
|
echo "Starting containers..."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# start docker and rebuild containers / networks
|
# start docker and rebuild containers / networks
|
||||||
cd "${SCRIPT_DIR}"
|
cd "${SCRIPT_DIR}"
|
||||||
docker-compose up -d --force-recreate
|
docker-compose up -d --force-recreate
|
||||||
|
|
Loading…
Add table
Reference in a new issue