mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-30 01:32:00 +01:00
The infrastructure map is a named bet, graded on 18 December on whether people open it and save its image. Nothing counted either, so the grade could only have read forum mentions. Schema v24 adds three counts to the ping, each a number of browser sessions over 30 days: sessions that opened the map, sessions that saved an image, and sessions that saved one with names hidden. The browser reports each milestone to its own Pulse server once per session, through a new route that takes one closed value and nothing else. The server keeps a daily tally and drops any key outside the closed set. The map draws names, addresses and networks, and none of them, nor the image, leaves the browser for this. Density is not counted: it defaults from estate size, so it would measure the estate and not a choice. The session rule is the one the workload-history counters already had, so both now share one recorder instead of two copies of it. PRIVACY.md lists the three fields and the v24 change. The receiver is in rcourtman/pulse-pro (PRs 919 and 923) and needs a licence-server deploy before the counts are stored.
90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/config"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/telemetry"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type infrastructureMapActivityRequest struct {
|
|
Activity string `json:"activity"`
|
|
}
|
|
|
|
// HandleInfrastructureMapActivity accepts one closed, content-free map
|
|
// milestone: the page was opened, an image was saved, or an image was saved
|
|
// with names hidden. The browser deduplicates each value per session;
|
|
// this boundary rejects everything outside the declared set and persists only
|
|
// counts. Nothing the map draws is ever part of the request.
|
|
func (r *Router) HandleInfrastructureMapActivity(w http.ResponseWriter, req *http.Request) {
|
|
if req.Method != http.MethodPost {
|
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
var payload infrastructureMapActivityRequest
|
|
dec := json.NewDecoder(http.MaxBytesReader(w, req.Body, 1024))
|
|
dec.DisallowUnknownFields()
|
|
if err := dec.Decode(&payload); err != nil {
|
|
http.Error(w, "Invalid request", http.StatusBadRequest)
|
|
return
|
|
}
|
|
var discard json.RawMessage
|
|
if err := dec.Decode(&discard); err != io.EOF {
|
|
http.Error(w, "Invalid request", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
activity := strings.TrimSpace(payload.Activity)
|
|
if !config.IsInfrastructureMapActivity(activity) {
|
|
http.Error(w, "Unknown infrastructure map activity", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
persistence := r.persistenceForOrg(req.Context())
|
|
if persistence != nil {
|
|
if err := persistence.RecordInfrastructureMapActivity(activity, time.Now().UTC()); err != nil {
|
|
log.Debug().Err(err).Str("activity", activity).Msg("Failed to record infrastructure map activity")
|
|
}
|
|
}
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}
|
|
|
|
// ApplyInfrastructureMapTelemetrySnapshot aggregates the bounded, content-free
|
|
// map counters across local organizations for the existing daily telemetry
|
|
// ping.
|
|
func (r *Router) ApplyInfrastructureMapTelemetrySnapshot(s *telemetry.Snapshot, now time.Time) {
|
|
if r == nil || s == nil {
|
|
return
|
|
}
|
|
if now.IsZero() {
|
|
now = time.Now()
|
|
}
|
|
since := now.UTC().Add(-telemetry.PulseIntelligenceTelemetryWindow)
|
|
for _, orgID := range r.pulseIntelligenceTelemetryOrgIDs() {
|
|
persistence := r.persistence
|
|
if orgID != "default" && r.multiTenant != nil {
|
|
var err error
|
|
persistence, err = r.multiTenant.GetPersistence(orgID)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
}
|
|
if persistence == nil {
|
|
continue
|
|
}
|
|
tally, err := persistence.LoadInfrastructureMapActivityTally()
|
|
if err != nil || tally == nil {
|
|
continue
|
|
}
|
|
s.InfrastructureMapOpenSessions30d += tally.CountSince(config.InfrastructureMapActivityOpen, since)
|
|
s.InfrastructureMapExportSessions30d += tally.CountSince(config.InfrastructureMapActivityExport, since)
|
|
s.InfrastructureMapExportNamesHiddenSessions30d += tally.CountSince(config.InfrastructureMapActivityExportNamesHidden, since)
|
|
}
|
|
}
|