Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9481d12c6 |
88
.drone.yml
Normal file
88
.drone.yml
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: kubernetes
|
||||||
|
name: default
|
||||||
|
|
||||||
|
environment:
|
||||||
|
GOCACHE: /cache/pkg/cache
|
||||||
|
GOMODCACHE: /cache/pkg/mod
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: fetch-tags
|
||||||
|
image: alpine/git
|
||||||
|
commands:
|
||||||
|
- git fetch --tags
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 250
|
||||||
|
memory: 50MiB
|
||||||
|
limits:
|
||||||
|
cpu: 250
|
||||||
|
memory: 100MiB
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
image: golang:1.25
|
||||||
|
pull: always
|
||||||
|
volumes:
|
||||||
|
- name: go
|
||||||
|
path: /go
|
||||||
|
- name: gopkg
|
||||||
|
path: /cache
|
||||||
|
commands:
|
||||||
|
- go test -v ./...
|
||||||
|
- go build ./...
|
||||||
|
|
||||||
|
- name: goreleaser
|
||||||
|
image: golang:1.25
|
||||||
|
pull: always
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 6000
|
||||||
|
memory: 1024MiB
|
||||||
|
limits:
|
||||||
|
cpu: 10000
|
||||||
|
memory: 4096MiB
|
||||||
|
volumes:
|
||||||
|
- name: go
|
||||||
|
path: /go
|
||||||
|
- name: gopkg
|
||||||
|
path: /cache
|
||||||
|
environment:
|
||||||
|
# GITHUB_TOKEN:
|
||||||
|
# from_secret: GITHUB_TOKEN
|
||||||
|
commands:
|
||||||
|
- ./scripts/run-goreleaser
|
||||||
|
depends_on: [test]
|
||||||
|
|
||||||
|
- name: docker
|
||||||
|
image: harbor.ntppool.org/ntppool/drone-kaniko:main
|
||||||
|
pull: always
|
||||||
|
volumes:
|
||||||
|
- name: go
|
||||||
|
path: /go
|
||||||
|
- name: gopkg
|
||||||
|
path: /cache
|
||||||
|
settings:
|
||||||
|
repo: ntppool/data-api
|
||||||
|
registry: harbor.ntppool.org
|
||||||
|
auto_tag: true
|
||||||
|
tags: SHA7,${DRONE_SOURCE_BRANCH}
|
||||||
|
cache: true
|
||||||
|
username:
|
||||||
|
from_secret: harbor_username
|
||||||
|
password:
|
||||||
|
from_secret: harbor_password
|
||||||
|
depends_on: [goreleaser]
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: go
|
||||||
|
temp: {}
|
||||||
|
- name: gopkg
|
||||||
|
claim:
|
||||||
|
name: go-pkg
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: signature
|
||||||
|
hmac: 7f4f57140394a1c3a34e4d23188edda3cd95359dacf6d0abfa45bda3afff692f
|
||||||
|
|
||||||
|
...
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
|||||||
data-api
|
data-api
|
||||||
database.yaml
|
database.yaml
|
||||||
dist/
|
dist/
|
||||||
/vendor/
|
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
when:
|
|
||||||
- event: [push, pull_request, tag, manual]
|
|
||||||
|
|
||||||
clone:
|
|
||||||
git:
|
|
||||||
image: woodpeckerci/plugin-git
|
|
||||||
settings:
|
|
||||||
tags: true
|
|
||||||
|
|
||||||
variables:
|
|
||||||
- &go_env
|
|
||||||
GOMODCACHE: /go/pkg/mod
|
|
||||||
GOCACHE: /go/pkg/cache
|
|
||||||
- &go_volumes
|
|
||||||
- go-pkg:/go/pkg
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: vendor
|
|
||||||
image: golang:1.26
|
|
||||||
pull: true
|
|
||||||
environment:
|
|
||||||
GOMODCACHE: /go/pkg/mod
|
|
||||||
GOCACHE: /go/pkg/cache
|
|
||||||
GITEA_TOKEN:
|
|
||||||
from_secret: gitea_token
|
|
||||||
volumes: *go_volumes
|
|
||||||
commands:
|
|
||||||
- printf "machine gitea.develooper.com\nlogin __token__\npassword $GITEA_TOKEN\n" > ~/.netrc
|
|
||||||
- go mod vendor
|
|
||||||
- rm -f ~/.netrc
|
|
||||||
|
|
||||||
- name: test
|
|
||||||
image: golang:1.26
|
|
||||||
pull: true
|
|
||||||
environment: *go_env
|
|
||||||
volumes: *go_volumes
|
|
||||||
commands:
|
|
||||||
- go test -v ./...
|
|
||||||
- go build ./...
|
|
||||||
depends_on: [vendor]
|
|
||||||
|
|
||||||
- name: goreleaser
|
|
||||||
image: golang:1.26
|
|
||||||
pull: true
|
|
||||||
environment: *go_env
|
|
||||||
volumes: *go_volumes
|
|
||||||
commands:
|
|
||||||
- ./scripts/run-goreleaser
|
|
||||||
backend_options:
|
|
||||||
kubernetes:
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
cpu: 6000m
|
|
||||||
memory: 1Gi
|
|
||||||
limits:
|
|
||||||
cpu: 10000m
|
|
||||||
memory: 4Gi
|
|
||||||
depends_on: [test]
|
|
||||||
|
|
||||||
- name: generate-tags
|
|
||||||
image: ghcr.io/abh/woodpecker-docker-tags-plugin:sha-8a3bd7c
|
|
||||||
settings:
|
|
||||||
tags: |
|
|
||||||
branch
|
|
||||||
sha
|
|
||||||
semver --auto
|
|
||||||
edge -v latest
|
|
||||||
when:
|
|
||||||
- event: [push, tag, manual]
|
|
||||||
depends_on: [goreleaser]
|
|
||||||
|
|
||||||
- name: docker
|
|
||||||
image: woodpeckerci/plugin-kaniko
|
|
||||||
settings:
|
|
||||||
registry: harbor.ntppool.org
|
|
||||||
repo: ntppool/data-api
|
|
||||||
cache: true
|
|
||||||
username:
|
|
||||||
from_secret: harbor_username
|
|
||||||
password:
|
|
||||||
from_secret: harbor_password
|
|
||||||
when:
|
|
||||||
- event: [push, tag, manual]
|
|
||||||
depends_on: [goreleaser, generate-tags]
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM alpine:3.23
|
FROM alpine:3.21
|
||||||
|
|
||||||
RUN apk --no-cache upgrade
|
RUN apk --no-cache upgrade
|
||||||
RUN apk --no-cache add ca-certificates tzdata zsh jq tmux curl
|
RUN apk --no-cache add ca-certificates tzdata zsh jq tmux curl
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package chdb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -68,11 +67,11 @@ func setupClickhouse(ctx context.Context, configFile string) (*ClickHouse, error
|
|||||||
|
|
||||||
ch.Logs, err = open(ctx, cfg.ClickHouse.Logs)
|
ch.Logs, err = open(ctx, cfg.ClickHouse.Logs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("logs: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
ch.Scores, err = open(ctx, cfg.ClickHouse.Scores)
|
ch.Scores, err = open(ctx, cfg.ClickHouse.Scores)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("scores: %w", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ch, nil
|
return ch, nil
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package chdb
|
package chdb
|
||||||
|
|
||||||
// queries to the DNS database
|
// queries to the GeoDNS database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -208,7 +208,7 @@ func (d *ClickHouse) DNSQueries(ctx context.Context) ([]DNSQueryCounts, error) {
|
|||||||
sum(q)/300 as avg, max(q) as max
|
sum(q)/300 as avg, max(q) as max
|
||||||
from (
|
from (
|
||||||
select window as t, sumSimpleState(queries) as q
|
select window as t, sumSimpleState(queries) as q
|
||||||
from dns.by_origin_1s
|
from geodns.by_origin_1s
|
||||||
where
|
where
|
||||||
window > FROM_UNIXTIME(?)
|
window > FROM_UNIXTIME(?)
|
||||||
and Origin IN ('pool.ntp.org', 'g.ntpns.org')
|
and Origin IN ('pool.ntp.org', 'g.ntpns.org')
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ func (d *ClickHouse) LogscoresTimeRange(ctx context.Context, serverID, monitorID
|
|||||||
samples = append(samples, map[string]interface{}{
|
samples = append(samples, map[string]interface{}{
|
||||||
"id": row.ID,
|
"id": row.ID,
|
||||||
"monitor_id": row.MonitorID,
|
"monitor_id": row.MonitorID,
|
||||||
"ts": row.Ts.Format(time.RFC3339),
|
"ts": row.Ts.Time.Format(time.RFC3339),
|
||||||
"score": row.Score,
|
"score": row.Score,
|
||||||
"rtt_valid": row.Rtt.Valid,
|
"rtt_valid": row.Rtt.Valid,
|
||||||
"offset_valid": row.Offset.Valid,
|
"offset_valid": row.Offset.Valid,
|
||||||
|
|||||||
27
go.mod
27
go.mod
@@ -15,13 +15,14 @@ tool (
|
|||||||
require (
|
require (
|
||||||
dario.cat/mergo v1.0.2
|
dario.cat/mergo v1.0.2
|
||||||
github.com/ClickHouse/clickhouse-go/v2 v2.40.3
|
github.com/ClickHouse/clickhouse-go/v2 v2.40.3
|
||||||
github.com/go-sql-driver/mysql v1.9.3
|
|
||||||
github.com/hashicorp/go-retryablehttp v0.7.8
|
github.com/hashicorp/go-retryablehttp v0.7.8
|
||||||
|
github.com/jackc/pgx/v5 v5.7.6
|
||||||
github.com/labstack/echo-contrib v0.17.4
|
github.com/labstack/echo-contrib v0.17.4
|
||||||
github.com/labstack/echo/v4 v4.13.4
|
github.com/labstack/echo/v4 v4.13.4
|
||||||
github.com/samber/slog-echo v1.17.2
|
github.com/samber/slog-echo v1.17.2
|
||||||
github.com/spf13/cobra v1.10.1
|
github.com/spf13/cobra v1.10.1
|
||||||
go.ntppool.org/common v0.5.2
|
go.ntppool.org/api v0.3.4
|
||||||
|
go.ntppool.org/common v0.6.3-0.20251129195245-283d3936f6d0
|
||||||
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.63.0
|
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.63.0
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.63.0
|
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.63.0
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
|
||||||
@@ -52,7 +53,8 @@ require (
|
|||||||
github.com/go-faster/errors v0.7.1 // indirect
|
github.com/go-faster/errors v0.7.1 // indirect
|
||||||
github.com/go-logr/logr v1.4.3 // indirect
|
github.com/go-logr/logr v1.4.3 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/google/cel-go v0.25.0 // indirect
|
github.com/go-sql-driver/mysql v1.9.3 // indirect
|
||||||
|
github.com/google/cel-go v0.24.1 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||||
@@ -62,7 +64,6 @@ require (
|
|||||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/pgx/v5 v5.7.5 // indirect
|
|
||||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/klauspost/compress v1.18.0 // indirect
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
@@ -76,10 +77,10 @@ require (
|
|||||||
github.com/paulmach/orb v0.12.0 // indirect
|
github.com/paulmach/orb v0.12.0 // indirect
|
||||||
github.com/pganalyze/pg_query_go/v6 v6.1.0 // indirect
|
github.com/pganalyze/pg_query_go/v6 v6.1.0 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
github.com/pierrec/lz4/v4 v4.1.22 // indirect
|
||||||
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee // indirect
|
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect
|
||||||
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
|
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
|
||||||
github.com/pingcap/log v1.1.0 // indirect
|
github.com/pingcap/log v1.1.0 // indirect
|
||||||
github.com/pingcap/tidb/pkg/parser v0.0.0-20250620043151-465b166e2b61 // indirect
|
github.com/pingcap/tidb/pkg/parser v0.0.0-20250324122243-d51e00e5bbf0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/prometheus/client_golang v1.23.2 // indirect
|
github.com/prometheus/client_golang v1.23.2 // indirect
|
||||||
@@ -98,12 +99,12 @@ require (
|
|||||||
github.com/spf13/cast v1.4.1 // indirect
|
github.com/spf13/cast v1.4.1 // indirect
|
||||||
github.com/spf13/pflag v1.0.10 // indirect
|
github.com/spf13/pflag v1.0.10 // indirect
|
||||||
github.com/sqlc-dev/sqlc v1.29.0 // indirect
|
github.com/sqlc-dev/sqlc v1.29.0 // indirect
|
||||||
github.com/stoewer/go-strcase v1.3.1 // indirect
|
github.com/stoewer/go-strcase v1.2.0 // indirect
|
||||||
github.com/tetratelabs/wazero v1.9.0 // indirect
|
github.com/tetratelabs/wazero v1.9.0 // indirect
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||||
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 // indirect
|
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 // indirect
|
||||||
github.com/wasilibs/wazero-helpers v0.0.0-20250123031827-cd30c44769bb // indirect
|
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
go.opentelemetry.io/contrib/bridges/otelslog v0.13.0 // indirect
|
go.opentelemetry.io/contrib/bridges/otelslog v0.13.0 // indirect
|
||||||
go.opentelemetry.io/contrib/bridges/prometheus v0.63.0 // indirect
|
go.opentelemetry.io/contrib/bridges/prometheus v0.63.0 // indirect
|
||||||
@@ -131,20 +132,20 @@ require (
|
|||||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||||
golang.org/x/crypto v0.42.0 // indirect
|
golang.org/x/crypto v0.42.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
|
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
|
||||||
golang.org/x/mod v0.28.0 // indirect
|
golang.org/x/mod v0.28.0 // indirect
|
||||||
golang.org/x/net v0.44.0 // indirect
|
golang.org/x/net v0.44.0 // indirect
|
||||||
golang.org/x/sys v0.36.0 // indirect
|
golang.org/x/sys v0.36.0 // indirect
|
||||||
golang.org/x/text v0.29.0 // indirect
|
golang.org/x/text v0.29.0 // indirect
|
||||||
golang.org/x/time v0.13.0 // indirect
|
golang.org/x/time v0.13.0 // indirect
|
||||||
golang.org/x/tools v0.36.0 // indirect
|
golang.org/x/tools v0.37.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250922171735-9219d122eba9 // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20250922171735-9219d122eba9 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 // indirect
|
||||||
google.golang.org/grpc v1.75.1 // indirect
|
google.golang.org/grpc v1.75.1 // indirect
|
||||||
google.golang.org/protobuf v1.36.9 // indirect
|
google.golang.org/protobuf v1.36.9 // indirect
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
modernc.org/libc v1.66.0 // indirect
|
modernc.org/libc v1.62.1 // indirect
|
||||||
modernc.org/mathutil v1.7.1 // indirect
|
modernc.org/mathutil v1.7.1 // indirect
|
||||||
modernc.org/memory v1.11.0 // indirect
|
modernc.org/memory v1.9.1 // indirect
|
||||||
modernc.org/sqlite v1.38.0 // indirect
|
modernc.org/sqlite v1.37.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
71
go.sum
71
go.sum
@@ -59,8 +59,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
|
|||||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/google/cel-go v0.25.0 h1:jsFw9Fhn+3y2kBbltZR4VEz5xKkcIFRPDnuEzAGv5GY=
|
github.com/google/cel-go v0.24.1 h1:jsBCtxG8mM5wiUJDSGUqU0K7Mtr3w7Eyv00rw4DiZxI=
|
||||||
github.com/google/cel-go v0.25.0/go.mod h1:hjEb6r5SuOSlhCHmFoLzu8HGCERvIsDAbxDAyNU/MmI=
|
github.com/google/cel-go v0.24.1/go.mod h1:Hdf9TqOaTNSFQA1ybQaRqATVoK7m/zcf7IMhGXP5zI8=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
@@ -92,8 +92,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
|
|||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
|
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
|
||||||
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
||||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||||
@@ -141,14 +141,14 @@ github.com/pganalyze/pg_query_go/v6 v6.1.0/go.mod h1:nvTHIuoud6e1SfrUaFwHqT0i4b5
|
|||||||
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
|
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
|
||||||
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||||
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||||
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee h1:/IDPbpzkzA97t1/Z1+C3KlxbevjMeaI6BQYxvivu4u8=
|
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb h1:3pSi4EDG6hg0orE1ndHkXvX6Qdq2cZn8gAPir8ymKZk=
|
||||||
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
|
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg=
|
||||||
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
|
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE=
|
||||||
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
|
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4=
|
||||||
github.com/pingcap/log v1.1.0 h1:ELiPxACz7vdo1qAvvaWJg1NrYFoY6gqAh/+Uo6aXdD8=
|
github.com/pingcap/log v1.1.0 h1:ELiPxACz7vdo1qAvvaWJg1NrYFoY6gqAh/+Uo6aXdD8=
|
||||||
github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
|
github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
|
||||||
github.com/pingcap/tidb/pkg/parser v0.0.0-20250620043151-465b166e2b61 h1:NBx61NtqoscSxX2DfwGovBHf9FJch1whHIwMhklBk7I=
|
github.com/pingcap/tidb/pkg/parser v0.0.0-20250324122243-d51e00e5bbf0 h1:W3rpAI3bubR6VWOcwxDIG0Gz9G5rl5b3SL116T0vBt0=
|
||||||
github.com/pingcap/tidb/pkg/parser v0.0.0-20250620043151-465b166e2b61/go.mod h1:mpCcwRdMnmvNkBxcT4AqiE0yuvfJTdmCJs7cfznJw1w=
|
github.com/pingcap/tidb/pkg/parser v0.0.0-20250324122243-d51e00e5bbf0/go.mod h1:+8feuexTKcXHZF/dkDfvCwEyBAmgb4paFc3/WeYV2eE=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
@@ -197,20 +197,15 @@ github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
|||||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/sqlc-dev/sqlc v1.29.0 h1:HQctoD7y/i29Bao53qXO7CZ/BV9NcvpGpsJWvz9nKWs=
|
github.com/sqlc-dev/sqlc v1.29.0 h1:HQctoD7y/i29Bao53qXO7CZ/BV9NcvpGpsJWvz9nKWs=
|
||||||
github.com/sqlc-dev/sqlc v1.29.0/go.mod h1:BavmYw11px5AdPOjAVHmb9fctP5A8GTziC38wBF9tp0=
|
github.com/sqlc-dev/sqlc v1.29.0/go.mod h1:BavmYw11px5AdPOjAVHmb9fctP5A8GTziC38wBF9tp0=
|
||||||
github.com/stoewer/go-strcase v1.3.1 h1:iS0MdW+kVTxgMoE1LAZyMiYJFKlOzLooE4MxjirtkAs=
|
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
|
||||||
github.com/stoewer/go-strcase v1.3.1/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
|
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
|
||||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
|
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
|
||||||
@@ -222,8 +217,8 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ
|
|||||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo=
|
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo=
|
||||||
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07/go.mod h1:Ak17IJ037caFp4jpCw/iQQ7/W74Sqpb1YuKJU6HTKfM=
|
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07/go.mod h1:Ak17IJ037caFp4jpCw/iQQ7/W74Sqpb1YuKJU6HTKfM=
|
||||||
github.com/wasilibs/wazero-helpers v0.0.0-20250123031827-cd30c44769bb h1:gQ+ZV4wJke/EBKYciZ2MshEouEHFuinB85dY3f5s1q8=
|
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4=
|
||||||
github.com/wasilibs/wazero-helpers v0.0.0-20250123031827-cd30c44769bb/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY=
|
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY=
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||||
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||||
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||||
@@ -233,8 +228,12 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7Jul
|
|||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
|
go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
|
||||||
go.ntppool.org/common v0.5.2 h1:Ijlezhiqqs7TJYZTWwEwultLFxhNaXsh6DkaO53m/F4=
|
go.ntppool.org/api v0.3.4 h1:KeRyFhIRkjJwZif7hkpqEDEBmukyYGiOi2Fd6j3UzQ0=
|
||||||
go.ntppool.org/common v0.5.2/go.mod h1:e5ohROK9LdZZTI1neNiSlmgmWC23F779qzLvSi4JzyI=
|
go.ntppool.org/api v0.3.4/go.mod h1:LFLAwnrc/JyjzKnjgf8tCOJhps6oFIjuledS3PCx7xc=
|
||||||
|
go.ntppool.org/common v0.6.2 h1:TvxrpaBQpSYuvuRT24M/I1ZqFjh4woHJTqayCOxe+o8=
|
||||||
|
go.ntppool.org/common v0.6.2/go.mod h1:Dkc2P5+aaCseC/cs0uD9elh4yTllqvyeZ1NNT/G/414=
|
||||||
|
go.ntppool.org/common v0.6.3-0.20251129195245-283d3936f6d0 h1:Vbs/RgrwfdA9ZzGAkhFRaU7ZSEl8D28pk95iYhjzvyA=
|
||||||
|
go.ntppool.org/common v0.6.3-0.20251129195245-283d3936f6d0/go.mod h1:Dkc2P5+aaCseC/cs0uD9elh4yTllqvyeZ1NNT/G/414=
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||||
go.opentelemetry.io/contrib/bridges/otelslog v0.13.0 h1:bwnLpizECbPr1RrQ27waeY2SPIPeccCx/xLuoYADZ9s=
|
go.opentelemetry.io/contrib/bridges/otelslog v0.13.0 h1:bwnLpizECbPr1RrQ27waeY2SPIPeccCx/xLuoYADZ9s=
|
||||||
@@ -317,8 +316,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
|||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
||||||
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
|
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
|
||||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
|
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
|
||||||
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
|
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
@@ -363,8 +362,8 @@ golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
|
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
|
||||||
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
|
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@@ -398,28 +397,26 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
|
|||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
modernc.org/cc/v4 v4.26.1 h1:+X5NtzVBn0KgsBCBe+xkDC7twLb/jNVj9FPgiwSQO3s=
|
modernc.org/cc/v4 v4.25.2 h1:T2oH7sZdGvTaie0BRNFbIYsabzCxUQg8nLqCdQ2i0ic=
|
||||||
modernc.org/cc/v4 v4.26.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
modernc.org/cc/v4 v4.25.2/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
|
||||||
modernc.org/ccgo/v4 v4.28.0 h1:rjznn6WWehKq7dG4JtLRKxb52Ecv8OUGah8+Z/SfpNU=
|
modernc.org/ccgo/v4 v4.25.1 h1:TFSzPrAGmDsdnhT9X2UrcPMI3N/mJ9/X9ykKXwLhDsU=
|
||||||
modernc.org/ccgo/v4 v4.28.0/go.mod h1:JygV3+9AV6SmPhDasu4JgquwU81XAKLd3OKTUDNOiKE=
|
modernc.org/ccgo/v4 v4.25.1/go.mod h1:njjuAYiPflywOOrm3B7kCB444ONP5pAVr8PIEoE0uDw=
|
||||||
modernc.org/fileutil v1.3.3 h1:3qaU+7f7xxTUmvU1pJTZiDLAIoJVdUSSauJNHg9yXoA=
|
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
|
||||||
modernc.org/fileutil v1.3.3/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
|
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
|
||||||
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
|
||||||
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
|
||||||
modernc.org/goabi0 v0.0.3 h1:y81b9r3asCh6Xtse6Nz85aYGB0cG3M3U6222yap1KWI=
|
modernc.org/libc v1.62.1 h1:s0+fv5E3FymN8eJVmnk0llBe6rOxCu/DEU+XygRbS8s=
|
||||||
modernc.org/goabi0 v0.0.3/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI=
|
modernc.org/libc v1.62.1/go.mod h1:iXhATfJQLjG3NWy56a6WVU73lWOcdYVxsvwCgoPljuo=
|
||||||
modernc.org/libc v1.66.0 h1:eoFuDb1ozurUY5WSWlgvxHp0FuL+AncMwNjFqGYMJPQ=
|
|
||||||
modernc.org/libc v1.66.0/go.mod h1:AiZxInURfEJx516LqEaFcrC+X38rt9G7+8ojIXQKHbo=
|
|
||||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||||
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
modernc.org/memory v1.9.1 h1:V/Z1solwAVmMW1yttq3nDdZPJqV1rM05Ccq6KMSZ34g=
|
||||||
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
modernc.org/memory v1.9.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||||
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
|
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
|
||||||
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||||
modernc.org/sqlite v1.38.0 h1:+4OrfPQ8pxHKuWG4md1JpR/EYAh3Md7TdejuuzE7EUI=
|
modernc.org/sqlite v1.37.0 h1:s1TMe7T3Q3ovQiK2Ouz4Jwh7dw4ZDqbebSDTlSJdfjI=
|
||||||
modernc.org/sqlite v1.38.0/go.mod h1:1Bj+yES4SVvBZ4cBOpVZ6QgesMCKpJZDq0nxYzOpmNE=
|
modernc.org/sqlite v1.37.0/go.mod h1:5YiWv+YviqGMuGw4V+PNplcyaJ5v+vQd7TQOgkACoJM=
|
||||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package logscores
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
"go.ntppool.org/common/logger"
|
"go.ntppool.org/common/logger"
|
||||||
"go.ntppool.org/common/tracing"
|
"go.ntppool.org/common/tracing"
|
||||||
"go.ntppool.org/data-api/chdb"
|
"go.ntppool.org/data-api/chdb"
|
||||||
@@ -19,12 +20,12 @@ type LogScoreHistory struct {
|
|||||||
// MonitorIDs []uint32
|
// MonitorIDs []uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHistoryClickHouse(ctx context.Context, ch *chdb.ClickHouse, db *sql.DB, serverID, monitorID uint32, since time.Time, count int, fullHistory bool) (*LogScoreHistory, error) {
|
func GetHistoryClickHouse(ctx context.Context, ch *chdb.ClickHouse, db *pgxpool.Pool, serverID, monitorID int64, since time.Time, count int, fullHistory bool) (*LogScoreHistory, error) {
|
||||||
log := logger.FromContext(ctx)
|
log := logger.FromContext(ctx)
|
||||||
ctx, span := tracing.Tracer().Start(ctx, "logscores.GetHistoryClickHouse",
|
ctx, span := tracing.Tracer().Start(ctx, "logscores.GetHistoryClickHouse",
|
||||||
trace.WithAttributes(
|
trace.WithAttributes(
|
||||||
attribute.Int("server", int(serverID)),
|
attribute.Int64("server", serverID),
|
||||||
attribute.Int("monitor", int(monitorID)),
|
attribute.Int64("monitor", monitorID),
|
||||||
attribute.Bool("full_history", fullHistory),
|
attribute.Bool("full_history", fullHistory),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -51,17 +52,17 @@ func GetHistoryClickHouse(ctx context.Context, ch *chdb.ClickHouse, db *sql.DB,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHistoryMySQL(ctx context.Context, db *sql.DB, serverID, monitorID uint32, since time.Time, count int) (*LogScoreHistory, error) {
|
func GetHistoryPostgres(ctx context.Context, db *pgxpool.Pool, serverID, monitorID int64, since time.Time, count int) (*LogScoreHistory, error) {
|
||||||
log := logger.FromContext(ctx)
|
log := logger.FromContext(ctx)
|
||||||
ctx, span := tracing.Tracer().Start(ctx, "logscores.GetHistoryMySQL")
|
ctx, span := tracing.Tracer().Start(ctx, "logscores.GetHistoryPostgres")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
span.SetAttributes(
|
span.SetAttributes(
|
||||||
attribute.Int("server", int(serverID)),
|
attribute.Int64("server", serverID),
|
||||||
attribute.Int("monitor", int(monitorID)),
|
attribute.Int64("monitor", monitorID),
|
||||||
)
|
)
|
||||||
|
|
||||||
log.Debug("GetHistoryMySQL", "server", serverID, "monitor", monitorID, "since", since, "count", count)
|
log.Debug("GetHistoryPostgres", "server", serverID, "monitor", monitorID, "since", since, "count", count)
|
||||||
|
|
||||||
q := ntpdb.NewWrappedQuerier(ntpdb.New(db))
|
q := ntpdb.NewWrappedQuerier(ntpdb.New(db))
|
||||||
|
|
||||||
@@ -69,13 +70,13 @@ func GetHistoryMySQL(ctx context.Context, db *sql.DB, serverID, monitorID uint32
|
|||||||
var err error
|
var err error
|
||||||
if monitorID > 0 {
|
if monitorID > 0 {
|
||||||
ls, err = q.GetServerLogScoresByMonitorID(ctx, ntpdb.GetServerLogScoresByMonitorIDParams{
|
ls, err = q.GetServerLogScoresByMonitorID(ctx, ntpdb.GetServerLogScoresByMonitorIDParams{
|
||||||
ServerID: serverID,
|
ServerID: int64(serverID),
|
||||||
MonitorID: sql.NullInt32{Int32: int32(monitorID), Valid: true},
|
MonitorID: pgtype.Int8{Int64: int64(monitorID), Valid: true},
|
||||||
Limit: int32(count),
|
Limit: int32(count),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ls, err = q.GetServerLogScores(ctx, ntpdb.GetServerLogScoresParams{
|
ls, err = q.GetServerLogScores(ctx, ntpdb.GetServerLogScoresParams{
|
||||||
ServerID: serverID,
|
ServerID: int64(serverID),
|
||||||
Limit: int32(count),
|
Limit: int32(count),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -97,12 +98,12 @@ func GetHistoryMySQL(ctx context.Context, db *sql.DB, serverID, monitorID uint32
|
|||||||
|
|
||||||
func getMonitorNames(ctx context.Context, ls []ntpdb.LogScore, q ntpdb.QuerierTx) (map[int]string, error) {
|
func getMonitorNames(ctx context.Context, ls []ntpdb.LogScore, q ntpdb.QuerierTx) (map[int]string, error) {
|
||||||
monitors := map[int]string{}
|
monitors := map[int]string{}
|
||||||
monitorIDs := []uint32{}
|
monitorIDs := []int64{}
|
||||||
for _, l := range ls {
|
for _, l := range ls {
|
||||||
if !l.MonitorID.Valid {
|
if !l.MonitorID.Valid {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mID := uint32(l.MonitorID.Int32)
|
mID := l.MonitorID.Int64
|
||||||
if _, ok := monitors[int(mID)]; !ok {
|
if _, ok := monitors[int(mID)]; !ok {
|
||||||
monitors[int(mID)] = ""
|
monitors[int(mID)] = ""
|
||||||
monitorIDs = append(monitorIDs, mID)
|
monitorIDs = append(monitorIDs, mID)
|
||||||
|
|||||||
13
ntpdb/db.go
13
ntpdb/db.go
@@ -6,14 +6,15 @@ package ntpdb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"github.com/jackc/pgx/v5/pgconn"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DBTX interface {
|
type DBTX interface {
|
||||||
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
|
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||||
PrepareContext(context.Context, string) (*sql.Stmt, error)
|
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||||
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
|
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||||
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(db DBTX) *Queries {
|
func New(db DBTX) *Queries {
|
||||||
@@ -24,7 +25,7 @@ type Queries struct {
|
|||||||
db DBTX
|
db DBTX
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||||
return &Queries{
|
return &Queries{
|
||||||
db: tx,
|
db: tx,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,85 +1,15 @@
|
|||||||
package ntpdb
|
package ntpdb
|
||||||
|
|
||||||
|
//go:generate go tool github.com/hexdigest/gowrap/cmd/gowrap gen -t ./opentelemetry.gowrap -g -i QuerierTx -p . -o otel.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"database/sql/driver"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/go-sql-driver/mysql"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
"go.ntppool.org/common/logger"
|
"go.ntppool.org/common/database/pgdb"
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
// OpenDB opens a PostgreSQL connection pool using the specified config file
|
||||||
MySQL DBConfig `yaml:"mysql"`
|
func OpenDB(ctx context.Context, configFile string) (*pgxpool.Pool, error) {
|
||||||
}
|
return pgdb.OpenPoolWithConfigFile(ctx, configFile)
|
||||||
|
|
||||||
type DBConfig struct {
|
|
||||||
DSN string `default:"" flag:"dsn" usage:"Database DSN"`
|
|
||||||
User string `default:"" flag:"user"`
|
|
||||||
Pass string `default:"" flag:"pass"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func OpenDB(ctx context.Context, configFile string) (*sql.DB, error) {
|
|
||||||
log := logger.FromContext(ctx)
|
|
||||||
|
|
||||||
dbconn := sql.OpenDB(Driver{CreateConnectorFunc: createConnector(ctx, configFile)})
|
|
||||||
|
|
||||||
dbconn.SetConnMaxLifetime(time.Minute * 3)
|
|
||||||
dbconn.SetMaxOpenConns(8)
|
|
||||||
dbconn.SetMaxIdleConns(3)
|
|
||||||
|
|
||||||
err := dbconn.Ping()
|
|
||||||
if err != nil {
|
|
||||||
log.DebugContext(ctx, "could not connect to database: %s", "err", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return dbconn, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func createConnector(ctx context.Context, configFile string) CreateConnectorFunc {
|
|
||||||
log := logger.FromContext(ctx)
|
|
||||||
return func() (driver.Connector, error) {
|
|
||||||
log.DebugContext(ctx, "opening db config file", "filename", configFile)
|
|
||||||
|
|
||||||
dbFile, err := os.Open(configFile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
dec := yaml.NewDecoder(dbFile)
|
|
||||||
|
|
||||||
cfg := Config{}
|
|
||||||
|
|
||||||
err = dec.Decode(&cfg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// log.Printf("db cfg: %+v", cfg)
|
|
||||||
|
|
||||||
dsn := cfg.MySQL.DSN
|
|
||||||
if len(dsn) == 0 {
|
|
||||||
return nil, fmt.Errorf("--database.dsn flag or DATABASE_DSN environment variable required")
|
|
||||||
}
|
|
||||||
|
|
||||||
dbcfg, err := mysql.ParseDSN(dsn)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if user := cfg.MySQL.User; len(user) > 0 {
|
|
||||||
dbcfg.User = user
|
|
||||||
}
|
|
||||||
|
|
||||||
if pass := cfg.MySQL.Pass; len(pass) > 0 {
|
|
||||||
dbcfg.Passwd = pass
|
|
||||||
}
|
|
||||||
|
|
||||||
return mysql.NewConnector(dbcfg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package ntpdb
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql/driver"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
// from https://github.com/Boostport/dynamic-database-config
|
|
||||||
|
|
||||||
type CreateConnectorFunc func() (driver.Connector, error)
|
|
||||||
|
|
||||||
type Driver struct {
|
|
||||||
CreateConnectorFunc CreateConnectorFunc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Driver) Driver() driver.Driver {
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Driver) Connect(ctx context.Context) (driver.Conn, error) {
|
|
||||||
connector, err := d.CreateConnectorFunc()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error creating connector from function: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return connector.Connect(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Driver) Open(name string) (driver.Conn, error) {
|
|
||||||
return nil, errors.New("open is not supported")
|
|
||||||
}
|
|
||||||
@@ -5,11 +5,10 @@
|
|||||||
package ntpdb
|
package ntpdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"go.ntppool.org/common/types"
|
"go.ntppool.org/common/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -271,73 +270,73 @@ func (ns NullZoneServerCountsIpVersion) Value() (driver.Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LogScore struct {
|
type LogScore struct {
|
||||||
ID uint64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
MonitorID sql.NullInt32 `db:"monitor_id" json:"monitor_id"`
|
MonitorID pgtype.Int8 `db:"monitor_id" json:"monitor_id"`
|
||||||
ServerID uint32 `db:"server_id" json:"server_id"`
|
ServerID int64 `db:"server_id" json:"server_id"`
|
||||||
Ts time.Time `db:"ts" json:"ts"`
|
Ts pgtype.Timestamptz `db:"ts" json:"ts"`
|
||||||
Score float64 `db:"score" json:"score"`
|
Score float64 `db:"score" json:"score"`
|
||||||
Step float64 `db:"step" json:"step"`
|
Step float64 `db:"step" json:"step"`
|
||||||
Offset sql.NullFloat64 `db:"offset" json:"offset"`
|
Offset pgtype.Float8 `db:"offset" json:"offset"`
|
||||||
Rtt sql.NullInt32 `db:"rtt" json:"rtt"`
|
Rtt pgtype.Int4 `db:"rtt" json:"rtt"`
|
||||||
Attributes types.LogScoreAttributes `db:"attributes" json:"attributes"`
|
Attributes types.LogScoreAttributes `db:"attributes" json:"attributes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
ID uint32 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
IDToken sql.NullString `db:"id_token" json:"id_token"`
|
IDToken pgtype.Text `db:"id_token" json:"id_token"`
|
||||||
Type MonitorsType `db:"type" json:"type"`
|
Type MonitorsType `db:"type" json:"type"`
|
||||||
UserID sql.NullInt32 `db:"user_id" json:"user_id"`
|
UserID pgtype.Int8 `db:"user_id" json:"user_id"`
|
||||||
AccountID sql.NullInt32 `db:"account_id" json:"account_id"`
|
AccountID pgtype.Int8 `db:"account_id" json:"account_id"`
|
||||||
Hostname string `db:"hostname" json:"hostname"`
|
Hostname string `db:"hostname" json:"hostname"`
|
||||||
Location string `db:"location" json:"location"`
|
Location string `db:"location" json:"location"`
|
||||||
Ip sql.NullString `db:"ip" json:"ip"`
|
Ip pgtype.Text `db:"ip" json:"ip"`
|
||||||
IpVersion NullMonitorsIpVersion `db:"ip_version" json:"ip_version"`
|
IpVersion NullMonitorsIpVersion `db:"ip_version" json:"ip_version"`
|
||||||
TlsName sql.NullString `db:"tls_name" json:"tls_name"`
|
TlsName pgtype.Text `db:"tls_name" json:"tls_name"`
|
||||||
ApiKey sql.NullString `db:"api_key" json:"api_key"`
|
ApiKey pgtype.Text `db:"api_key" json:"api_key"`
|
||||||
Status MonitorsStatus `db:"status" json:"status"`
|
Status MonitorsStatus `db:"status" json:"status"`
|
||||||
Config string `db:"config" json:"config"`
|
Config string `db:"config" json:"config"`
|
||||||
ClientVersion string `db:"client_version" json:"client_version"`
|
ClientVersion string `db:"client_version" json:"client_version"`
|
||||||
LastSeen sql.NullTime `db:"last_seen" json:"last_seen"`
|
LastSeen pgtype.Timestamptz `db:"last_seen" json:"last_seen"`
|
||||||
LastSubmit sql.NullTime `db:"last_submit" json:"last_submit"`
|
LastSubmit pgtype.Timestamptz `db:"last_submit" json:"last_submit"`
|
||||||
CreatedOn time.Time `db:"created_on" json:"created_on"`
|
CreatedOn pgtype.Timestamptz `db:"created_on" json:"created_on"`
|
||||||
DeletedOn sql.NullTime `db:"deleted_on" json:"deleted_on"`
|
DeletedOn pgtype.Timestamptz `db:"deleted_on" json:"deleted_on"`
|
||||||
IsCurrent sql.NullBool `db:"is_current" json:"is_current"`
|
IsCurrent pgtype.Bool `db:"is_current" json:"is_current"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
ID uint32 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
Ip string `db:"ip" json:"ip"`
|
Ip string `db:"ip" json:"ip"`
|
||||||
IpVersion ServersIpVersion `db:"ip_version" json:"ip_version"`
|
IpVersion ServersIpVersion `db:"ip_version" json:"ip_version"`
|
||||||
UserID sql.NullInt32 `db:"user_id" json:"user_id"`
|
UserID pgtype.Int8 `db:"user_id" json:"user_id"`
|
||||||
AccountID sql.NullInt32 `db:"account_id" json:"account_id"`
|
AccountID pgtype.Int8 `db:"account_id" json:"account_id"`
|
||||||
Hostname sql.NullString `db:"hostname" json:"hostname"`
|
Hostname pgtype.Text `db:"hostname" json:"hostname"`
|
||||||
Stratum sql.NullInt16 `db:"stratum" json:"stratum"`
|
Stratum pgtype.Int2 `db:"stratum" json:"stratum"`
|
||||||
InPool uint8 `db:"in_pool" json:"in_pool"`
|
InPool int16 `db:"in_pool" json:"in_pool"`
|
||||||
InServerList uint8 `db:"in_server_list" json:"in_server_list"`
|
InServerList int16 `db:"in_server_list" json:"in_server_list"`
|
||||||
Netspeed uint32 `db:"netspeed" json:"netspeed"`
|
Netspeed int64 `db:"netspeed" json:"netspeed"`
|
||||||
NetspeedTarget uint32 `db:"netspeed_target" json:"netspeed_target"`
|
NetspeedTarget int64 `db:"netspeed_target" json:"netspeed_target"`
|
||||||
CreatedOn time.Time `db:"created_on" json:"created_on"`
|
CreatedOn pgtype.Timestamptz `db:"created_on" json:"created_on"`
|
||||||
UpdatedOn time.Time `db:"updated_on" json:"updated_on"`
|
UpdatedOn pgtype.Timestamptz `db:"updated_on" json:"updated_on"`
|
||||||
ScoreTs sql.NullTime `db:"score_ts" json:"score_ts"`
|
ScoreTs pgtype.Timestamptz `db:"score_ts" json:"score_ts"`
|
||||||
ScoreRaw float64 `db:"score_raw" json:"score_raw"`
|
ScoreRaw float64 `db:"score_raw" json:"score_raw"`
|
||||||
DeletionOn sql.NullTime `db:"deletion_on" json:"deletion_on"`
|
DeletionOn pgtype.Date `db:"deletion_on" json:"deletion_on"`
|
||||||
Flags string `db:"flags" json:"flags"`
|
Flags string `db:"flags" json:"flags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Zone struct {
|
type Zone struct {
|
||||||
ID uint32 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
Name string `db:"name" json:"name"`
|
Name string `db:"name" json:"name"`
|
||||||
Description sql.NullString `db:"description" json:"description"`
|
Description pgtype.Text `db:"description" json:"description"`
|
||||||
ParentID sql.NullInt32 `db:"parent_id" json:"parent_id"`
|
ParentID pgtype.Int8 `db:"parent_id" json:"parent_id"`
|
||||||
Dns bool `db:"dns" json:"dns"`
|
Dns bool `db:"dns" json:"dns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ZoneServerCount struct {
|
type ZoneServerCount struct {
|
||||||
ID uint32 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
ZoneID uint32 `db:"zone_id" json:"zone_id"`
|
ZoneID int64 `db:"zone_id" json:"zone_id"`
|
||||||
IpVersion ZoneServerCountsIpVersion `db:"ip_version" json:"ip_version"`
|
IpVersion ZoneServerCountsIpVersion `db:"ip_version" json:"ip_version"`
|
||||||
Date time.Time `db:"date" json:"date"`
|
Date pgtype.Date `db:"date" json:"date"`
|
||||||
CountActive uint32 `db:"count_active" json:"count_active"`
|
CountActive int32 `db:"count_active" json:"count_active"`
|
||||||
CountRegistered uint32 `db:"count_registered" json:"count_registered"`
|
CountRegistered int32 `db:"count_registered" json:"count_registered"`
|
||||||
NetspeedActive int `db:"netspeed_active" json:"netspeed_active"`
|
NetspeedActive int `db:"netspeed_active" json:"netspeed_active"`
|
||||||
}
|
}
|
||||||
|
|||||||
55
ntpdb/opentelemetry.gowrap
Normal file
55
ntpdb/opentelemetry.gowrap
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
_codes "go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel"
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
)
|
||||||
|
|
||||||
|
{{ $decorator := (or .Vars.DecoratorName (printf "%sWithTracing" .Interface.Name)) }}
|
||||||
|
{{ $spanNameType := (or .Vars.SpanNamePrefix .Interface.Name) }}
|
||||||
|
|
||||||
|
// {{$decorator}} implements {{.Interface.Name}} interface instrumented with open telemetry spans
|
||||||
|
type {{$decorator}} struct {
|
||||||
|
{{.Interface.Type}}
|
||||||
|
_instance string
|
||||||
|
_spanDecorator func(span trace.Span, params, results map[string]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// New{{$decorator}} returns {{$decorator}}
|
||||||
|
func New{{$decorator}} (base {{.Interface.Type}}, instance string, spanDecorator ...func(span trace.Span, params, results map[string]interface{})) {{$decorator}} {
|
||||||
|
d := {{$decorator}} {
|
||||||
|
{{.Interface.Name}}: base,
|
||||||
|
_instance: instance,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(spanDecorator) > 0 && spanDecorator[0] != nil {
|
||||||
|
d._spanDecorator = spanDecorator[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
{{range $method := .Interface.Methods}}
|
||||||
|
{{if $method.AcceptsContext}}
|
||||||
|
// {{$method.Name}} implements {{$.Interface.Name}}
|
||||||
|
func (_d {{$decorator}}) {{$method.Declaration}} {
|
||||||
|
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "{{$spanNameType}}.{{$method.Name}}")
|
||||||
|
defer func() {
|
||||||
|
if _d._spanDecorator != nil {
|
||||||
|
_d._spanDecorator(_span, {{$method.ParamsMap}}, {{$method.ResultsMap}})
|
||||||
|
}{{- if $method.ReturnsError}} else if err != nil {
|
||||||
|
_span.RecordError(err)
|
||||||
|
_span.SetStatus(_codes.Error, err.Error())
|
||||||
|
_span.SetAttributes(
|
||||||
|
attribute.String("event", "error"),
|
||||||
|
attribute.String("message", err.Error()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
_span.End()
|
||||||
|
}()
|
||||||
|
{{$method.Pass (printf "_d.%s." $.Interface.Name) }}
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// Code generated by gowrap. DO NOT EDIT.
|
// Code generated by gowrap. DO NOT EDIT.
|
||||||
// template: https://raw.githubusercontent.com/hexdigest/gowrap/6bd1bc023b4d2a619f30020924f258b8ff665a7a/templates/opentelemetry
|
// template: opentelemetry.gowrap
|
||||||
// gowrap: http://github.com/hexdigest/gowrap
|
// gowrap: http://github.com/hexdigest/gowrap
|
||||||
|
|
||||||
package ntpdb
|
package ntpdb
|
||||||
@@ -7,10 +7,11 @@ package ntpdb
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
_codes "go.opentelemetry.io/otel/codes"
|
_codes "go.opentelemetry.io/otel/codes"
|
||||||
"go.opentelemetry.io/otel/trace"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// QuerierTxWithTracing implements QuerierTx interface instrumented with open telemetry spans
|
// QuerierTxWithTracing implements QuerierTx interface instrumented with open telemetry spans
|
||||||
@@ -104,7 +105,7 @@ func (_d QuerierTxWithTracing) GetMonitorByNameAndIPVersion(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetMonitorsByID implements QuerierTx
|
// GetMonitorsByID implements QuerierTx
|
||||||
func (_d QuerierTxWithTracing) GetMonitorsByID(ctx context.Context, monitorids []uint32) (ma1 []Monitor, err error) {
|
func (_d QuerierTxWithTracing) GetMonitorsByID(ctx context.Context, monitorids []int64) (ma1 []Monitor, err error) {
|
||||||
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetMonitorsByID")
|
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetMonitorsByID")
|
||||||
defer func() {
|
defer func() {
|
||||||
if _d._spanDecorator != nil {
|
if _d._spanDecorator != nil {
|
||||||
@@ -128,7 +129,7 @@ func (_d QuerierTxWithTracing) GetMonitorsByID(ctx context.Context, monitorids [
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetServerByID implements QuerierTx
|
// GetServerByID implements QuerierTx
|
||||||
func (_d QuerierTxWithTracing) GetServerByID(ctx context.Context, id uint32) (s1 Server, err error) {
|
func (_d QuerierTxWithTracing) GetServerByID(ctx context.Context, id int64) (s1 Server, err error) {
|
||||||
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetServerByID")
|
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetServerByID")
|
||||||
defer func() {
|
defer func() {
|
||||||
if _d._spanDecorator != nil {
|
if _d._spanDecorator != nil {
|
||||||
@@ -224,14 +225,14 @@ func (_d QuerierTxWithTracing) GetServerLogScoresByMonitorID(ctx context.Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetServerNetspeed implements QuerierTx
|
// GetServerNetspeed implements QuerierTx
|
||||||
func (_d QuerierTxWithTracing) GetServerNetspeed(ctx context.Context, ip string) (u1 uint32, err error) {
|
func (_d QuerierTxWithTracing) GetServerNetspeed(ctx context.Context, ip string) (i1 int64, err error) {
|
||||||
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetServerNetspeed")
|
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetServerNetspeed")
|
||||||
defer func() {
|
defer func() {
|
||||||
if _d._spanDecorator != nil {
|
if _d._spanDecorator != nil {
|
||||||
_d._spanDecorator(_span, map[string]interface{}{
|
_d._spanDecorator(_span, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
"ip": ip}, map[string]interface{}{
|
"ip": ip}, map[string]interface{}{
|
||||||
"u1": u1,
|
"i1": i1,
|
||||||
"err": err})
|
"err": err})
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
_span.RecordError(err)
|
_span.RecordError(err)
|
||||||
@@ -296,7 +297,7 @@ func (_d QuerierTxWithTracing) GetZoneByName(ctx context.Context, name string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetZoneCounts implements QuerierTx
|
// GetZoneCounts implements QuerierTx
|
||||||
func (_d QuerierTxWithTracing) GetZoneCounts(ctx context.Context, zoneID uint32) (za1 []ZoneServerCount, err error) {
|
func (_d QuerierTxWithTracing) GetZoneCounts(ctx context.Context, zoneID int64) (za1 []ZoneServerCount, err error) {
|
||||||
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetZoneCounts")
|
ctx, _span := otel.Tracer(_d._instance).Start(ctx, "QuerierTx.GetZoneCounts")
|
||||||
defer func() {
|
defer func() {
|
||||||
if _d._spanDecorator != nil {
|
if _d._spanDecorator != nil {
|
||||||
|
|||||||
@@ -10,15 +10,15 @@ import (
|
|||||||
|
|
||||||
type Querier interface {
|
type Querier interface {
|
||||||
GetMonitorByNameAndIPVersion(ctx context.Context, arg GetMonitorByNameAndIPVersionParams) (Monitor, error)
|
GetMonitorByNameAndIPVersion(ctx context.Context, arg GetMonitorByNameAndIPVersionParams) (Monitor, error)
|
||||||
GetMonitorsByID(ctx context.Context, monitorids []uint32) ([]Monitor, error)
|
GetMonitorsByID(ctx context.Context, monitorids []int64) ([]Monitor, error)
|
||||||
GetServerByID(ctx context.Context, id uint32) (Server, error)
|
GetServerByID(ctx context.Context, id int64) (Server, error)
|
||||||
GetServerByIP(ctx context.Context, ip string) (Server, error)
|
GetServerByIP(ctx context.Context, ip string) (Server, error)
|
||||||
GetServerLogScores(ctx context.Context, arg GetServerLogScoresParams) ([]LogScore, error)
|
GetServerLogScores(ctx context.Context, arg GetServerLogScoresParams) ([]LogScore, error)
|
||||||
GetServerLogScoresByMonitorID(ctx context.Context, arg GetServerLogScoresByMonitorIDParams) ([]LogScore, error)
|
GetServerLogScoresByMonitorID(ctx context.Context, arg GetServerLogScoresByMonitorIDParams) ([]LogScore, error)
|
||||||
GetServerNetspeed(ctx context.Context, ip string) (uint32, error)
|
GetServerNetspeed(ctx context.Context, ip string) (int64, error)
|
||||||
GetServerScores(ctx context.Context, arg GetServerScoresParams) ([]GetServerScoresRow, error)
|
GetServerScores(ctx context.Context, arg GetServerScoresParams) ([]GetServerScoresRow, error)
|
||||||
GetZoneByName(ctx context.Context, name string) (Zone, error)
|
GetZoneByName(ctx context.Context, name string) (Zone, error)
|
||||||
GetZoneCounts(ctx context.Context, zoneID uint32) ([]ZoneServerCount, error)
|
GetZoneCounts(ctx context.Context, zoneID int64) ([]ZoneServerCount, error)
|
||||||
GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow, error)
|
GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow, error)
|
||||||
GetZoneStatsV2(ctx context.Context, ip string) ([]GetZoneStatsV2Row, error)
|
GetZoneStatsV2(ctx context.Context, ip string) ([]GetZoneStatsV2Row, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,28 +7,27 @@ package ntpdb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"strings"
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const getMonitorByNameAndIPVersion = `-- name: GetMonitorByNameAndIPVersion :one
|
const getMonitorByNameAndIPVersion = `-- name: GetMonitorByNameAndIPVersion :one
|
||||||
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
|
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
|
where
|
||||||
tls_name like ? AND
|
tls_name like $1 AND
|
||||||
(ip_version = ? OR (type = 'score' AND ip_version IS NULL)) AND
|
(ip_version = $2 OR (type = 'score' AND ip_version IS NULL)) AND
|
||||||
is_current = 1
|
is_current = true
|
||||||
order by id
|
order by id
|
||||||
limit 1
|
limit 1
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetMonitorByNameAndIPVersionParams struct {
|
type GetMonitorByNameAndIPVersionParams struct {
|
||||||
TlsName sql.NullString `db:"tls_name" json:"tls_name"`
|
TlsName pgtype.Text `db:"tls_name" json:"tls_name"`
|
||||||
IpVersion NullMonitorsIpVersion `db:"ip_version" json:"ip_version"`
|
IpVersion NullMonitorsIpVersion `db:"ip_version" json:"ip_version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetMonitorByNameAndIPVersion(ctx context.Context, arg GetMonitorByNameAndIPVersionParams) (Monitor, error) {
|
func (q *Queries) GetMonitorByNameAndIPVersion(ctx context.Context, arg GetMonitorByNameAndIPVersionParams) (Monitor, error) {
|
||||||
row := q.db.QueryRowContext(ctx, getMonitorByNameAndIPVersion, arg.TlsName, arg.IpVersion)
|
row := q.db.QueryRow(ctx, getMonitorByNameAndIPVersion, arg.TlsName, arg.IpVersion)
|
||||||
var i Monitor
|
var i Monitor
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
@@ -56,21 +55,11 @@ func (q *Queries) GetMonitorByNameAndIPVersion(ctx context.Context, arg GetMonit
|
|||||||
|
|
||||||
const getMonitorsByID = `-- name: GetMonitorsByID :many
|
const getMonitorsByID = `-- name: GetMonitorsByID :many
|
||||||
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
|
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*/?)
|
where id = ANY($1::bigint[])
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetMonitorsByID(ctx context.Context, monitorids []uint32) ([]Monitor, error) {
|
func (q *Queries) GetMonitorsByID(ctx context.Context, monitorids []int64) ([]Monitor, error) {
|
||||||
query := getMonitorsByID
|
rows, err := q.db.Query(ctx, getMonitorsByID, monitorids)
|
||||||
var queryParams []interface{}
|
|
||||||
if len(monitorids) > 0 {
|
|
||||||
for _, v := range monitorids {
|
|
||||||
queryParams = append(queryParams, v)
|
|
||||||
}
|
|
||||||
query = strings.Replace(query, "/*SLICE:MonitorIDs*/?", strings.Repeat(",?", len(monitorids))[1:], 1)
|
|
||||||
} else {
|
|
||||||
query = strings.Replace(query, "/*SLICE:MonitorIDs*/?", "NULL", 1)
|
|
||||||
}
|
|
||||||
rows, err := q.db.QueryContext(ctx, query, queryParams...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -103,9 +92,6 @@ func (q *Queries) GetMonitorsByID(ctx context.Context, monitorids []uint32) ([]M
|
|||||||
}
|
}
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -115,11 +101,11 @@ func (q *Queries) GetMonitorsByID(ctx context.Context, monitorids []uint32) ([]M
|
|||||||
const getServerByID = `-- name: GetServerByID :one
|
const getServerByID = `-- name: GetServerByID :one
|
||||||
select id, ip, ip_version, user_id, account_id, hostname, stratum, in_pool, in_server_list, netspeed, netspeed_target, created_on, updated_on, score_ts, score_raw, deletion_on, flags from servers
|
select id, ip, ip_version, user_id, account_id, hostname, stratum, in_pool, in_server_list, netspeed, netspeed_target, created_on, updated_on, score_ts, score_raw, deletion_on, flags from servers
|
||||||
where
|
where
|
||||||
id = ?
|
id = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetServerByID(ctx context.Context, id uint32) (Server, error) {
|
func (q *Queries) GetServerByID(ctx context.Context, id int64) (Server, error) {
|
||||||
row := q.db.QueryRowContext(ctx, getServerByID, id)
|
row := q.db.QueryRow(ctx, getServerByID, id)
|
||||||
var i Server
|
var i Server
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
@@ -146,11 +132,11 @@ func (q *Queries) GetServerByID(ctx context.Context, id uint32) (Server, error)
|
|||||||
const getServerByIP = `-- name: GetServerByIP :one
|
const getServerByIP = `-- name: GetServerByIP :one
|
||||||
select id, ip, ip_version, user_id, account_id, hostname, stratum, in_pool, in_server_list, netspeed, netspeed_target, created_on, updated_on, score_ts, score_raw, deletion_on, flags from servers
|
select id, ip, ip_version, user_id, account_id, hostname, stratum, in_pool, in_server_list, netspeed, netspeed_target, created_on, updated_on, score_ts, score_raw, deletion_on, flags from servers
|
||||||
where
|
where
|
||||||
ip = ?
|
ip = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetServerByIP(ctx context.Context, ip string) (Server, error) {
|
func (q *Queries) GetServerByIP(ctx context.Context, ip string) (Server, error) {
|
||||||
row := q.db.QueryRowContext(ctx, getServerByIP, ip)
|
row := q.db.QueryRow(ctx, getServerByIP, ip)
|
||||||
var i Server
|
var i Server
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
@@ -175,20 +161,20 @@ func (q *Queries) GetServerByIP(ctx context.Context, ip string) (Server, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getServerLogScores = `-- name: GetServerLogScores :many
|
const getServerLogScores = `-- name: GetServerLogScores :many
|
||||||
select id, monitor_id, server_id, ts, score, step, offset, rtt, attributes from log_scores
|
select id, monitor_id, server_id, ts, score, step, "offset", rtt, attributes from log_scores
|
||||||
where
|
where
|
||||||
server_id = ?
|
server_id = $1
|
||||||
order by ts desc
|
order by ts desc
|
||||||
limit ?
|
limit $2
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetServerLogScoresParams struct {
|
type GetServerLogScoresParams struct {
|
||||||
ServerID uint32 `db:"server_id" json:"server_id"`
|
ServerID int64 `db:"server_id" json:"server_id"`
|
||||||
Limit int32 `db:"limit" json:"limit"`
|
Limit int32 `db:"limit" json:"limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetServerLogScores(ctx context.Context, arg GetServerLogScoresParams) ([]LogScore, error) {
|
func (q *Queries) GetServerLogScores(ctx context.Context, arg GetServerLogScoresParams) ([]LogScore, error) {
|
||||||
rows, err := q.db.QueryContext(ctx, getServerLogScores, arg.ServerID, arg.Limit)
|
rows, err := q.db.Query(ctx, getServerLogScores, arg.ServerID, arg.Limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -211,9 +197,6 @@ func (q *Queries) GetServerLogScores(ctx context.Context, arg GetServerLogScores
|
|||||||
}
|
}
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -221,22 +204,22 @@ func (q *Queries) GetServerLogScores(ctx context.Context, arg GetServerLogScores
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getServerLogScoresByMonitorID = `-- name: GetServerLogScoresByMonitorID :many
|
const getServerLogScoresByMonitorID = `-- name: GetServerLogScoresByMonitorID :many
|
||||||
select id, monitor_id, server_id, ts, score, step, offset, rtt, attributes from log_scores
|
select id, monitor_id, server_id, ts, score, step, "offset", rtt, attributes from log_scores
|
||||||
where
|
where
|
||||||
server_id = ? AND
|
server_id = $1 AND
|
||||||
monitor_id = ?
|
monitor_id = $2
|
||||||
order by ts desc
|
order by ts desc
|
||||||
limit ?
|
limit $3
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetServerLogScoresByMonitorIDParams struct {
|
type GetServerLogScoresByMonitorIDParams struct {
|
||||||
ServerID uint32 `db:"server_id" json:"server_id"`
|
ServerID int64 `db:"server_id" json:"server_id"`
|
||||||
MonitorID sql.NullInt32 `db:"monitor_id" json:"monitor_id"`
|
MonitorID pgtype.Int8 `db:"monitor_id" json:"monitor_id"`
|
||||||
Limit int32 `db:"limit" json:"limit"`
|
Limit int32 `db:"limit" json:"limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetServerLogScoresByMonitorID(ctx context.Context, arg GetServerLogScoresByMonitorIDParams) ([]LogScore, error) {
|
func (q *Queries) GetServerLogScoresByMonitorID(ctx context.Context, arg GetServerLogScoresByMonitorIDParams) ([]LogScore, error) {
|
||||||
rows, err := q.db.QueryContext(ctx, getServerLogScoresByMonitorID, arg.ServerID, arg.MonitorID, arg.Limit)
|
rows, err := q.db.Query(ctx, getServerLogScoresByMonitorID, arg.ServerID, arg.MonitorID, arg.Limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -259,9 +242,6 @@ func (q *Queries) GetServerLogScoresByMonitorID(ctx context.Context, arg GetServ
|
|||||||
}
|
}
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -269,12 +249,12 @@ func (q *Queries) GetServerLogScoresByMonitorID(ctx context.Context, arg GetServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getServerNetspeed = `-- name: GetServerNetspeed :one
|
const getServerNetspeed = `-- name: GetServerNetspeed :one
|
||||||
select netspeed from servers where ip = ?
|
select netspeed from servers where ip = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetServerNetspeed(ctx context.Context, ip string) (uint32, error) {
|
func (q *Queries) GetServerNetspeed(ctx context.Context, ip string) (int64, error) {
|
||||||
row := q.db.QueryRowContext(ctx, getServerNetspeed, ip)
|
row := q.db.QueryRow(ctx, getServerNetspeed, ip)
|
||||||
var netspeed uint32
|
var netspeed int64
|
||||||
err := row.Scan(&netspeed)
|
err := row.Scan(&netspeed)
|
||||||
return netspeed, err
|
return netspeed, err
|
||||||
}
|
}
|
||||||
@@ -287,39 +267,28 @@ select
|
|||||||
inner join monitors m
|
inner join monitors m
|
||||||
on (m.id=ss.monitor_id)
|
on (m.id=ss.monitor_id)
|
||||||
where
|
where
|
||||||
server_id = ? AND
|
server_id = $1 AND
|
||||||
monitor_id in (/*SLICE:MonitorIDs*/?)
|
monitor_id = ANY($2::bigint[])
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetServerScoresParams struct {
|
type GetServerScoresParams struct {
|
||||||
ServerID uint32 `db:"server_id" json:"server_id"`
|
ServerID int64 `db:"server_id" json:"server_id"`
|
||||||
MonitorIDs []uint32 `db:"MonitorIDs" json:"MonitorIDs"`
|
MonitorIDs []int64 `db:"MonitorIDs" json:"MonitorIDs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetServerScoresRow struct {
|
type GetServerScoresRow struct {
|
||||||
ID uint32 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
Hostname string `db:"hostname" json:"hostname"`
|
Hostname string `db:"hostname" json:"hostname"`
|
||||||
TlsName sql.NullString `db:"tls_name" json:"tls_name"`
|
TlsName pgtype.Text `db:"tls_name" json:"tls_name"`
|
||||||
Location string `db:"location" json:"location"`
|
Location string `db:"location" json:"location"`
|
||||||
Type MonitorsType `db:"type" json:"type"`
|
Type MonitorsType `db:"type" json:"type"`
|
||||||
ScoreRaw float64 `db:"score_raw" json:"score_raw"`
|
ScoreRaw float64 `db:"score_raw" json:"score_raw"`
|
||||||
ScoreTs sql.NullTime `db:"score_ts" json:"score_ts"`
|
ScoreTs pgtype.Timestamptz `db:"score_ts" json:"score_ts"`
|
||||||
Status ServerScoresStatus `db:"status" json:"status"`
|
Status ServerScoresStatus `db:"status" json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetServerScores(ctx context.Context, arg GetServerScoresParams) ([]GetServerScoresRow, error) {
|
func (q *Queries) GetServerScores(ctx context.Context, arg GetServerScoresParams) ([]GetServerScoresRow, error) {
|
||||||
query := getServerScores
|
rows, err := q.db.Query(ctx, getServerScores, arg.ServerID, arg.MonitorIDs)
|
||||||
var queryParams []interface{}
|
|
||||||
queryParams = append(queryParams, arg.ServerID)
|
|
||||||
if len(arg.MonitorIDs) > 0 {
|
|
||||||
for _, v := range arg.MonitorIDs {
|
|
||||||
queryParams = append(queryParams, v)
|
|
||||||
}
|
|
||||||
query = strings.Replace(query, "/*SLICE:MonitorIDs*/?", strings.Repeat(",?", len(arg.MonitorIDs))[1:], 1)
|
|
||||||
} else {
|
|
||||||
query = strings.Replace(query, "/*SLICE:MonitorIDs*/?", "NULL", 1)
|
|
||||||
}
|
|
||||||
rows, err := q.db.QueryContext(ctx, query, queryParams...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -341,9 +310,6 @@ func (q *Queries) GetServerScores(ctx context.Context, arg GetServerScoresParams
|
|||||||
}
|
}
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -353,11 +319,11 @@ func (q *Queries) GetServerScores(ctx context.Context, arg GetServerScoresParams
|
|||||||
const getZoneByName = `-- name: GetZoneByName :one
|
const getZoneByName = `-- name: GetZoneByName :one
|
||||||
select id, name, description, parent_id, dns from zones
|
select id, name, description, parent_id, dns from zones
|
||||||
where
|
where
|
||||||
name = ?
|
name = $1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetZoneByName(ctx context.Context, name string) (Zone, error) {
|
func (q *Queries) GetZoneByName(ctx context.Context, name string) (Zone, error) {
|
||||||
row := q.db.QueryRowContext(ctx, getZoneByName, name)
|
row := q.db.QueryRow(ctx, getZoneByName, name)
|
||||||
var i Zone
|
var i Zone
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
&i.ID,
|
&i.ID,
|
||||||
@@ -371,12 +337,12 @@ func (q *Queries) GetZoneByName(ctx context.Context, name string) (Zone, error)
|
|||||||
|
|
||||||
const getZoneCounts = `-- name: GetZoneCounts :many
|
const getZoneCounts = `-- name: GetZoneCounts :many
|
||||||
select id, zone_id, ip_version, date, count_active, count_registered, netspeed_active from zone_server_counts
|
select id, zone_id, ip_version, date, count_active, count_registered, netspeed_active from zone_server_counts
|
||||||
where zone_id = ?
|
where zone_id = $1
|
||||||
order by date
|
order by date
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetZoneCounts(ctx context.Context, zoneID uint32) ([]ZoneServerCount, error) {
|
func (q *Queries) GetZoneCounts(ctx context.Context, zoneID int64) ([]ZoneServerCount, error) {
|
||||||
rows, err := q.db.QueryContext(ctx, getZoneCounts, zoneID)
|
rows, err := q.db.Query(ctx, getZoneCounts, zoneID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -397,9 +363,6 @@ func (q *Queries) GetZoneCounts(ctx context.Context, zoneID uint32) ([]ZoneServe
|
|||||||
}
|
}
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -408,7 +371,7 @@ func (q *Queries) GetZoneCounts(ctx context.Context, zoneID uint32) ([]ZoneServe
|
|||||||
|
|
||||||
const getZoneStatsData = `-- name: GetZoneStatsData :many
|
const getZoneStatsData = `-- name: GetZoneStatsData :many
|
||||||
SELECT zc.date, z.name, zc.ip_version, count_active, count_registered, netspeed_active
|
SELECT zc.date, z.name, zc.ip_version, count_active, count_registered, netspeed_active
|
||||||
FROM zone_server_counts zc USE INDEX (date_idx)
|
FROM zone_server_counts zc
|
||||||
INNER JOIN zones z
|
INNER JOIN zones z
|
||||||
ON(zc.zone_id=z.id)
|
ON(zc.zone_id=z.id)
|
||||||
WHERE date IN (SELECT max(date) from zone_server_counts)
|
WHERE date IN (SELECT max(date) from zone_server_counts)
|
||||||
@@ -416,16 +379,16 @@ ORDER BY name
|
|||||||
`
|
`
|
||||||
|
|
||||||
type GetZoneStatsDataRow struct {
|
type GetZoneStatsDataRow struct {
|
||||||
Date time.Time `db:"date" json:"date"`
|
Date pgtype.Date `db:"date" json:"date"`
|
||||||
Name string `db:"name" json:"name"`
|
Name string `db:"name" json:"name"`
|
||||||
IpVersion ZoneServerCountsIpVersion `db:"ip_version" json:"ip_version"`
|
IpVersion ZoneServerCountsIpVersion `db:"ip_version" json:"ip_version"`
|
||||||
CountActive uint32 `db:"count_active" json:"count_active"`
|
CountActive int32 `db:"count_active" json:"count_active"`
|
||||||
CountRegistered uint32 `db:"count_registered" json:"count_registered"`
|
CountRegistered int32 `db:"count_registered" json:"count_registered"`
|
||||||
NetspeedActive int `db:"netspeed_active" json:"netspeed_active"`
|
NetspeedActive int `db:"netspeed_active" json:"netspeed_active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow, error) {
|
func (q *Queries) GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow, error) {
|
||||||
rows, err := q.db.QueryContext(ctx, getZoneStatsData)
|
rows, err := q.db.Query(ctx, getZoneStatsData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -445,9 +408,6 @@ func (q *Queries) GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow,
|
|||||||
}
|
}
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -455,15 +415,14 @@ func (q *Queries) GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getZoneStatsV2 = `-- name: GetZoneStatsV2 :many
|
const getZoneStatsV2 = `-- name: GetZoneStatsV2 :many
|
||||||
select zone_name, netspeed_active+0 as netspeed_active FROM (
|
|
||||||
SELECT
|
SELECT
|
||||||
z.name as zone_name,
|
z.name as zone_name,
|
||||||
SUM(
|
CAST(SUM(
|
||||||
IF (deletion_on IS NULL AND score_raw > 10,
|
CASE WHEN deletion_on IS NULL AND score_raw > 10
|
||||||
netspeed,
|
THEN netspeed
|
||||||
0
|
ELSE 0
|
||||||
)
|
END
|
||||||
) AS netspeed_active
|
) AS int) AS netspeed_active
|
||||||
FROM
|
FROM
|
||||||
servers s
|
servers s
|
||||||
INNER JOIN server_zones sz ON (sz.server_id = s.id)
|
INNER JOIN server_zones sz ON (sz.server_id = s.id)
|
||||||
@@ -472,23 +431,22 @@ FROM
|
|||||||
select zone_id, s.ip_version
|
select zone_id, s.ip_version
|
||||||
from server_zones sz
|
from server_zones sz
|
||||||
inner join servers s on (s.id=sz.server_id)
|
inner join servers s on (s.id=sz.server_id)
|
||||||
where s.ip=?
|
where s.ip=$1
|
||||||
) as srvz on (srvz.zone_id=z.id AND srvz.ip_version=s.ip_version)
|
) as srvz on (srvz.zone_id=z.id AND srvz.ip_version=s.ip_version)
|
||||||
WHERE
|
WHERE
|
||||||
(deletion_on IS NULL OR deletion_on > NOW())
|
(deletion_on IS NULL OR deletion_on > NOW())
|
||||||
AND in_pool = 1
|
AND in_pool = 1
|
||||||
AND netspeed > 0
|
AND netspeed > 0
|
||||||
GROUP BY z.name)
|
GROUP BY z.name
|
||||||
AS server_netspeed
|
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetZoneStatsV2Row struct {
|
type GetZoneStatsV2Row struct {
|
||||||
ZoneName string `db:"zone_name" json:"zone_name"`
|
ZoneName string `db:"zone_name" json:"zone_name"`
|
||||||
NetspeedActive int `db:"netspeed_active" json:"netspeed_active"`
|
NetspeedActive int32 `db:"netspeed_active" json:"netspeed_active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetZoneStatsV2(ctx context.Context, ip string) ([]GetZoneStatsV2Row, error) {
|
func (q *Queries) GetZoneStatsV2(ctx context.Context, ip string) ([]GetZoneStatsV2Row, error) {
|
||||||
rows, err := q.db.QueryContext(ctx, getZoneStatsV2, ip)
|
rows, err := q.db.Query(ctx, getZoneStatsV2, ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -501,9 +459,6 @@ func (q *Queries) GetZoneStatsV2(ctx context.Context, ip string) ([]GetZoneStats
|
|||||||
}
|
}
|
||||||
items = append(items, i)
|
items = append(items, i)
|
||||||
}
|
}
|
||||||
if err := rows.Close(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
69
ntpdb/tx.go
69
ntpdb/tx.go
@@ -2,7 +2,11 @@ package ntpdb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"go.ntppool.org/common/logger"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
type QuerierTx interface {
|
type QuerierTx interface {
|
||||||
@@ -11,14 +15,17 @@ type QuerierTx interface {
|
|||||||
Begin(ctx context.Context) (QuerierTx, error)
|
Begin(ctx context.Context) (QuerierTx, error)
|
||||||
Commit(ctx context.Context) error
|
Commit(ctx context.Context) error
|
||||||
Rollback(ctx context.Context) error
|
Rollback(ctx context.Context) error
|
||||||
|
|
||||||
|
// Conn returns the connection used by this transaction
|
||||||
|
Conn() *pgx.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
type Beginner interface {
|
type Beginner interface {
|
||||||
Begin(context.Context) (sql.Tx, error)
|
Begin(context.Context) (pgx.Tx, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tx interface {
|
type Tx interface {
|
||||||
Begin(context.Context) (sql.Tx, error)
|
Begin(context.Context) (pgx.Tx, error)
|
||||||
Commit(ctx context.Context) error
|
Commit(ctx context.Context) error
|
||||||
Rollback(ctx context.Context) error
|
Rollback(ctx context.Context) error
|
||||||
}
|
}
|
||||||
@@ -28,21 +35,33 @@ func (q *Queries) Begin(ctx context.Context) (QuerierTx, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Queries{db: &tx}, nil
|
return &Queries{db: tx}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) Commit(ctx context.Context) error {
|
func (q *Queries) Commit(ctx context.Context) error {
|
||||||
tx, ok := q.db.(Tx)
|
tx, ok := q.db.(Tx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return sql.ErrTxDone
|
// Commit called on Queries with dbpool, so treat as transaction already committed
|
||||||
|
return pgx.ErrTxClosed
|
||||||
}
|
}
|
||||||
return tx.Commit(ctx)
|
return tx.Commit(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *Queries) Conn() *pgx.Conn {
|
||||||
|
// pgx.Tx is an interface that has Conn() method
|
||||||
|
tx, ok := q.db.(pgx.Tx)
|
||||||
|
if !ok {
|
||||||
|
logger.Setup().Error("could not get connection from QuerierTx")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return tx.Conn()
|
||||||
|
}
|
||||||
|
|
||||||
func (q *Queries) Rollback(ctx context.Context) error {
|
func (q *Queries) Rollback(ctx context.Context) error {
|
||||||
tx, ok := q.db.(Tx)
|
tx, ok := q.db.(Tx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return sql.ErrTxDone
|
// Rollback called on Queries with dbpool, so treat as transaction already committed
|
||||||
|
return pgx.ErrTxClosed
|
||||||
}
|
}
|
||||||
return tx.Rollback(ctx)
|
return tx.Rollback(ctx)
|
||||||
}
|
}
|
||||||
@@ -62,3 +81,41 @@ func (wq *WrappedQuerier) Begin(ctx context.Context) (QuerierTx, error) {
|
|||||||
}
|
}
|
||||||
return NewWrappedQuerier(q), nil
|
return NewWrappedQuerier(q), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (wq *WrappedQuerier) Conn() *pgx.Conn {
|
||||||
|
return wq.QuerierTxWithTracing.Conn()
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogRollback logs and performs a rollback if the transaction is still active
|
||||||
|
func LogRollback(ctx context.Context, tx QuerierTx) {
|
||||||
|
if !isInTransaction(tx) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log := logger.FromContext(ctx)
|
||||||
|
log.WarnContext(ctx, "transaction rollback called on an active transaction")
|
||||||
|
|
||||||
|
// if caller ctx is done we still need rollback to happen
|
||||||
|
// so Rollback gets a fresh context with span copied over
|
||||||
|
rbCtx := context.Background()
|
||||||
|
if span := trace.SpanFromContext(ctx); span != nil {
|
||||||
|
rbCtx = trace.ContextWithSpan(rbCtx, span)
|
||||||
|
}
|
||||||
|
if err := tx.Rollback(rbCtx); err != nil && !errors.Is(err, pgx.ErrTxClosed) {
|
||||||
|
log.ErrorContext(ctx, "rollback failed", "err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isInTransaction(tx QuerierTx) bool {
|
||||||
|
if tx == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := tx.Conn()
|
||||||
|
if conn == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 'I' means idle, so if it's not idle, we're in a transaction
|
||||||
|
return conn.PgConn().TxStatus() != 'I'
|
||||||
|
}
|
||||||
|
|||||||
44
query.sql
44
query.sql
@@ -1,6 +1,6 @@
|
|||||||
-- name: GetZoneStatsData :many
|
-- name: GetZoneStatsData :many
|
||||||
SELECT zc.date, z.name, zc.ip_version, count_active, count_registered, netspeed_active
|
SELECT zc.date, z.name, zc.ip_version, count_active, count_registered, netspeed_active
|
||||||
FROM zone_server_counts zc USE INDEX (date_idx)
|
FROM zone_server_counts zc
|
||||||
INNER JOIN zones z
|
INNER JOIN zones z
|
||||||
ON(zc.zone_id=z.id)
|
ON(zc.zone_id=z.id)
|
||||||
WHERE date IN (SELECT max(date) from zone_server_counts)
|
WHERE date IN (SELECT max(date) from zone_server_counts)
|
||||||
@@ -8,18 +8,17 @@ ORDER BY name;
|
|||||||
|
|
||||||
|
|
||||||
-- name: GetServerNetspeed :one
|
-- name: GetServerNetspeed :one
|
||||||
select netspeed from servers where ip = ?;
|
select netspeed from servers where ip = $1;
|
||||||
|
|
||||||
-- name: GetZoneStatsV2 :many
|
-- name: GetZoneStatsV2 :many
|
||||||
select zone_name, netspeed_active+0 as netspeed_active FROM (
|
|
||||||
SELECT
|
SELECT
|
||||||
z.name as zone_name,
|
z.name as zone_name,
|
||||||
SUM(
|
CAST(SUM(
|
||||||
IF (deletion_on IS NULL AND score_raw > 10,
|
CASE WHEN deletion_on IS NULL AND score_raw > 10
|
||||||
netspeed,
|
THEN netspeed
|
||||||
0
|
ELSE 0
|
||||||
)
|
END
|
||||||
) AS netspeed_active
|
) AS int) AS netspeed_active
|
||||||
FROM
|
FROM
|
||||||
servers s
|
servers s
|
||||||
INNER JOIN server_zones sz ON (sz.server_id = s.id)
|
INNER JOIN server_zones sz ON (sz.server_id = s.id)
|
||||||
@@ -28,19 +27,18 @@ FROM
|
|||||||
select zone_id, s.ip_version
|
select zone_id, s.ip_version
|
||||||
from server_zones sz
|
from server_zones sz
|
||||||
inner join servers s on (s.id=sz.server_id)
|
inner join servers s on (s.id=sz.server_id)
|
||||||
where s.ip=?
|
where s.ip=$1
|
||||||
) as srvz on (srvz.zone_id=z.id AND srvz.ip_version=s.ip_version)
|
) as srvz on (srvz.zone_id=z.id AND srvz.ip_version=s.ip_version)
|
||||||
WHERE
|
WHERE
|
||||||
(deletion_on IS NULL OR deletion_on > NOW())
|
(deletion_on IS NULL OR deletion_on > NOW())
|
||||||
AND in_pool = 1
|
AND in_pool = 1
|
||||||
AND netspeed > 0
|
AND netspeed > 0
|
||||||
GROUP BY z.name)
|
GROUP BY z.name;
|
||||||
AS server_netspeed;
|
|
||||||
|
|
||||||
-- name: GetServerByID :one
|
-- name: GetServerByID :one
|
||||||
select * from servers
|
select * from servers
|
||||||
where
|
where
|
||||||
id = ?;
|
id = $1;
|
||||||
|
|
||||||
-- name: GetServerByIP :one
|
-- name: GetServerByIP :one
|
||||||
select * from servers
|
select * from servers
|
||||||
@@ -52,13 +50,13 @@ select * from monitors
|
|||||||
where
|
where
|
||||||
tls_name like sqlc.arg('tls_name') AND
|
tls_name like sqlc.arg('tls_name') AND
|
||||||
(ip_version = sqlc.arg('ip_version') OR (type = 'score' AND ip_version IS NULL)) AND
|
(ip_version = sqlc.arg('ip_version') OR (type = 'score' AND ip_version IS NULL)) AND
|
||||||
is_current = 1
|
is_current = true
|
||||||
order by id
|
order by id
|
||||||
limit 1;
|
limit 1;
|
||||||
|
|
||||||
-- name: GetMonitorsByID :many
|
-- name: GetMonitorsByID :many
|
||||||
select * from monitors
|
select * from monitors
|
||||||
where id in (sqlc.slice('MonitorIDs'));
|
where id = ANY(sqlc.arg('MonitorIDs')::bigint[]);
|
||||||
|
|
||||||
-- name: GetServerScores :many
|
-- name: GetServerScores :many
|
||||||
select
|
select
|
||||||
@@ -68,23 +66,23 @@ select
|
|||||||
inner join monitors m
|
inner join monitors m
|
||||||
on (m.id=ss.monitor_id)
|
on (m.id=ss.monitor_id)
|
||||||
where
|
where
|
||||||
server_id = ? AND
|
server_id = $1 AND
|
||||||
monitor_id in (sqlc.slice('MonitorIDs'));
|
monitor_id = ANY(sqlc.arg('MonitorIDs')::bigint[]);
|
||||||
|
|
||||||
-- name: GetServerLogScores :many
|
-- name: GetServerLogScores :many
|
||||||
select * from log_scores
|
select * from log_scores
|
||||||
where
|
where
|
||||||
server_id = ?
|
server_id = $1
|
||||||
order by ts desc
|
order by ts desc
|
||||||
limit ?;
|
limit $2;
|
||||||
|
|
||||||
-- name: GetServerLogScoresByMonitorID :many
|
-- name: GetServerLogScoresByMonitorID :many
|
||||||
select * from log_scores
|
select * from log_scores
|
||||||
where
|
where
|
||||||
server_id = ? AND
|
server_id = $1 AND
|
||||||
monitor_id = ?
|
monitor_id = $2
|
||||||
order by ts desc
|
order by ts desc
|
||||||
limit ?;
|
limit $3;
|
||||||
|
|
||||||
-- name: GetZoneByName :one
|
-- name: GetZoneByName :one
|
||||||
select * from zones
|
select * from zones
|
||||||
@@ -93,5 +91,5 @@ where
|
|||||||
|
|
||||||
-- name: GetZoneCounts :many
|
-- name: GetZoneCounts :many
|
||||||
select * from zone_server_counts
|
select * from zone_server_counts
|
||||||
where zone_id = ?
|
where zone_id = $1
|
||||||
order by date;
|
order by date;
|
||||||
|
|||||||
3838
schema.sql
3838
schema.sql
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
go install github.com/goreleaser/goreleaser/v2@v2.13.3
|
go install github.com/goreleaser/goreleaser/v2@v2.12.3
|
||||||
|
|
||||||
if [ ! -z "${harbor_username:-}" ]; then
|
if [ ! -z "${harbor_username:-}" ]; then
|
||||||
DOCKER_FILE=~/.docker/config.json
|
DOCKER_FILE=~/.docker/config.json
|
||||||
@@ -13,11 +13,11 @@ if [ ! -z "${harbor_username:-}" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CI_TAG=${CI_COMMIT_TAG:-${DRONE_TAG:-""}}
|
DRONE_TAG=${DRONE_TAG-""}
|
||||||
|
|
||||||
is_snapshot=""
|
is_snapshot=""
|
||||||
|
|
||||||
if [ -z "$CI_TAG" ]; then
|
if [ -z "$DRONE_TAG" ]; then
|
||||||
is_snapshot="--snapshot"
|
is_snapshot="--snapshot"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
@@ -56,7 +56,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
|
|||||||
queryGroup, ctx := errgroup.WithContext(ctx)
|
queryGroup, ctx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
var zoneStats []ntpdb.GetZoneStatsV2Row
|
var zoneStats []ntpdb.GetZoneStatsV2Row
|
||||||
var serverNetspeed uint32
|
var serverNetspeed int64
|
||||||
|
|
||||||
queryGroup.Go(func() error {
|
queryGroup.Go(func() error {
|
||||||
var err error
|
var err error
|
||||||
@@ -64,7 +64,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
|
|||||||
|
|
||||||
serverNetspeed, err = q.GetServerNetspeed(ctx, ip.String())
|
serverNetspeed, err = q.GetServerNetspeed(ctx, ip.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, sql.ErrNoRows) {
|
if !errors.Is(err, pgx.ErrNoRows) {
|
||||||
log.Error("GetServerNetspeed", "err", err)
|
log.Error("GetServerNetspeed", "err", err)
|
||||||
}
|
}
|
||||||
return err // this will return if the server doesn't exist
|
return err // this will return if the server doesn't exist
|
||||||
@@ -116,7 +116,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
|
|||||||
|
|
||||||
err = queryGroup.Wait()
|
err = queryGroup.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
return c.String(http.StatusNotFound, "Not found")
|
return c.String(http.StatusNotFound, "Not found")
|
||||||
}
|
}
|
||||||
log.Error("query error", "err", err)
|
log.Error("query error", "err", err)
|
||||||
@@ -130,7 +130,7 @@ func (srv *Server) dnsAnswers(c echo.Context) error {
|
|||||||
if zn == "@" {
|
if zn == "@" {
|
||||||
zn = ""
|
zn = ""
|
||||||
}
|
}
|
||||||
zoneTotals[zn] = z.NetspeedActive // binary.BigEndian.Uint64(...)
|
zoneTotals[zn] = int(z.NetspeedActive) // binary.BigEndian.Uint64(...)
|
||||||
// log.Info("zone netspeed", "cc", z.ZoneName, "speed", z.NetspeedActive)
|
// log.Info("zone netspeed", "cc", z.ZoneName, "speed", z.NetspeedActive)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
"go.ntppool.org/common/logger"
|
"go.ntppool.org/common/logger"
|
||||||
"go.ntppool.org/common/tracing"
|
"go.ntppool.org/common/tracing"
|
||||||
"go.ntppool.org/data-api/ntpdb"
|
"go.ntppool.org/data-api/ntpdb"
|
||||||
@@ -22,7 +22,7 @@ func (srv *Server) FindServer(ctx context.Context, serverID string) (ntpdb.Serve
|
|||||||
var serverData ntpdb.Server
|
var serverData ntpdb.Server
|
||||||
var dberr error
|
var dberr error
|
||||||
if id, err := strconv.Atoi(serverID); id > 0 && err == nil {
|
if id, err := strconv.Atoi(serverID); id > 0 && err == nil {
|
||||||
serverData, dberr = q.GetServerByID(ctx, uint32(id))
|
serverData, dberr = q.GetServerByID(ctx, int64(id))
|
||||||
} else {
|
} else {
|
||||||
ip, err := netip.ParseAddr(serverID)
|
ip, err := netip.ParseAddr(serverID)
|
||||||
if err != nil || !ip.IsValid() {
|
if err != nil || !ip.IsValid() {
|
||||||
@@ -31,7 +31,7 @@ func (srv *Server) FindServer(ctx context.Context, serverID string) (ntpdb.Serve
|
|||||||
serverData, dberr = q.GetServerByIP(ctx, ip.String())
|
serverData, dberr = q.GetServerByIP(ctx, ip.String())
|
||||||
}
|
}
|
||||||
if dberr != nil {
|
if dberr != nil {
|
||||||
if !errors.Is(dberr, sql.ErrNoRows) {
|
if !errors.Is(dberr, pgx.ErrNoRows) {
|
||||||
log.Error("could not query server id", "err", dberr)
|
log.Error("could not query server id", "err", dberr)
|
||||||
return serverData, dberr
|
return serverData, dberr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ func transformToGrafanaTableFormat(history *logscores.LogScoreHistory, monitors
|
|||||||
skippedInvalidMonitors++
|
skippedInvalidMonitors++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
monitorID := int(ls.MonitorID.Int32)
|
monitorID := int(ls.MonitorID.Int64)
|
||||||
monitorData[monitorID] = append(monitorData[monitorID], ls)
|
monitorData[monitorID] = append(monitorData[monitorID], ls)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ func transformToGrafanaTableFormat(history *logscores.LogScoreHistory, monitors
|
|||||||
var values [][]interface{}
|
var values [][]interface{}
|
||||||
for _, ls := range logScores {
|
for _, ls := range logScores {
|
||||||
// Convert timestamp to milliseconds
|
// Convert timestamp to milliseconds
|
||||||
timestampMs := ls.Ts.Unix() * 1000
|
timestampMs := ls.Ts.Time.Unix() * 1000
|
||||||
|
|
||||||
// Create row: [time, score, rtt, offset]
|
// Create row: [time, score, rtt, offset]
|
||||||
row := []interface{}{
|
row := []interface{}{
|
||||||
@@ -382,7 +382,7 @@ func (srv *Server) scoresTimeRange(c echo.Context) error {
|
|||||||
"time_range_duration", params.to.Sub(params.from).String(),
|
"time_range_duration", params.to.Sub(params.from).String(),
|
||||||
)
|
)
|
||||||
|
|
||||||
logScores, err := srv.ch.LogscoresTimeRange(ctx, int(server.ID), params.monitorID, params.from, params.to, params.maxDataPoints)
|
logScores, err := srv.ch.LogscoresTimeRange(ctx, int(server.ID), int(params.monitorID), params.from, params.to, params.maxDataPoints)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.ErrorContext(ctx, "clickhouse time range query", "err", err,
|
log.ErrorContext(ctx, "clickhouse time range query", "err", err,
|
||||||
"server_id", server.ID,
|
"server_id", server.ID,
|
||||||
@@ -397,8 +397,8 @@ func (srv *Server) scoresTimeRange(c echo.Context) error {
|
|||||||
log.InfoContext(ctx, "clickhouse query results",
|
log.InfoContext(ctx, "clickhouse query results",
|
||||||
"server_id", server.ID,
|
"server_id", server.ID,
|
||||||
"rows_returned", len(logScores),
|
"rows_returned", len(logScores),
|
||||||
"first_few_ids", func() []uint64 {
|
"first_few_ids", func() []int64 {
|
||||||
ids := make([]uint64, 0, 3)
|
ids := make([]int64, 0, 3)
|
||||||
for i, ls := range logScores {
|
for i, ls := range logScores {
|
||||||
if i >= 3 {
|
if i >= 3 {
|
||||||
break
|
break
|
||||||
@@ -416,10 +416,10 @@ func (srv *Server) scoresTimeRange(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get monitor names for the returned data
|
// Get monitor names for the returned data
|
||||||
monitorIDs := []uint32{}
|
monitorIDs := []int64{}
|
||||||
for _, ls := range logScores {
|
for _, ls := range logScores {
|
||||||
if ls.MonitorID.Valid {
|
if ls.MonitorID.Valid {
|
||||||
monitorID := uint32(ls.MonitorID.Int32)
|
monitorID := ls.MonitorID.Int64
|
||||||
if _, exists := history.Monitors[int(monitorID)]; !exists {
|
if _, exists := history.Monitors[int(monitorID)]; !exists {
|
||||||
history.Monitors[int(monitorID)] = ""
|
history.Monitors[int(monitorID)] = ""
|
||||||
monitorIDs = append(monitorIDs, monitorID)
|
monitorIDs = append(monitorIDs, monitorID)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package server
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -15,6 +14,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
|
"github.com/jackc/pgx/v5/pgtype"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"go.ntppool.org/common/logger"
|
"go.ntppool.org/common/logger"
|
||||||
"go.ntppool.org/common/tracing"
|
"go.ntppool.org/common/tracing"
|
||||||
@@ -63,7 +64,7 @@ func paramHistoryMode(s string) historyMode {
|
|||||||
|
|
||||||
type historyParameters struct {
|
type historyParameters struct {
|
||||||
limit int
|
limit int
|
||||||
monitorID int
|
monitorID int64
|
||||||
server ntpdb.Server
|
server ntpdb.Server
|
||||||
since time.Time
|
since time.Time
|
||||||
fullHistory bool
|
fullHistory bool
|
||||||
@@ -90,7 +91,7 @@ func (srv *Server) getHistoryParameters(ctx context.Context, c echo.Context, ser
|
|||||||
|
|
||||||
monitorParam := c.QueryParam("monitor")
|
monitorParam := c.QueryParam("monitor")
|
||||||
|
|
||||||
var monitorID uint32
|
var monitorID int64
|
||||||
switch monitorParam {
|
switch monitorParam {
|
||||||
case "":
|
case "":
|
||||||
name := "recentmedian.scores.ntp.dev"
|
name := "recentmedian.scores.ntp.dev"
|
||||||
@@ -101,7 +102,7 @@ func (srv *Server) getHistoryParameters(ctx context.Context, c echo.Context, ser
|
|||||||
ipVersion = ntpdb.NullMonitorsIpVersion{MonitorsIpVersion: ntpdb.MonitorsIpVersionV6, Valid: true}
|
ipVersion = ntpdb.NullMonitorsIpVersion{MonitorsIpVersion: ntpdb.MonitorsIpVersionV6, Valid: true}
|
||||||
}
|
}
|
||||||
monitor, err := q.GetMonitorByNameAndIPVersion(ctx, ntpdb.GetMonitorByNameAndIPVersionParams{
|
monitor, err := q.GetMonitorByNameAndIPVersion(ctx, ntpdb.GetMonitorByNameAndIPVersionParams{
|
||||||
TlsName: sql.NullString{Valid: true, String: name},
|
TlsName: pgtype.Text{Valid: true, String: name},
|
||||||
IpVersion: ipVersion,
|
IpVersion: ipVersion,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -111,9 +112,9 @@ func (srv *Server) getHistoryParameters(ctx context.Context, c echo.Context, ser
|
|||||||
case "*":
|
case "*":
|
||||||
monitorID = 0 // don't filter on monitor ID
|
monitorID = 0 // don't filter on monitor ID
|
||||||
default:
|
default:
|
||||||
mID, err := strconv.ParseUint(monitorParam, 10, 32)
|
mID, err := strconv.ParseInt(monitorParam, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
monitorID = uint32(mID)
|
monitorID = mID
|
||||||
} else {
|
} else {
|
||||||
// only accept the name prefix; no wildcards; trust the database
|
// only accept the name prefix; no wildcards; trust the database
|
||||||
// to filter out any other crazy
|
// to filter out any other crazy
|
||||||
@@ -129,11 +130,11 @@ func (srv *Server) getHistoryParameters(ctx context.Context, c echo.Context, ser
|
|||||||
ipVersion = ntpdb.NullMonitorsIpVersion{MonitorsIpVersion: ntpdb.MonitorsIpVersionV6, Valid: true}
|
ipVersion = ntpdb.NullMonitorsIpVersion{MonitorsIpVersion: ntpdb.MonitorsIpVersionV6, Valid: true}
|
||||||
}
|
}
|
||||||
monitor, err := q.GetMonitorByNameAndIPVersion(ctx, ntpdb.GetMonitorByNameAndIPVersionParams{
|
monitor, err := q.GetMonitorByNameAndIPVersion(ctx, ntpdb.GetMonitorByNameAndIPVersionParams{
|
||||||
TlsName: sql.NullString{Valid: true, String: monitorParam},
|
TlsName: pgtype.Text{Valid: true, String: monitorParam},
|
||||||
IpVersion: ipVersion,
|
IpVersion: ipVersion,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
return p, echo.NewHTTPError(http.StatusNotFound, "monitor not found").WithInternal(err)
|
return p, echo.NewHTTPError(http.StatusNotFound, "monitor not found").WithInternal(err)
|
||||||
}
|
}
|
||||||
log.WarnContext(ctx, "could not find monitor", "name", monitorParam, "ip_version", server.IpVersion, "err", err)
|
log.WarnContext(ctx, "could not find monitor", "name", monitorParam, "ip_version", server.IpVersion, "err", err)
|
||||||
@@ -144,7 +145,7 @@ func (srv *Server) getHistoryParameters(ctx context.Context, c echo.Context, ser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.monitorID = int(monitorID)
|
p.monitorID = monitorID
|
||||||
log.DebugContext(ctx, "monitor param", "monitor", monitorID, "ip_version", server.IpVersion)
|
log.DebugContext(ctx, "monitor param", "monitor", monitorID, "ip_version", server.IpVersion)
|
||||||
|
|
||||||
since, _ := strconv.ParseInt(c.QueryParam("since"), 10, 64) // defaults to 0 so don't care if it parses
|
since, _ := strconv.ParseInt(c.QueryParam("since"), 10, 64) // defaults to 0 so don't care if it parses
|
||||||
@@ -170,8 +171,8 @@ func (srv *Server) getHistoryParameters(ctx context.Context, c echo.Context, ser
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) getHistoryMySQL(ctx context.Context, _ echo.Context, p historyParameters) (*logscores.LogScoreHistory, error) {
|
func (srv *Server) getHistoryPostgres(ctx context.Context, _ echo.Context, p historyParameters) (*logscores.LogScoreHistory, error) {
|
||||||
ls, err := logscores.GetHistoryMySQL(ctx, srv.db, p.server.ID, uint32(p.monitorID), p.since, p.limit)
|
ls, err := logscores.GetHistoryPostgres(ctx, srv.db, p.server.ID, p.monitorID, p.since, p.limit)
|
||||||
return ls, err
|
return ls, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,9 +231,9 @@ func (srv *Server) history(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if sourceParam == "m" {
|
if sourceParam == "m" {
|
||||||
history, err = srv.getHistoryMySQL(ctx, c, p)
|
history, err = srv.getHistoryPostgres(ctx, c, p)
|
||||||
} else {
|
} else {
|
||||||
history, err = logscores.GetHistoryClickHouse(ctx, srv.ch, srv.db, p.server.ID, uint32(p.monitorID), p.since, p.limit, p.fullHistory)
|
history, err = logscores.GetHistoryClickHouse(ctx, srv.ch, srv.db, p.server.ID, p.monitorID, p.since, p.limit, p.fullHistory)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var httpError *echo.HTTPError
|
var httpError *echo.HTTPError
|
||||||
@@ -276,7 +277,7 @@ func (srv *Server) historyJSON(ctx context.Context, c echo.Context, server ntpdb
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MonitorEntry struct {
|
type MonitorEntry struct {
|
||||||
ID uint32 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Ts string `json:"ts"`
|
Ts string `json:"ts"`
|
||||||
@@ -297,9 +298,9 @@ func (srv *Server) historyJSON(ctx context.Context, c echo.Context, server ntpdb
|
|||||||
|
|
||||||
// log.InfoContext(ctx, "monitor id list", "ids", history.MonitorIDs)
|
// log.InfoContext(ctx, "monitor id list", "ids", history.MonitorIDs)
|
||||||
|
|
||||||
monitorIDs := []uint32{}
|
monitorIDs := []int64{}
|
||||||
for k := range history.Monitors {
|
for k := range history.Monitors {
|
||||||
monitorIDs = append(monitorIDs, uint32(k))
|
monitorIDs = append(monitorIDs, int64(k))
|
||||||
}
|
}
|
||||||
|
|
||||||
q := ntpdb.NewWrappedQuerier(ntpdb.New(srv.db))
|
q := ntpdb.NewWrappedQuerier(ntpdb.New(srv.db))
|
||||||
@@ -318,12 +319,12 @@ func (srv *Server) historyJSON(ctx context.Context, c echo.Context, server ntpdb
|
|||||||
// log.InfoContext(ctx, "got logScoreMonitors", "count", len(logScoreMonitors))
|
// log.InfoContext(ctx, "got logScoreMonitors", "count", len(logScoreMonitors))
|
||||||
|
|
||||||
// Calculate average RTT per monitor
|
// Calculate average RTT per monitor
|
||||||
monitorRttSums := make(map[uint32]float64)
|
monitorRttSums := make(map[int64]float64)
|
||||||
monitorRttCounts := make(map[uint32]int)
|
monitorRttCounts := make(map[int64]int)
|
||||||
|
|
||||||
for _, ls := range history.LogScores {
|
for _, ls := range history.LogScores {
|
||||||
if ls.MonitorID.Valid && ls.Rtt.Valid {
|
if ls.MonitorID.Valid && ls.Rtt.Valid {
|
||||||
monitorID := uint32(ls.MonitorID.Int32)
|
monitorID := ls.MonitorID.Int64
|
||||||
monitorRttSums[monitorID] += float64(ls.Rtt.Int32) / 1000.0
|
monitorRttSums[monitorID] += float64(ls.Rtt.Int32) / 1000.0
|
||||||
monitorRttCounts[monitorID]++
|
monitorRttCounts[monitorID]++
|
||||||
}
|
}
|
||||||
@@ -362,8 +363,8 @@ func (srv *Server) historyJSON(ctx context.Context, c echo.Context, server ntpdb
|
|||||||
x := float64(1000000000000)
|
x := float64(1000000000000)
|
||||||
score := math.Round(ls.Score*x) / x
|
score := math.Round(ls.Score*x) / x
|
||||||
res.History[i] = ScoresEntry{
|
res.History[i] = ScoresEntry{
|
||||||
TS: ls.Ts.Unix(),
|
TS: ls.Ts.Time.Unix(),
|
||||||
MonitorID: int(ls.MonitorID.Int32),
|
MonitorID: int(ls.MonitorID.Int64),
|
||||||
Step: ls.Step,
|
Step: ls.Step,
|
||||||
Score: score,
|
Score: score,
|
||||||
}
|
}
|
||||||
@@ -414,7 +415,7 @@ func (srv *Server) historyCSV(ctx context.Context, c echo.Context, history *logs
|
|||||||
score := ff(l.Score)
|
score := ff(l.Score)
|
||||||
var monName string
|
var monName string
|
||||||
if l.MonitorID.Valid {
|
if l.MonitorID.Valid {
|
||||||
monName = history.Monitors[int(l.MonitorID.Int32)]
|
monName = history.Monitors[int(l.MonitorID.Int64)]
|
||||||
}
|
}
|
||||||
var leap string
|
var leap string
|
||||||
if l.Attributes.Leap != 0 {
|
if l.Attributes.Leap != 0 {
|
||||||
@@ -427,13 +428,13 @@ func (srv *Server) historyCSV(ctx context.Context, c echo.Context, history *logs
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := w.Write([]string{
|
err := w.Write([]string{
|
||||||
strconv.Itoa(int(l.Ts.Unix())),
|
strconv.Itoa(int(l.Ts.Time.Unix())),
|
||||||
// l.Ts.Format(time.RFC3339),
|
// l.Ts.Format(time.RFC3339),
|
||||||
l.Ts.Format("2006-01-02 15:04:05"),
|
l.Ts.Time.Format("2006-01-02 15:04:05"),
|
||||||
offset,
|
offset,
|
||||||
step,
|
step,
|
||||||
score,
|
score,
|
||||||
fmt.Sprintf("%d", l.MonitorID.Int32),
|
fmt.Sprintf("%d", l.MonitorID.Int64),
|
||||||
monName,
|
monName,
|
||||||
rtt,
|
rtt,
|
||||||
leap,
|
leap,
|
||||||
@@ -464,7 +465,7 @@ func setHistoryCacheControl(c echo.Context, history *logscores.LogScoreHistory)
|
|||||||
if len(history.LogScores) == 0 ||
|
if len(history.LogScores) == 0 ||
|
||||||
// cache for longer if data hasn't updated for a while; or we didn't
|
// cache for longer if data hasn't updated for a while; or we didn't
|
||||||
// find any.
|
// find any.
|
||||||
(time.Now().Add(-8 * time.Hour).After(history.LogScores[len(history.LogScores)-1].Ts)) {
|
(time.Now().Add(-8 * time.Hour).After(history.LogScores[len(history.LogScores)-1].Ts.Time)) {
|
||||||
hdr.Set("Cache-Control", "s-maxage=260,max-age=360")
|
hdr.Set("Cache-Control", "s-maxage=260,max-age=360")
|
||||||
} else {
|
} else {
|
||||||
if len(history.LogScores) == 1 {
|
if len(history.LogScores) == 1 {
|
||||||
|
|||||||
@@ -2,17 +2,16 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
"github.com/labstack/echo-contrib/echoprometheus"
|
"github.com/labstack/echo-contrib/echoprometheus"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
@@ -29,14 +28,14 @@ import (
|
|||||||
"go.ntppool.org/common/version"
|
"go.ntppool.org/common/version"
|
||||||
"go.ntppool.org/common/xff/fastlyxff"
|
"go.ntppool.org/common/xff/fastlyxff"
|
||||||
|
|
||||||
"go.ntppool.org/common/config"
|
"go.ntppool.org/api/config"
|
||||||
|
|
||||||
chdb "go.ntppool.org/data-api/chdb"
|
chdb "go.ntppool.org/data-api/chdb"
|
||||||
"go.ntppool.org/data-api/ntpdb"
|
"go.ntppool.org/data-api/ntpdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
db *sql.DB
|
db *pgxpool.Pool
|
||||||
ch *chdb.ClickHouse
|
ch *chdb.ClickHouse
|
||||||
config *config.Config
|
config *config.Config
|
||||||
|
|
||||||
@@ -55,7 +54,7 @@ func NewServer(ctx context.Context, configFile string) (*Server, error) {
|
|||||||
}
|
}
|
||||||
db, err := ntpdb.OpenDB(ctx, configFile)
|
db, err := ntpdb.OpenDB(ctx, configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("mysql open: %w", err)
|
return nil, fmt.Errorf("postgres open: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
@@ -187,10 +186,6 @@ func (srv *Server) Run() error {
|
|||||||
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
|
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
e.Pre(middleware.Rewrite(map[string]string{
|
|
||||||
"/api/data/*": "/api/$1",
|
|
||||||
}))
|
|
||||||
|
|
||||||
e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
|
e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
|
||||||
LogErrorFunc: func(c echo.Context, err error, stack []byte) error {
|
LogErrorFunc: func(c echo.Context, err error, stack []byte) error {
|
||||||
log.ErrorContext(c.Request().Context(), err.Error(), "stack", string(stack))
|
log.ErrorContext(c.Request().Context(), err.Error(), "stack", string(stack))
|
||||||
@@ -307,22 +302,9 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
g, ctx := errgroup.WithContext(ctx)
|
g, ctx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
stats := srv.db.Stats()
|
stats := srv.db.Stat()
|
||||||
if stats.OpenConnections > 3 {
|
if stats.TotalConns() > 3 {
|
||||||
log.InfoContext(ctx, "health requests", "url", req.URL.String(), "stats", stats)
|
log.InfoContext(ctx, "health requests", "url", req.URL.String(), "total_conns", stats.TotalConns())
|
||||||
}
|
|
||||||
|
|
||||||
if resetParam := req.URL.Query().Get("reset"); resetParam != "" {
|
|
||||||
reset, err := strconv.ParseBool(resetParam)
|
|
||||||
log.InfoContext(ctx, "db reset request", "err", err, "reset", reset)
|
|
||||||
|
|
||||||
if err == nil && reset {
|
|
||||||
// this feature was to debug some specific problem
|
|
||||||
log.InfoContext(ctx, "setting idle db conns to zero")
|
|
||||||
srv.db.SetConnMaxLifetime(30 * time.Second)
|
|
||||||
srv.db.SetMaxIdleConns(0)
|
|
||||||
srv.db.SetMaxIdleConns(4)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
@@ -344,7 +326,7 @@ func healthHandler(srv *Server, log *slog.Logger) func(w http.ResponseWriter, re
|
|||||||
})
|
})
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
err := srv.db.PingContext(ctx)
|
err := srv.db.Ping(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WarnContext(ctx, "db ping", "err", err)
|
log.WarnContext(ctx, "db ping", "err", err)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"go.ntppool.org/common/logger"
|
"go.ntppool.org/common/logger"
|
||||||
"go.ntppool.org/common/tracing"
|
"go.ntppool.org/common/tracing"
|
||||||
@@ -27,7 +27,7 @@ func (srv *Server) zoneCounts(c echo.Context) error {
|
|||||||
|
|
||||||
zone, err := q.GetZoneByName(ctx, c.Param("zone_name"))
|
zone, err := q.GetZoneByName(ctx, c.Param("zone_name"))
|
||||||
if err != nil || zone.ID == 0 {
|
if err != nil || zone.ID == 0 {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
return c.String(http.StatusNotFound, "Not found")
|
return c.String(http.StatusNotFound, "Not found")
|
||||||
}
|
}
|
||||||
log.ErrorContext(ctx, "could not query for zone", "err", err)
|
log.ErrorContext(ctx, "could not query for zone", "err", err)
|
||||||
@@ -37,7 +37,7 @@ func (srv *Server) zoneCounts(c echo.Context) error {
|
|||||||
|
|
||||||
counts, err := q.GetZoneCounts(ctx, zone.ID)
|
counts, err := q.GetZoneCounts(ctx, zone.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, sql.ErrNoRows) {
|
if !errors.Is(err, pgx.ErrNoRows) {
|
||||||
log.ErrorContext(ctx, "get counts", "err", err)
|
log.ErrorContext(ctx, "get counts", "err", err)
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
return c.String(http.StatusInternalServerError, "internal error")
|
return c.String(http.StatusInternalServerError, "internal error")
|
||||||
@@ -71,7 +71,7 @@ func (srv *Server) zoneCounts(c echo.Context) error {
|
|||||||
count := 0
|
count := 0
|
||||||
dates := map[int64]bool{}
|
dates := map[int64]bool{}
|
||||||
for _, c := range counts {
|
for _, c := range counts {
|
||||||
ep := c.Date.Unix()
|
ep := c.Date.Time.Unix()
|
||||||
if _, ok := dates[ep]; !ok {
|
if _, ok := dates[ep]; !ok {
|
||||||
count++
|
count++
|
||||||
dates[ep] = true
|
dates[ep] = true
|
||||||
@@ -99,13 +99,13 @@ func (srv *Server) zoneCounts(c echo.Context) error {
|
|||||||
lastSkip := int64(0)
|
lastSkip := int64(0)
|
||||||
skipThreshold := 0.5
|
skipThreshold := 0.5
|
||||||
for _, c := range counts {
|
for _, c := range counts {
|
||||||
cDate := c.Date.Unix()
|
cDate := c.Date.Time.Unix()
|
||||||
if (toSkip <= skipThreshold && cDate != lastSkip) ||
|
if (toSkip <= skipThreshold && cDate != lastSkip) ||
|
||||||
lastDate == cDate ||
|
lastDate == cDate ||
|
||||||
mostRecentDate == cDate {
|
mostRecentDate == cDate {
|
||||||
// log.Info("adding date", "date", c.Date.Format(time.DateOnly))
|
// log.Info("adding date", "date", c.Date.Time.Format(time.DateOnly))
|
||||||
rv.History = append(rv.History, historyEntry{
|
rv.History = append(rv.History, historyEntry{
|
||||||
D: c.Date.Format(time.DateOnly),
|
D: c.Date.Time.Format(time.DateOnly),
|
||||||
Ts: int(cDate),
|
Ts: int(cDate),
|
||||||
Ac: int(c.CountActive),
|
Ac: int(c.CountActive),
|
||||||
Rc: int(c.CountRegistered),
|
Rc: int(c.CountRegistered),
|
||||||
|
|||||||
@@ -2,16 +2,17 @@ version: "2"
|
|||||||
sql:
|
sql:
|
||||||
- schema: "schema.sql"
|
- schema: "schema.sql"
|
||||||
queries: "query.sql"
|
queries: "query.sql"
|
||||||
engine: "mysql"
|
engine: "postgresql"
|
||||||
|
strict_order_by: false
|
||||||
gen:
|
gen:
|
||||||
go:
|
go:
|
||||||
package: "ntpdb"
|
package: "ntpdb"
|
||||||
out: "ntpdb"
|
out: "ntpdb"
|
||||||
|
sql_package: "pgx/v5"
|
||||||
emit_json_tags: true
|
emit_json_tags: true
|
||||||
emit_db_tags: true
|
emit_db_tags: true
|
||||||
omit_unused_structs: true
|
omit_unused_structs: true
|
||||||
emit_interface: true
|
emit_interface: true
|
||||||
# emit_all_enum_values: true
|
|
||||||
rename:
|
rename:
|
||||||
servers.Ip: IP
|
servers.Ip: IP
|
||||||
overrides:
|
overrides:
|
||||||
|
|||||||
Reference in New Issue
Block a user