Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Promxy] Update promxy on recent prometheus and add native histogram support #696

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.21-alpine3.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.22-alpine3.20 as builder

ARG BUILDPLATFORM
ARG TARGETARCH
Expand Down
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*")
GOFMT ?= gofmt
GOIMPORTS ?= goimports -local=github.com/jacksontj/promxy
STATICCHECK ?= staticcheck
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_REVISION := $(shell git rev-parse --short HEAD)
IMAGE_TAG ?= $(subst /,-,$(GIT_BRANCH))-$(GIT_REVISION)

.PHONY: clean
clean:
Expand Down Expand Up @@ -31,16 +34,20 @@ release:
./build.bash github.com/jacksontj/promxy/cmd/promxy $(BUILD)
./build.bash github.com/jacksontj/promxy/cmd/remote_write_exporter $(BUILD)

.PHONY: build-image
build-image: clean
docker buildx build --load --platform linux/amd64 --build-arg revision=$(GIT_REVISION) -t promxy:latest -t promxy:$(IMAGE_TAG) .

testlocal-build:
docker build -t 127.0.0.1:32000/promxy:latest .
docker push 127.0.0.1:32000/promxy:latest

.PHONY: vendor
vendor:
GO111MODULE=on $(GO) mod tidy -compat=1.20
GO111MODULE=on $(GO) mod tidy -compat=1.22
GO111MODULE=on $(GO) mod vendor

.PHONY: update-prom-fork
update-prom-fork:
GO111MODULE=on $(GO) mod edit -replace github.com/prometheus/prometheus=github.com/jacksontj/prometheus@v0.2.37.5-fork
GO111MODULE=on $(GO) mod edit -replace github.com/prometheus/prometheus=github.com/rishabhkumar92/prometheus@vrishabhk-promxy-upgrade
$(MAKE) vendor
2 changes: 1 addition & 1 deletion cmd/promxy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ test-local:
go build -race -mod=vendor -tags netgo,builtinassets && ./promxy --http.shutdown-delay=0s --config=local_test.conf --web.external-url=http://localhost:8082/promxy --log-level=debug

version:
go build -race -mod=vendor -tags netgo,builtinassets && ./promxy --version
go build -race -mod=readonly -tags netgo,builtinassets && ./promxy --version
91 changes: 29 additions & 62 deletions cmd/promxy/config.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,64 @@
##
## Regular prometheus configuration
##
global:
evaluation_interval: 5s
external_labels:
source: promxy

# Uncomment below section to enable evaluation interval.
#global:
# evaluation_interval: 5s
# external_labels:
# source: promxy

# Rule files specifies a list of globs. Rules and alerts are read from
# all matching files.
rule_files:
- "*rule"
# all matching files. Uncomment below section to enable.

#rule_files:
# - "*rule"

# Alerting specifies settings related to the Alertmanager.
alerting:
alertmanagers:
- scheme: http
static_configs:
- targets:
- "127.0.0.1:12345"
# Alerting specifies settings related to the Alertmanager. Uncomment below section to enable.

#alerting:
# alertmanagers:
# - scheme: http
# static_configs:
# - targets:
# - "127.0.0.1:12345"

# remote_write configuration is used by promxy as its local Appender, meaning all
# metrics promxy would "write" (not export) would be sent to this. Examples
# of this include: recording rules, metrics on alerting rules, etc.
remote_write:
- url: http://localhost:8083/receive
# of this include: recording rules, metrics on alerting rules, etc. Uncomment below section to enable.

#remote_write:
# - url: http://localhost:8083/receive

