Skip to content

Commit

Permalink
use ckit/httpgrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
rfratto committed Jan 14, 2022
1 parent 9927bfa commit 86a6d76
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 74 deletions.
2 changes: 2 additions & 0 deletions cmd/agent/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ func (ep *Entrypoint) ApplyConfig(cfg config.Config) error {
// wire is used to hook up API endpoints to components, and is called every
// time a new Weaveworks server is creatd.
func (ep *Entrypoint) wire(mux *mux.Router, grpc *grpc.Server) {
ep.cluster.Wire(mux, grpc)

ep.promMetrics.WireAPI(mux)
ep.promMetrics.WireGRPC(grpc)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require (
github.com/prometheus/procfs v0.7.4-0.20211011103944-1a7a2bd3279f
github.com/prometheus/prometheus v1.8.2-0.20211102100715-d4c83da6d252
github.com/prometheus/statsd_exporter v0.22.2
github.com/rfratto/ckit v0.0.0-20220114170145-e8a57aa35a61
github.com/rfratto/ckit v0.0.0-20220114184126-aeebd522ec88
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2078,10 +2078,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qq
github.com/renier/xmlrpc v0.0.0-20170708154548-ce4a1a486c03 h1:Wdi9nwnhFNAlseAOekn6B5G/+GMtks9UKbvRU/CMM/o=
github.com/renier/xmlrpc v0.0.0-20170708154548-ce4a1a486c03/go.mod h1:gRAiPF5C5Nd0eyyRdqIu9qTiFSoZzpTq727b5B8fkkU=
github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc=
github.com/rfratto/ckit v0.0.0-20210903030023-721309d48f1e h1:lnBT2XlgGKkJA3YSpcqmcmEZrHVNryCHj5xQZfNBk14=
github.com/rfratto/ckit v0.0.0-20210903030023-721309d48f1e/go.mod h1:woq/KwrCx3v4/0TbrM0XpyaDT+05hrWDYMTR4Nnc97U=
github.com/rfratto/ckit v0.0.0-20220114170145-e8a57aa35a61 h1:DEBpspNdwyo2PQePID1DifS2d8RnTxl/6HhDM7LTAaI=
github.com/rfratto/ckit v0.0.0-20220114170145-e8a57aa35a61/go.mod h1:+dNhReGTs5VbDKP80jkmXc8vgIXEpN4g22Rc0eBID5I=
github.com/rfratto/ckit v0.0.0-20220114184126-aeebd522ec88 h1:+vI6UJsZ51V05tz+8rDTm169kDCkH3ukr+eYvY7sRJw=
github.com/rfratto/ckit v0.0.0-20220114184126-aeebd522ec88/go.mod h1:k96zanEnWkeGCt9KJUNY23aMfUXdWbvMi+7zVNpjzJQ=
github.com/rfratto/go-yaml v0.0.0-20211119180816-77389c3526dc h1:g196Usc63pWDzWallipxVhsEjDdh/+RLc/Oz7q3ihW4=
github.com/rfratto/go-yaml v0.0.0-20211119180816-77389c3526dc/go.mod h1:rMzeXFmWpS5JnfDANtpzbklRJY4pqZMJNN9/SJHAXPA=
github.com/rgeyer/github-exporter v0.0.0-20210722215637-d0cec2ee0dc8 h1:wNuNGrFzFmZlhrtz1Q8EiK1Ob6yWli8lX7D2AGmSGzE=
Expand Down
9 changes: 9 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/gorilla/mux"
"github.com/grafana/dskit/flagext"
"github.com/hashicorp/go-discover"
"github.com/hashicorp/go-discover/provider/k8s"
"github.com/rfratto/ckit"
"github.com/rfratto/ckit/advertise"
"github.com/rfratto/ckit/chash"
"github.com/rfratto/ckit/httpgrpc"
"google.golang.org/grpc"
)

// ErrClusterDisabled is returned when performing a cluster operation when the
Expand Down Expand Up @@ -197,6 +200,12 @@ func (n *Node) OnPeersChanged(w PeersChangedWatcher) {
n.watchers = append(n.watchers, w)
}

// Wire connects HTTP and gRPC services.
func (n *Node) Wire(mux *mux.Router, grpc *grpc.Server) { // nolint:interfacer
// Allow nodes to talk to each other over ckit/httpgrpc.
httpgrpc.Serve(grpc, mux)
}

// Start starts the node. If it was configured to join any peers, it will join
// them now. This will also invoke any PeersChangedWatchers to inform them that
// peers are joining.
Expand Down
66 changes: 0 additions & 66 deletions pkg/cluster/httpclient/httpclient.go

This file was deleted.

5 changes: 2 additions & 3 deletions pkg/metrics/v2/metrics_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/grafana/agent/pkg/cluster/httpclient"
"github.com/grafana/agent/pkg/metrics/cluster/configapi"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/rfratto/ckit"
"github.com/weaveworks/common/httpgrpc"
"github.com/rfratto/ckit/httpgrpc"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -89,7 +88,7 @@ func queryPeer(ctx context.Context, p *ckit.Peer, endpoint string, v interface{}
return fmt.Errorf("failed to connect to peer %q: %w", p.Name, err)
}

cli := http.Client{Transport: httpclient.RoundTripper{Client: httpgrpc.NewHTTPClient(cc)}}
cli := http.Client{Transport: httpgrpc.ClientTransport(cc)}
url := fmt.Sprintf("http://%s%s", p.ApplicationAddr, endpoint)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
Expand Down

0 comments on commit 86a6d76

Please sign in to comment.