Private
Public Access
1
0

Update schema for monitors v4; use go tool
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2025-06-21 00:45:02 -07:00
parent ae7acb4111
commit 087d253d90
14 changed files with 332 additions and 211 deletions

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// sqlc v1.29.0
package ntpdb

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// sqlc v1.29.0
package ntpdb
@@ -283,10 +283,11 @@ type LogScore struct {
type Monitor struct {
ID uint32 `db:"id" json:"id"`
IDToken sql.NullString `db:"id_token" json:"id_token"`
Type MonitorsType `db:"type" json:"type"`
UserID sql.NullInt32 `db:"user_id" json:"user_id"`
AccountID sql.NullInt32 `db:"account_id" json:"account_id"`
Name string `db:"name" json:"name"`
Hostname string `db:"hostname" json:"hostname"`
Location string `db:"location" json:"location"`
Ip sql.NullString `db:"ip" json:"ip"`
IpVersion NullMonitorsIpVersion `db:"ip_version" json:"ip_version"`
@@ -298,6 +299,8 @@ type Monitor struct {
LastSeen sql.NullTime `db:"last_seen" json:"last_seen"`
LastSubmit sql.NullTime `db:"last_submit" json:"last_submit"`
CreatedOn time.Time `db:"created_on" json:"created_on"`
DeletedOn sql.NullTime `db:"deleted_on" json:"deleted_on"`
IsCurrent sql.NullBool `db:"is_current" json:"is_current"`
}
type Server struct {

View File

@@ -7,8 +7,8 @@ import (
func (m *Monitor) DisplayName() string {
switch {
case len(m.Name) > 0:
return m.Name
// case len(m.Hostname) > 0:
// return m.Hostname
case m.TlsName.Valid && len(m.TlsName.String) > 0:
name := m.TlsName.String
if idx := strings.Index(name, "."); idx > 0 {

View File

@@ -1,10 +1,10 @@
// Code generated by gowrap. DO NOT EDIT.
// template: https://raw.githubusercontent.com/hexdigest/gowrap/6c8f05695fec23df85903a8da0af66ac414e2a63/templates/opentelemetry
// template: https://raw.githubusercontent.com/hexdigest/gowrap/6bd1bc023b4d2a619f30020924f258b8ff665a7a/templates/opentelemetry
// gowrap: http://github.com/hexdigest/gowrap
package ntpdb
//go:generate gowrap gen -p go.ntppool.org/data-api/ntpdb -i QuerierTx -t https://raw.githubusercontent.com/hexdigest/gowrap/6c8f05695fec23df85903a8da0af66ac414e2a63/templates/opentelemetry -o otel.go -l ""
//go:generate gowrap gen -p go.ntppool.org/data-api/ntpdb -i QuerierTx -t https://raw.githubusercontent.com/hexdigest/gowrap/6bd1bc023b4d2a619f30020924f258b8ff665a7a/templates/opentelemetry -o otel.go -l ""
import (
"context"
@@ -12,10 +12,11 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
_codes "go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
// QuerierTxWithTracing implements QuerierTx interface instrumented with opentracing spans
// QuerierTxWithTracing implements QuerierTx interface instrumented with open telemetry spans
type QuerierTxWithTracing struct {
QuerierTx
_instance string
@@ -47,6 +48,7 @@ func (_d QuerierTxWithTracing) Begin(ctx context.Context) (q1 QuerierTx, err err
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -68,6 +70,7 @@ func (_d QuerierTxWithTracing) Commit(ctx context.Context) (err error) {
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -91,6 +94,7 @@ func (_d QuerierTxWithTracing) GetMonitorByName(ctx context.Context, tlsName sql
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -114,6 +118,7 @@ func (_d QuerierTxWithTracing) GetMonitorsByID(ctx context.Context, monitorids [
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -137,6 +142,7 @@ func (_d QuerierTxWithTracing) GetServerByID(ctx context.Context, id uint32) (s1
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -160,6 +166,7 @@ func (_d QuerierTxWithTracing) GetServerByIP(ctx context.Context, ip string) (s1
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -183,6 +190,7 @@ func (_d QuerierTxWithTracing) GetServerLogScores(ctx context.Context, arg GetSe
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -206,6 +214,7 @@ func (_d QuerierTxWithTracing) GetServerLogScoresByMonitorID(ctx context.Context
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -229,6 +238,7 @@ func (_d QuerierTxWithTracing) GetServerNetspeed(ctx context.Context, ip string)
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -252,6 +262,7 @@ func (_d QuerierTxWithTracing) GetServerScores(ctx context.Context, arg GetServe
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -275,6 +286,7 @@ func (_d QuerierTxWithTracing) GetZoneByName(ctx context.Context, name string) (
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -298,6 +310,7 @@ func (_d QuerierTxWithTracing) GetZoneCounts(ctx context.Context, zoneID uint32)
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -320,6 +333,7 @@ func (_d QuerierTxWithTracing) GetZoneStatsData(ctx context.Context) (ga1 []GetZ
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -343,6 +357,7 @@ func (_d QuerierTxWithTracing) GetZoneStatsV2(ctx context.Context, ip string) (g
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),
@@ -364,6 +379,7 @@ func (_d QuerierTxWithTracing) Rollback(ctx context.Context) (err error) {
"err": err})
} else if err != nil {
_span.RecordError(err)
_span.SetStatus(_codes.Error, err.Error())
_span.SetAttributes(
attribute.String("event", "error"),
attribute.String("message", err.Error()),

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// sqlc v1.29.0
package ntpdb

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// sqlc v1.29.0
// source: query.sql
package ntpdb
@@ -13,7 +13,7 @@ import (
)
const getMonitorByName = `-- name: GetMonitorByName :one
select id, type, user_id, account_id, name, location, ip, ip_version, tls_name, api_key, status, config, client_version, last_seen, last_submit, created_on from monitors
select id, id_token, type, user_id, account_id, hostname, location, ip, ip_version, tls_name, api_key, status, config, client_version, last_seen, last_submit, created_on, deleted_on, is_current from monitors
where
tls_name like ?
order by id
@@ -25,10 +25,11 @@ func (q *Queries) GetMonitorByName(ctx context.Context, tlsName sql.NullString)
var i Monitor
err := row.Scan(
&i.ID,
&i.IDToken,
&i.Type,
&i.UserID,
&i.AccountID,
&i.Name,
&i.Hostname,
&i.Location,
&i.Ip,
&i.IpVersion,
@@ -40,12 +41,14 @@ func (q *Queries) GetMonitorByName(ctx context.Context, tlsName sql.NullString)
&i.LastSeen,
&i.LastSubmit,
&i.CreatedOn,
&i.DeletedOn,
&i.IsCurrent,
)
return i, err
}
const getMonitorsByID = `-- name: GetMonitorsByID :many
select id, type, user_id, account_id, name, location, ip, ip_version, tls_name, api_key, status, config, client_version, last_seen, last_submit, created_on from monitors
select id, id_token, type, user_id, account_id, hostname, location, ip, ip_version, tls_name, api_key, status, config, client_version, last_seen, last_submit, created_on, deleted_on, is_current from monitors
where id in (/*SLICE:MonitorIDs*/?)
`
@@ -70,10 +73,11 @@ func (q *Queries) GetMonitorsByID(ctx context.Context, monitorids []uint32) ([]M
var i Monitor
if err := rows.Scan(
&i.ID,
&i.IDToken,
&i.Type,
&i.UserID,
&i.AccountID,
&i.Name,
&i.Hostname,
&i.Location,
&i.Ip,
&i.IpVersion,
@@ -85,6 +89,8 @@ func (q *Queries) GetMonitorsByID(ctx context.Context, monitorids []uint32) ([]M
&i.LastSeen,
&i.LastSubmit,
&i.CreatedOn,
&i.DeletedOn,
&i.IsCurrent,
); err != nil {
return nil, err
}
@@ -268,7 +274,7 @@ func (q *Queries) GetServerNetspeed(ctx context.Context, ip string) (uint32, err
const getServerScores = `-- name: GetServerScores :many
select
m.id, m.name, m.tls_name, m.location, m.type,
m.id, m.hostname, m.tls_name, m.location, m.type,
ss.score_raw, ss.score_ts, ss.status
from server_scores ss
inner join monitors m
@@ -285,7 +291,7 @@ type GetServerScoresParams struct {
type GetServerScoresRow struct {
ID uint32 `db:"id" json:"id"`
Name string `db:"name" json:"name"`
Hostname string `db:"hostname" json:"hostname"`
TlsName sql.NullString `db:"tls_name" json:"tls_name"`
Location string `db:"location" json:"location"`
Type MonitorsType `db:"type" json:"type"`
@@ -316,7 +322,7 @@ func (q *Queries) GetServerScores(ctx context.Context, arg GetServerScoresParams
var i GetServerScoresRow
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Hostname,
&i.TlsName,
&i.Location,
&i.Type,