##
### Promxy configuration
##
promxy:
# In below examples, point 8000 & 8001 to prometheus servers.
server_groups:
# All upstream prometheus service discovery mechanisms are supported with the same
# markup, all defined in https://github.com/prometheus/prometheus/blob/master/discovery/config/config.go#L33
- static_configs:
- targets:
- localhost:9090
- localhost:8000
# labels to be added to metrics retrieved from this server_group
labels:
sg: localhost_9090
sg: localhost_8000
# anti-affinity for merging values in timeseries between hosts in the server_group
anti_affinity: 10s
# time to wait for a server's response headers after fully writing the request (including its body, if any).
# This time does not include the time to read the response body.
timeout: 5s
# Controls whether to use remote_read or the prom API for fetching remote RAW data (e.g. matrix selectors)
# Note, some prometheus implementations (e.g. [VictoriaMetrics](https://github.com/prometheus/prometheus/issues/4456) don't support remote_read.
remote_read: true
remote_read: false
# configures the path to send remote read requests to. The default is "api/v1/read"
remote_read_path: api/v1/read
# path_prefix defines a prefix to prepend to all queries to hosts in this servergroup
# This can be relabeled using __path_prefix__
path_prefix: /example/prefix
path_prefix: /prometheus
# query_params adds the following map of query parameters to downstream requests.
# The initial use-case for this is to add `nocache=1` to VictoriaMetrics downstreams
# (see https://github.com/jacksontj/promxy/issues/202)
query_params:
nocache: 1
# configures the protocol scheme used for requests. Defaults to http
scheme: http
# options for promxy's HTTP client when talking to hosts in server_groups
http_client:
Expand All @@ -65,40 +67,5 @@ promxy:
dial_timeout: 1s
tls_config:
insecure_skip_verify: true

# relative_time_range defines a relative-to-now time range that this server group contains.
# this is completely optional and start/end are both optional as well
# an example is if this servergroup only has the most recent 3h of data
# the "start" would be -3h and the end would be left out
relative_time_range:
start: -3h
end: -1h
truncate: false

# when merging sample streams, the max value at a given timestamp will be preferred
prefer_max: false

# absolute_time_range defines an absolute time range that this server group contains.
# this is completely optional and start/end are both optional as well
# and example is if the servergroup has been deprecated and is no longer receiving data
# you could set the specific times that it has data for.
absolute_time_range:
start: '2009-10-10T23:00:00Z'
end: '2009-10-11T23:00:00Z'
truncate: true

