This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package db | |
import ( | |
"github.com/prometheus/client_golang/prometheus" | |
"github.com/prometheus/client_golang/prometheus/promauto" | |
) | |
var queryTime = promauto.NewHistogramVec( | |
prometheus.HistogramOpts{ | |
Name: "db_client_query_execution_time", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package caller | |
// Info generates caller metadata: | |
// - func name (trimmed of leading path parts) - e.g. somepkg.(*SomeStruct).SomeMethod | |
// - file name - e.g. /go/src/github.com/someone/someproject/file.go | |
// - line - e.g. 23 | |
func Info(depth, skip int) (string, string, int) { | |
var ( | |
pcs [depth]uintptr | |
fn, file string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package some_test | |
import ( | |
"crypto/ecdsa" | |
"crypto/elliptic" | |
"crypto/rand" | |
"crypto/x509" | |
"crypto/x509/pkix" | |
"encoding/pem" | |
"fmt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package collector | |
import ( | |
"sync" | |
) | |
// Collector manages feeding workers with Job objects and Result data collection, | |
// synchronizing both parts through an internal counter. | |
// Once created, it can and should be re-used. | |
type Collector[Result, Job any] struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package db | |
import ( | |
"github.com/prometheus/client_golang/prometheus" | |
"github.com/prometheus/client_golang/prometheus/promauto" | |
) | |
const ( | |
clientNamespace = "db_client" | |
querySubsystem = "query" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SizedPool is a channel-based pool of slices objects. | |
// It retains an arbitrary number of slices of objects and ensures their initial capacity. | |
type SizedPool[T any] struct { | |
pool chan []T | |
cap int | |
} | |
func NewSizedPool[T any](size int, cap int) *SizedPool[T] { | |
return &SizedPool[T]{ | |
pool: make(chan []T, size), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH | |
first AS ( | |
DELETE FROM table1 WHERE condition1 | |
RETURNING * | |
), | |
second AS ( | |
DELETE FROM table2 WHERE condition2 | |
RETURNING * | |
), | |
-- add more analogous delete statements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH ranked_records AS ( | |
SELECT row_number() OVER (PARTITION BY user_id, user_id ORDER BY created_at DESC) AS rn, | |
id, some_other_column, created_at | |
FROM user_status WHERE user_id IN (?) | |
) | |
SELECT | |
id, some_other_column, created_at | |
FROM ranked_records | |
WHERE rn=1 | |
ORDER BY user_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH get AS ( | |
SELECT id FROM table_name WHERE name=$1 | |
), new AS ( | |
INSERT INTO table_name (name) VALUES ($1) ON CONFLICT (name) DO NOTHING RETURNING id | |
) | |
SELECT id FROM get | |
UNION ALL | |
SELECT id FROM new; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config: | |
environments: | |
local: | |
target: "http://localhost:8000" | |
phases: | |
- duration: 10 | |
arrivalRate: 1 | |
arrivalCount: 200 | |
maxVusers: 50 | |
name: "Warm up" |
NewerOlder