cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.13.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/promapi/prometheus.go

38lines · modecode

1package promapi
2
3import (
4 "sync"
5 "time"
6
7 lru "github.com/hashicorp/golang-lru"
8 "github.com/prometheus/client_golang/api"
9 v1 "github.com/prometheus/client_golang/api/prometheus/v1"
10)
11
12type Prometheus struct {
13 name string
14 uri string
15 api v1.API
16 timeout time.Duration
17 cache *lru.Cache
18 lock *partitionLocker
19}
20
21func NewPrometheus(name, uri string, timeout time.Duration) *Prometheus {
22 client, err := api.NewClient(api.Config{Address: uri})
23 if err != nil {
24 // config validation should prevent this from ever happening
25 // panic so we don't need to return an error and it's easier to
26 // use this code in tests
27 panic(err)
28 }
29 cache, _ := lru.New(1000)
30 return &Prometheus{
31 name: name,
32 uri: uri,
33 api: v1.NewAPI(client),
34 timeout: timeout,
35 cache: cache,
36 lock: newPartitionLocker((&sync.Mutex{})),
37 }
38}