Skip to content

Commit

Permalink
replace node_exporter https package with exporter-toolkit
Browse files Browse the repository at this point in the history
The node_exporter/https package has been moved to exporter-toolkit as of
v1.1.0. weaveworks/common was still using this package, which was
preventing downstream importers (i.e., grafana/agent) from updating
their dependency on node_exporter.

This change also required bumping kuberesolver to v2.4.0 (the next
version after v2.1.0) which uses a newer version of the gRPC library
where type names have changed.

kuberesolver diff: sercand/kuberesolver@v2.1.0...v2.4.0
  • Loading branch information
rfratto committed Oct 22, 2021
1 parent c935aeb commit 56b8fa7
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 97 deletions.
14 changes: 7 additions & 7 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
node_https "github.com/prometheus/node_exporter/https"
"github.com/prometheus/exporter-toolkit/web"
"golang.org/x/net/context"
"golang.org/x/net/netutil"
"google.golang.org/grpc"
Expand Down Expand Up @@ -62,8 +62,8 @@ type Config struct {
GRPCListenPort int `yaml:"grpc_listen_port"`
GRPCConnLimit int `yaml:"grpc_listen_conn_limit"`

HTTPTLSConfig node_https.TLSStruct `yaml:"http_tls_config"`
GRPCTLSConfig node_https.TLSStruct `yaml:"grpc_tls_config"`
HTTPTLSConfig web.TLSStruct `yaml:"http_tls_config"`
GRPCTLSConfig web.TLSStruct `yaml:"grpc_tls_config"`

RegisterInstrumentation bool `yaml:"register_instrumentation"`
ExcludeRequestInLog bool `yaml:"-"`
Expand Down Expand Up @@ -210,16 +210,16 @@ func New(cfg Config) (*Server, error) {
// Setup TLS
var httpTLSConfig *tls.Config
if len(cfg.HTTPTLSConfig.TLSCertPath) > 0 && len(cfg.HTTPTLSConfig.TLSKeyPath) > 0 {
// Note: ConfigToTLSConfig from prometheus/node_exporter is awaiting security review.
httpTLSConfig, err = node_https.ConfigToTLSConfig(&cfg.HTTPTLSConfig)
// Note: ConfigToTLSConfig from prometheus/exporter-toolkit is awaiting security review.
httpTLSConfig, err = web.ConfigToTLSConfig(&cfg.HTTPTLSConfig)
if err != nil {
return nil, fmt.Errorf("error generating http tls config: %v", err)
}
}
var grpcTLSConfig *tls.Config
if len(cfg.GRPCTLSConfig.TLSCertPath) > 0 && len(cfg.GRPCTLSConfig.TLSKeyPath) > 0 {
// Note: ConfigToTLSConfig from prometheus/node_exporter is awaiting security review.
grpcTLSConfig, err = node_https.ConfigToTLSConfig(&cfg.GRPCTLSConfig)
// Note: ConfigToTLSConfig from prometheus/exporter-toolkit is awaiting security review.
grpcTLSConfig, err = web.ConfigToTLSConfig(&cfg.GRPCTLSConfig)
if err != nil {
return nil, fmt.Errorf("error generating grpc tls config: %v", err)
}
Expand Down
180 changes: 90 additions & 90 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
node_https "github.com/prometheus/node_exporter/https"
"github.com/prometheus/exporter-toolkit/web"
"github.com/stretchr/testify/require"
"github.com/weaveworks/common/httpgrpc"
"github.com/weaveworks/common/logging"
Expand Down Expand Up @@ -349,93 +349,93 @@ func TestHTTPInstrumentationMetrics(t *testing.T) {
server.Shutdown()

require.NoError(t, testutil.GatherAndCompare(prometheus.DefaultGatherer, bytes.NewBufferString(`
# HELP inflight_requests Current number of inflight requests.
# TYPE inflight_requests gauge
inflight_requests{method="POST",route="sleep10"} 0
inflight_requests{method="GET",route="succeed"} 0
inflight_requests{method="GET",route="error500"} 0
# HELP request_message_bytes Size (in bytes) of messages received in the request.
# TYPE request_message_bytes histogram
request_message_bytes_bucket{method="GET",route="error500",le="1.048576e+06"} 1
request_message_bytes_bucket{method="GET",route="error500",le="2.62144e+06"} 1
request_message_bytes_bucket{method="GET",route="error500",le="5.24288e+06"} 1
request_message_bytes_bucket{method="GET",route="error500",le="1.048576e+07"} 1
request_message_bytes_bucket{method="GET",route="error500",le="2.62144e+07"} 1
request_message_bytes_bucket{method="GET",route="error500",le="5.24288e+07"} 1
request_message_bytes_bucket{method="GET",route="error500",le="1.048576e+08"} 1
request_message_bytes_bucket{method="GET",route="error500",le="2.62144e+08"} 1
request_message_bytes_bucket{method="GET",route="error500",le="+Inf"} 1
request_message_bytes_sum{method="GET",route="error500"} 0
request_message_bytes_count{method="GET",route="error500"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+06"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+06"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="5.24288e+06"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+07"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+07"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="5.24288e+07"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+08"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+08"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="+Inf"} 1
request_message_bytes_sum{method="POST",route="sleep10"} 4
request_message_bytes_count{method="POST",route="sleep10"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+06"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+06"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="5.24288e+06"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+07"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+07"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="5.24288e+07"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+08"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+08"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="+Inf"} 1
request_message_bytes_sum{method="GET",route="succeed"} 0
request_message_bytes_count{method="GET",route="succeed"} 1
# HELP response_message_bytes Size (in bytes) of messages sent in response.
# TYPE response_message_bytes histogram
response_message_bytes_bucket{method="GET",route="error500",le="1.048576e+06"} 1
response_message_bytes_bucket{method="GET",route="error500",le="2.62144e+06"} 1
response_message_bytes_bucket{method="GET",route="error500",le="5.24288e+06"} 1
response_message_bytes_bucket{method="GET",route="error500",le="1.048576e+07"} 1
response_message_bytes_bucket{method="GET",route="error500",le="2.62144e+07"} 1
response_message_bytes_bucket{method="GET",route="error500",le="5.24288e+07"} 1
response_message_bytes_bucket{method="GET",route="error500",le="1.048576e+08"} 1
response_message_bytes_bucket{method="GET",route="error500",le="2.62144e+08"} 1
response_message_bytes_bucket{method="GET",route="error500",le="+Inf"} 1
response_message_bytes_sum{method="GET",route="error500"} 0
response_message_bytes_count{method="GET",route="error500"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+06"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+06"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="5.24288e+06"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+07"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+07"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="5.24288e+07"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+08"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+08"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="+Inf"} 1
response_message_bytes_sum{method="POST",route="sleep10"} 0
response_message_bytes_count{method="POST",route="sleep10"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+06"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+06"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="5.24288e+06"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+07"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+07"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="5.24288e+07"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+08"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+08"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="+Inf"} 1
response_message_bytes_sum{method="GET",route="succeed"} 2
response_message_bytes_count{method="GET",route="succeed"} 1
# HELP tcp_connections Current number of accepted TCP connections.
# TYPE tcp_connections gauge
tcp_connections{protocol="http"} 0
tcp_connections{protocol="grpc"} 0
`), "request_message_bytes", "response_message_bytes", "inflight_requests", "tcp_connections"))
# HELP inflight_requests Current number of inflight requests.
# TYPE inflight_requests gauge
inflight_requests{method="POST",route="sleep10"} 0
inflight_requests{method="GET",route="succeed"} 0
inflight_requests{method="GET",route="error500"} 0
# HELP request_message_bytes Size (in bytes) of messages received in the request.
# TYPE request_message_bytes histogram
request_message_bytes_bucket{method="GET",route="error500",le="1.048576e+06"} 1
request_message_bytes_bucket{method="GET",route="error500",le="2.62144e+06"} 1
request_message_bytes_bucket{method="GET",route="error500",le="5.24288e+06"} 1
request_message_bytes_bucket{method="GET",route="error500",le="1.048576e+07"} 1
request_message_bytes_bucket{method="GET",route="error500",le="2.62144e+07"} 1
request_message_bytes_bucket{method="GET",route="error500",le="5.24288e+07"} 1
request_message_bytes_bucket{method="GET",route="error500",le="1.048576e+08"} 1
request_message_bytes_bucket{method="GET",route="error500",le="2.62144e+08"} 1
request_message_bytes_bucket{method="GET",route="error500",le="+Inf"} 1
request_message_bytes_sum{method="GET",route="error500"} 0
request_message_bytes_count{method="GET",route="error500"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+06"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+06"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="5.24288e+06"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+07"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+07"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="5.24288e+07"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+08"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+08"} 1
request_message_bytes_bucket{method="POST",route="sleep10",le="+Inf"} 1
request_message_bytes_sum{method="POST",route="sleep10"} 4
request_message_bytes_count{method="POST",route="sleep10"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+06"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+06"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="5.24288e+06"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+07"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+07"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="5.24288e+07"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+08"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+08"} 1
request_message_bytes_bucket{method="GET",route="succeed",le="+Inf"} 1
request_message_bytes_sum{method="GET",route="succeed"} 0
request_message_bytes_count{method="GET",route="succeed"} 1
# HELP response_message_bytes Size (in bytes) of messages sent in response.
# TYPE response_message_bytes histogram
response_message_bytes_bucket{method="GET",route="error500",le="1.048576e+06"} 1
response_message_bytes_bucket{method="GET",route="error500",le="2.62144e+06"} 1
response_message_bytes_bucket{method="GET",route="error500",le="5.24288e+06"} 1
response_message_bytes_bucket{method="GET",route="error500",le="1.048576e+07"} 1
response_message_bytes_bucket{method="GET",route="error500",le="2.62144e+07"} 1
response_message_bytes_bucket{method="GET",route="error500",le="5.24288e+07"} 1
response_message_bytes_bucket{method="GET",route="error500",le="1.048576e+08"} 1
response_message_bytes_bucket{method="GET",route="error500",le="2.62144e+08"} 1
response_message_bytes_bucket{method="GET",route="error500",le="+Inf"} 1
response_message_bytes_sum{method="GET",route="error500"} 0
response_message_bytes_count{method="GET",route="error500"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+06"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+06"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="5.24288e+06"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+07"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+07"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="5.24288e+07"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="1.048576e+08"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="2.62144e+08"} 1
response_message_bytes_bucket{method="POST",route="sleep10",le="+Inf"} 1
response_message_bytes_sum{method="POST",route="sleep10"} 0
response_message_bytes_count{method="POST",route="sleep10"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+06"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+06"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="5.24288e+06"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+07"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+07"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="5.24288e+07"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="1.048576e+08"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="2.62144e+08"} 1
response_message_bytes_bucket{method="GET",route="succeed",le="+Inf"} 1
response_message_bytes_sum{method="GET",route="succeed"} 2
response_message_bytes_count{method="GET",route="succeed"} 1
# HELP tcp_connections Current number of accepted TCP connections.
# TYPE tcp_connections gauge
tcp_connections{protocol="http"} 0
tcp_connections{protocol="grpc"} 0
`), "request_message_bytes", "response_message_bytes", "inflight_requests", "tcp_connections"))
}

func TestRunReturnsError(t *testing.T) {
Expand Down Expand Up @@ -522,13 +522,13 @@ func TestTLSServer(t *testing.T) {
HTTPListenNetwork: DefaultNetwork,
HTTPListenAddress: "localhost",
HTTPListenPort: 9193,
HTTPTLSConfig: node_https.TLSStruct{
HTTPTLSConfig: web.TLSStruct{
TLSCertPath: "certs/server.crt",
TLSKeyPath: "certs/server.key",
ClientAuth: "RequireAndVerifyClientCert",
ClientCAs: "certs/root.crt",
},
GRPCTLSConfig: node_https.TLSStruct{
GRPCTLSConfig: web.TLSStruct{
TLSCertPath: "certs/server.crt",
TLSKeyPath: "certs/server.key",
ClientAuth: "VerifyClientCertIfGiven",
Expand Down

0 comments on commit 56b8fa7

Please sign in to comment.