# as many additional server groups as you have
- static_configs:
- targets:
- localhost:9091
labels:
sg: localhost_9091
anti_affinity: 10s
scheme: http
http_client:
tls_config:
insecure_skip_verify: true
# ignore_error will make the given server group's response "optional"
# meaning if this servergroup returns and error and others don't the overall
# query can still succeed
ignore_error: true
# make response as optional
ignore_error: false
37 changes: 19 additions & 18 deletions cmd/promxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net"
"net/http"
_ "net/http/pprof"
"net/url"
"os"
"os/signal"
Expand All @@ -16,18 +17,16 @@ import (
"syscall"
"time"

_ "net/http/pprof"

kitlog "github.com/go-kit/log"
"github.com/golang/glog"
"github.com/grafana/regexp"
"github.com/jessevdk/go-flags"
"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus"
collectorVersion "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promslog"
"github.com/prometheus/common/version"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/discovery"
Expand Down Expand Up @@ -70,7 +69,7 @@ var (
)

func init() {
prometheus.MustRegister(version.NewCollector("promxy"))
prometheus.MustRegister(collectorVersion.NewCollector("promxy"))
}

type cliOpts struct {
Expand Down Expand Up @@ -109,7 +108,7 @@ type cliOpts struct {
ResendDelay time.Duration `long:"rules.alert.resend-delay" description:"Minimum amount of time to wait before resending an alert to Alertmanager." default:"1m"`
AlertBackfill bool `long:"rules.alertbackfill" description:"Enable promxy to recalculate alert state on startup when the downstream datastore doesn't have an ALERTS_FOR_STATE"`

ShutdownDelay time.Duration `long:"http.shutdown-delay" description:"time to wait before shutting down the http server, this allows for a grace period for upstreams (e.g. LoadBalancers) to discover the new stopping status through healthchecks" default:"10s"`
ShutdownDelay time.Duration `long:"http.shutdown-delay" description:"time to wait before shutting down the http server, this allows for a grace period for upstreams (e.g. LoadBalancers) to discover the new stopping status through healthchecks" default:"1s"`
ShutdownTimeout time.Duration `long:"http.shutdown-timeout" description:"max time to wait for a graceful shutdown of the HTTP server" default:"60s"`
}

Expand Down Expand Up @@ -238,15 +237,15 @@ func main() {
reloadables = append(reloadables, ps)
proxyStorage = ps

logCfg := &promlog.Config{
Level: &promlog.AllowedLevel{},
Format: &promlog.AllowedFormat{},
logCfg := &promslog.Config{
Level: &promslog.AllowedLevel{},
Format: &promslog.AllowedFormat{},
}
if err := logCfg.Level.Set("info"); err != nil {
logrus.Fatalf("Unable to set log level: %v", err)
}

logger := promlog.New(logCfg)
logger := promslog.New(logCfg)

engineOpts := promql.EngineOpts{
Reg: prometheus.DefaultRegisterer,
Expand All @@ -265,7 +264,7 @@ func main() {
if opts.LocalStoragePath == "" {
logrus.Fatalf("local storage path must be defined if you wish to enable max query concurrency limits")
}
engineOpts.ActiveQueryTracker = promql.NewActiveQueryTracker(opts.LocalStoragePath, opts.QueryMaxConcurrency, kitlog.With(logger, "component", "activeQueryTracker"))
engineOpts.ActiveQueryTracker = promql.NewActiveQueryTracker(opts.LocalStoragePath, opts.QueryMaxConcurrency, logger.With("component", "activeQueryTracker"))
}

engine := promql.NewEngine(engineOpts)
Expand All @@ -282,11 +281,11 @@ func main() {
Registerer: prometheus.DefaultRegisterer,
QueueCapacity: opts.NotificationQueueCapacity,
},
kitlog.With(logger, "component", "notifier"),
logger.With("component", "notifier"),
)
reloadables = append(reloadables, proxyconfig.WrapPromReloadable(notifierManager))

discoveryManagerNotify := discovery.NewManager(ctx, kitlog.With(logger, "component", "discovery manager notify"))
discoveryManagerNotify := discovery.NewManager(ctx, logger.With("component", "discovery manager notify"), prometheus.DefaultRegisterer, nil, discovery.Name("notify"))

reloadables = append(reloadables,
proxyconfig.WrapPromReloadable(&proxyconfig.ApplyConfigFunc{func(cfg *config.Config) error {
Expand Down Expand Up @@ -387,7 +386,8 @@ func main() {
}}))

// We need an empty scrape manager, simply to make the API not panic and error out
scrapeManager := scrape.NewManager(nil, kitlog.With(logger, "component", "scrape manager"), nil)
scrapeManager, _ := scrape.NewManager(nil, logger.With("component", "scrape manager"), nil, proxyStorage, prometheus.DefaultRegisterer)
listenAddresses := []string{opts.BindAddr}

webOptions := &web.Options{
Registerer: prometheus.DefaultRegisterer,
Expand All @@ -406,9 +406,10 @@ func main() {

EnableLifecycle: opts.EnableLifecycle,

Flags: opts.ToFlags(),
RoutePrefix: opts.RoutePrefix,
ExternalURL: externalUrl,
Flags: opts.ToFlags(),
ListenAddresses: listenAddresses,
RoutePrefix: opts.RoutePrefix,
ExternalURL: externalUrl,
Version: &web.PrometheusVersion{
Version: version.Version,
Revision: version.Revision,
Expand All @@ -433,7 +434,7 @@ func main() {

webHandler := web.New(logger, webOptions)
reloadables = append(reloadables, proxyconfig.WrapPromReloadable(webHandler))
webHandler.SetReady(true)
webHandler.SetReady(web.Ready)

apiPrefix := path.Join(webOptions.RoutePrefix, "/api/v1")
// Register API endpoint with correct route prefix
Expand Down
Loading