From aa6535af7593c1f8ff96a01b13a2a2361ba4090f Mon Sep 17 00:00:00 2001 From: swithek <52840391+swithek@users.noreply.github.com> Date: Sun, 23 Aug 2026 18:22:28 +0200 Subject: [PATCH] fix datagen deps --- datagen/cmd/main.go | 2 +- datagen/go.mod | 34 ++++---- datagen/go.sum | 83 ++++++++----------- datagen/internal/gen/manager.go | 2 +- datagen/internal/server/server.go | 6 +- server/core/pkg/metricutil/metricutil.go | 60 +++++++++++++- server/core/pkg/metricutil/metricutil_test.go | 57 +++++++++++++ server/core/pkg/metricutil/util.go | 6 ++ 8 files changed, 179 insertions(+), 71 deletions(-) diff --git a/datagen/cmd/main.go b/datagen/cmd/main.go index f4cfdac9..ef909171 100644 --- a/datagen/cmd/main.go +++ b/datagen/cmd/main.go @@ -12,7 +12,7 @@ import ( "github.com/oxynote/oxynote/datagen/internal/mariademo" "github.com/oxynote/oxynote/datagen/internal/pgdemo" "github.com/oxynote/oxynote/datagen/internal/server" - "github.com/oxynote/purse/util/metricutil" + "github.com/oxynote/oxynote/server/core/pkg/metricutil" "github.com/prometheus/client_golang/prometheus" ) diff --git a/datagen/go.mod b/datagen/go.mod index 6d05cda1..80f8eebf 100644 --- a/datagen/go.mod +++ b/datagen/go.mod @@ -1,33 +1,33 @@ module github.com/oxynote/oxynote/datagen -go 1.25.5 +go 1.27.0 require ( - github.com/go-chi/chi/v5 v5.2.2 - github.com/go-sql-driver/mysql v1.9.3 - github.com/jackc/pgx/v5 v5.8.0 - github.com/oxynote/purse v0.0.0-20260221143056-b9e7b929b864 - github.com/prometheus/client_golang v1.23.0 + github.com/go-chi/chi/v5 v5.3.0 + github.com/go-sql-driver/mysql v1.10.0 + github.com/jackc/pgx/v5 v5.9.2 + github.com/oxynote/oxynote/server/core v0.0.0 + github.com/prometheus/client_golang v1.23.2 ) +replace github.com/oxynote/oxynote/server/core => ../server/core + require ( - filippo.io/edwards25519 v1.1.0 // indirect + filippo.io/edwards25519 v1.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/getsentry/sentry-go v0.35.0 // indirect + github.com/getsentry/sentry-go v0.46.2 // indirect github.com/gorilla/schema v1.4.1 // indirect - github.com/hashicorp/errwrap v1.0.0 // indirect - github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect - github.com/jellydator/validation v1.1.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/prometheus/client_model v0.6.2 // indirect - github.com/prometheus/common v0.65.0 // indirect - github.com/prometheus/procfs v0.16.1 // indirect + github.com/prometheus/common v0.67.5 // indirect + github.com/prometheus/procfs v0.20.1 // indirect + github.com/robfig/cron/v3 v3.0.1 // indirect github.com/rs/xid v1.6.0 // indirect - golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 // indirect - golang.org/x/sys v0.33.0 // indirect - golang.org/x/text v0.29.0 // indirect - google.golang.org/protobuf v1.36.6 // indirect + go.yaml.in/yaml/v2 v2.4.4 // indirect + golang.org/x/sys v0.47.0 // indirect + golang.org/x/text v0.40.0 // indirect + google.golang.org/protobuf v1.36.11 // indirect ) diff --git a/datagen/go.sum b/datagen/go.sum index 705a1c0b..83d7f0f9 100644 --- a/datagen/go.sum +++ b/datagen/go.sum @@ -1,88 +1,77 @@ -filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= -filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= -github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= -github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo= +filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/getsentry/sentry-go v0.35.0 h1:+FJNlnjJsZMG3g0/rmmP7GiKjQoUF5EXfEtBwtPtkzY= -github.com/getsentry/sentry-go v0.35.0/go.mod h1:C55omcY9ChRQIUcVcGcs+Zdy4ZpQGvNJ7JYHIoSWOtE= -github.com/go-chi/chi/v5 v5.2.2 h1:CMwsvRVTbXVytCk1Wd72Zy1LAsAh9GxMmSNWLHCG618= -github.com/go-chi/chi/v5 v5.2.2/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/getsentry/sentry-go v0.46.2 h1:1jhYwrKGa3sIpo/y5iDNXS5wDoT7I1KNzMHrnK6ojns= +github.com/getsentry/sentry-go v0.46.2/go.mod h1:evVbw2qotNUdYG8KxXbAdjOQWWvWIwKxpjdZZIvcIPw= +github.com/go-chi/chi/v5 v5.3.0 h1:halUjDxhshgXHMrao5bB8eNBXo/rnzwr8m5m36glehM= +github.com/go-chi/chi/v5 v5.3.0/go.mod h1:R+tYY2hNuVUUjxoPtqUdgBqevM9s9njzkTLutVsOCto= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo= -github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= +github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw= +github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E= github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= -github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= 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/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.8.0 h1:TYPDoleBBme0xGSAX3/+NujXXtpZn9HBONkQC7IEZSo= -github.com/jackc/pgx/v5 v5.8.0/go.mod h1:QVeDInX2m9VyzvNeiCJVjCkNFqzsNb43204HshNSZKw= +github.com/jackc/pgx/v5 v5.9.2 h1:3ZhOzMWnR4yJ+RW1XImIPsD1aNSz4T4fyP7zlQb56hw= +github.com/jackc/pgx/v5 v5.9.2/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= 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/jarcoal/httpmock v1.4.0 h1:BvhqnH0JAYbNudL2GMJKgOHe2CtKlzJ/5rWKyp+hc2k= -github.com/jarcoal/httpmock v1.4.0/go.mod h1:ftW1xULwo+j0R0JJkJIIi7UKigZUXCLLanykgjwBXL0= -github.com/jellydator/validation v1.1.0 h1:TBkx56y6dd0By2AhtStRdTIhDjtcuoSE9w6G6z7wQ4o= -github.com/jellydator/validation v1.1.0/go.mod h1:AaCjfkQ4Ykdcb+YCwqCtaI3wDsf2UAGhJ06lJs0VgOw= -github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= -github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/jarcoal/httpmock v1.4.2 h1:dKwiP/9zITCPfBLsDn3kchbSOu16JrnxtVEmL0fPRcI= +github.com/jarcoal/httpmock v1.4.2/go.mod h1:ftW1xULwo+j0R0JJkJIIi7UKigZUXCLLanykgjwBXL0= +github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao= +github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/oxynote/purse v0.0.0-20260221143056-b9e7b929b864 h1:cmOvsVn2VCrt02k2IOVKZ1a6gxWuRPy/ZcDtT/0mT3c= -github.com/oxynote/purse v0.0.0-20260221143056-b9e7b929b864/go.mod h1:BzVO555hazk20lGO77zniqpHqPndyCWRVk7QwFQ60dw= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.23.0 h1:ust4zpdl9r4trLY/gSjlm07PuiBq2ynaXXlptpfy8Uc= -github.com/prometheus/client_golang v1.23.0/go.mod h1:i/o0R9ByOnHX0McrTMTyhYvKE4haaf2mW08I+jGAjEE= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o= +github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg= github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= -github.com/prometheus/common v0.65.0 h1:QDwzd+G1twt//Kwj/Ww6E9FQq1iVMmODnILtW1t2VzE= -github.com/prometheus/common v0.65.0/go.mod h1:0gZns+BLRQ3V6NdaerOhMbwwRbNh9hkGINtQAsP5GS8= -github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg= -github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is= +github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4= +github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw= +github.com/prometheus/procfs v0.20.1 h1:XwbrGOIplXW/AU3YhIhLODXMJYyC1isLFfYCsTEycfc= +github.com/prometheus/procfs v0.20.1/go.mod h1:o9EMBZGRyvDrSPH1RqdxhojkuXstoe4UlK79eF5TGGo= +github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= +github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU= github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= -github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= -github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 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.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -golang.org/x/exp v0.0.0-20250718183923-645b1fa84792 h1:R9PFI6EUdfVKgwKjZef7QIwGcBKu86OEFpJ9nUEP2l4= -golang.org/x/exp v0.0.0-20250718183923-645b1fa84792/go.mod h1:A+z0yzpGtvnG90cToK5n2tu8UJVP2XUATh+r+sfOOOc= -golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= -golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= -golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= -golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= -golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= -google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= -google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= +go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= +go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= +golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= +golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs= +golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY= +google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= +google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/datagen/internal/gen/manager.go b/datagen/internal/gen/manager.go index f06b13ab..7b1d80ab 100644 --- a/datagen/internal/gen/manager.go +++ b/datagen/internal/gen/manager.go @@ -7,7 +7,7 @@ import ( "time" "github.com/oxynote/oxynote/datagen/internal/mockmetrics" - "github.com/oxynote/purse/util/metricutil" + "github.com/oxynote/oxynote/server/core/pkg/metricutil" "github.com/prometheus/client_golang/prometheus" ) diff --git a/datagen/internal/server/server.go b/datagen/internal/server/server.go index d9d6f96c..a885bb40 100644 --- a/datagen/internal/server/server.go +++ b/datagen/internal/server/server.go @@ -9,9 +9,9 @@ import ( "time" "github.com/go-chi/chi/v5" - "github.com/oxynote/purse/http/httpserver" - "github.com/oxynote/purse/util/logutil" - "github.com/oxynote/purse/util/metricutil" + "github.com/oxynote/oxynote/server/core/pkg/httpserver" + "github.com/oxynote/oxynote/server/core/pkg/logutil" + "github.com/oxynote/oxynote/server/core/pkg/metricutil" "github.com/prometheus/client_golang/prometheus/promhttp" ) diff --git a/server/core/pkg/metricutil/metricutil.go b/server/core/pkg/metricutil/metricutil.go index 5c9bccf8..91d00202 100644 --- a/server/core/pkg/metricutil/metricutil.go +++ b/server/core/pkg/metricutil/metricutil.go @@ -36,6 +36,9 @@ type Factory interface { // NewHistogramVec creates a new histogram vector. NewHistogramVec(opts Options, labels []string) HistogramVec + + // NewGaugeVec creates a new gauge vector. + NewGaugeVec(opts Options, labels []string) GaugeVec } // RegistererGatherer is a registerer and gatherer. @@ -57,18 +60,34 @@ type factory struct { // NewFactory creates a new metrics factory. If registerer is nil, collectors // are no-op. -func NewFactory(namespace string, rg RegistererGatherer) Factory { +func NewFactory(namespace string, rg RegistererGatherer, opts ...Option) Factory { host, err := os.Hostname() if err != nil { // NOCOV: this should never happen host = "unknown" } - return &factory{ + f := &factory{ RegistererGatherer: rg, namespace: namespace, host: host, } + + for _, opt := range opts { + opt(f) + } + + return f +} + +// Option modifies the factory during construction. +type Option func(f *factory) + +// WithCustomHost sets a custom hostname for the metrics. +func WithCustomHost(host string) Option { + return func(f *factory) { + f.host = host + } } // registerOrExisting registers the collector and returns it, or returns the @@ -185,6 +204,28 @@ func (f *factory) NewHistogramVec(opts Options, labels []string) HistogramVec { return hv } +// NewGaugeVec creates a new gauge vector. +func (f *factory) NewGaugeVec(opts Options, labels []string) GaugeVec { + gv := &gaugeVec{ + host: f.host, + } + + if f.RegistererGatherer == nil { + return gv + } + + gv.gauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: f.namespace, //nolint:promlinter // cannot validate a variable + Subsystem: opts.Subsystem, + Name: opts.Name, + Help: opts.Help, + }, append(labels, _hostLabel)) + + gv.gauge = registerOrExisting(f, gv.gauge) + + return gv +} + // counterVec is a counter vector. type counterVec struct { counter *prometheus.CounterVec @@ -215,6 +256,21 @@ func (hv histogramVec) With(labels prometheus.Labels) Observer { return hv.histogram.With(withHost(labels, hv.host)) } +// gaugeVec is a gauge vector. +type gaugeVec struct { + gauge *prometheus.GaugeVec + host string +} + +// With implements GaugeVec. +func (gv gaugeVec) With(labels prometheus.Labels) Gauge { + if gv.gauge == nil { + return discarder{} + } + + return gv.gauge.With(withHost(labels, gv.host)) +} + // withHost returns a copy of the labels carrying the host label, leaving the // caller's map untouched so it stays reusable across metric families. func withHost(labels prometheus.Labels, host string) prometheus.Labels { diff --git a/server/core/pkg/metricutil/metricutil_test.go b/server/core/pkg/metricutil/metricutil_test.go index 2335ee26..c018ae6c 100644 --- a/server/core/pkg/metricutil/metricutil_test.go +++ b/server/core/pkg/metricutil/metricutil_test.go @@ -17,6 +17,18 @@ func Test_NewFactory(t *testing.T) { f := NewFactory("test", reg) assert.Equal(t, reg, f.(*factory).RegistererGatherer) assert.Equal(t, "test", f.(*factory).namespace) + + f = NewFactory("test", reg, WithCustomHost("custom")) + assert.Equal(t, "custom", f.(*factory).host) +} + +func Test_WithCustomHost(t *testing.T) { + t.Parallel() + + f := &factory{} + + WithCustomHost("custom")(f) + assert.Equal(t, "custom", f.host) } func Test_registerOrExisting(t *testing.T) { @@ -134,6 +146,30 @@ func Test_factory_NewHistogramVec(t *testing.T) { assert.Same(t, cv.(*histogramVec).histogram, ncv.(*histogramVec).histogram) } +func Test_factory_NewGaugeVec(t *testing.T) { + var f factory + + gv := f.NewGaugeVec(Options{}, []string{"foo"}) + assert.Equal(t, &gaugeVec{}, gv.(*gaugeVec)) + + f.RegistererGatherer = prometheus.NewRegistry() + + gv = f.NewGaugeVec(Options{ + Name: "test_duration", + Help: "test help", + }, []string{"foo"}) + + assert.IsType(t, &prometheus.GaugeVec{}, gv.(*gaugeVec).gauge) + + ngv := f.NewGaugeVec(Options{ + Name: "test_duration", + Help: "test help", + }, []string{"foo"}) + + assert.IsType(t, &prometheus.GaugeVec{}, ngv.(*gaugeVec).gauge) + assert.Same(t, gv.(*gaugeVec).gauge, ngv.(*gaugeVec).gauge) +} + func Test_counterVec_With(t *testing.T) { var cv counterVec @@ -176,6 +212,27 @@ func Test_histogramVec_With(t *testing.T) { assert.Equal(t, prometheus.Labels{"foo": "bar"}, labels, "caller labels must not be mutated") } +func Test_gaugeVec_With(t *testing.T) { + var gv gaugeVec + + g := gv.With(prometheus.Labels{"foo": "bar"}) + assert.IsType(t, discarder{}, g) + + gv.gauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "test_duration", + Help: "test help", + }, []string{"foo", _hostLabel}) + + g = gv.With(prometheus.Labels{"foo": "bar"}) + _, ok := g.(prometheus.Gauge) + assert.True(t, ok) + + labels := prometheus.Labels{"foo": "bar"} + + gv.With(labels) + assert.Equal(t, prometheus.Labels{"foo": "bar"}, labels, "caller labels must not be mutated") +} + func Test_discarder_Set(_ *testing.T) { (&discarder{}).Set(123) } diff --git a/server/core/pkg/metricutil/util.go b/server/core/pkg/metricutil/util.go index 460566f8..a56d2968 100644 --- a/server/core/pkg/metricutil/util.go +++ b/server/core/pkg/metricutil/util.go @@ -73,6 +73,12 @@ type Observer interface { Observe(value float64) } +// GaugeVec is a gauge vector. +type GaugeVec interface { + // With returns a gauge with the given labels. + With(labels prometheus.Labels) Gauge +} + // Gauge is a gauge data collector. type Gauge interface { // Set should set the Gauge to an arbitrary value.