Skip to content

Commit 7ae2d0b

Browse files
author
Ganesh Vernekar
committed
Fix most of Peter's comments
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
1 parent 60337a3 commit 7ae2d0b

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

development/tsdb-blocks-storage-s3/config/cortex.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ alertmanager:
8888
enable_api: true
8989
sharding_enabled: true
9090
sharding_ring:
91-
replication_factor: 1
91+
replication_factor: 3
9292
heartbeat_period: 5s
9393
heartbeat_timeout: 15s
9494
kvstore:

development/tsdb-blocks-storage-s3/docker-compose.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,48 @@ services:
215215
volumes:
216216
- ./config:/cortex/config
217217

218-
alertmanager:
218+
alertmanager-1:
219219
build:
220220
context: .
221221
dockerfile: dev.dockerfile
222222
image: cortex
223-
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18010 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=alertmanager -server.http-listen-port=8010 -server.grpc-listen-port=9010 -alertmanager.web.external-url=localhost:8010"]
223+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18031 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=alertmanager -server.http-listen-port=8031 -server.grpc-listen-port=9031 -alertmanager.web.external-url=localhost:8031"]
224224
depends_on:
225225
- consul
226226
- minio
227227
ports:
228-
- 8010:8010
229-
- 18010:18010
228+
- 8031:8031
229+
- 18031:18031
230+
volumes:
231+
- ./config:/cortex/config
232+
233+
alertmanager-2:
234+
build:
235+
context: .
236+
dockerfile: dev.dockerfile
237+
image: cortex
238+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18032 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=alertmanager -server.http-listen-port=8032 -server.grpc-listen-port=9032 -alertmanager.web.external-url=localhost:8032"]
239+
depends_on:
240+
- consul
241+
- minio
242+
ports:
243+
- 8032:8032
244+
- 18032:18032
245+
volumes:
246+
- ./config:/cortex/config
247+
248+
alertmanager-3:
249+
build:
250+
context: .
251+
dockerfile: dev.dockerfile
252+
image: cortex
253+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18033 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=alertmanager -server.http-listen-port=8033 -server.grpc-listen-port=9033 -alertmanager.web.external-url=localhost:8033"]
254+
depends_on:
255+
- consul
256+
- minio
257+
ports:
258+
- 8033:8033
259+
- 18033:18033
230260
volumes:
231261
- ./config:/cortex/config
232262

pkg/alertmanager/alertmanager_client.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ func newAlertmanagerClientsPool(discovery client.PoolServiceDiscovery, amClientC
6464
}
6565

6666
requestDuration := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
67-
Namespace: "cortex",
68-
Name: "alertmanager_distributor_client_request_duration_seconds",
69-
Help: "Time spent executing requests from an alertmanager to another alertmanager.",
70-
Buckets: prometheus.ExponentialBuckets(0.008, 4, 7),
71-
ConstLabels: prometheus.Labels{"client": "alertmanager"},
67+
Name: "cortex_alertmanager_distributor_client_request_duration_seconds",
68+
Help: "Time spent executing requests from an alertmanager to another alertmanager.",
69+
Buckets: prometheus.ExponentialBuckets(0.008, 4, 7),
7270
}, []string{"operation", "status_code"})
7371

7472
factory := func(addr string) (client.PoolClient, error) {

pkg/alertmanager/distributor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ func (d *Distributor) doWrite(userID string, w http.ResponseWriter, r *http.Requ
145145
respondFromHTTPGRPCResponse(w, firstSuccessfulResponse)
146146
} else {
147147
// This should not happen.
148-
level.Warn(logger).Log("msg", "distributor did not receive response from alertmanager though no errors")
149-
w.WriteHeader(http.StatusOK)
148+
level.Error(logger).Log("msg", "distributor did not receive response from alertmanager though no errors")
149+
w.WriteHeader(http.StatusInternalServerError)
150150
}
151151
}
152152

pkg/alertmanager/multitenant.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,15 @@ type MultitenantAlertmanager struct {
237237
cfg *MultitenantAlertmanagerConfig
238238

239239
// Ring used for sharding alertmanager instances.
240+
// When sharding is disabled, the flow is:
241+
// ServeHTTP() -> serveRequest()
242+
// When sharding is enabled:
243+
// ServeHTTP() -> distributor.DistributeRequest() -> (sends to other AM or even the current)
244+
// -> HandleRequest() (gRPC call) -> grpcServer() -> handlerForGRPCServer.ServeHTTP() -> serveRequest().
240245
ringLifecycler *ring.BasicLifecycler
241246
ring *ring.Ring
242247
distributor *Distributor
248+
grpcServer *server.Server
243249

244250
// Subservices manager (ring, lifecycler)
245251
subservices *services.Manager
@@ -265,7 +271,6 @@ type MultitenantAlertmanager struct {
265271
peer *cluster.Peer
266272

267273
// For distributor.
268-
grpcServer *server.Server
269274

270275
registry prometheus.Registerer
271276
ringCheckErrors prometheus.Counter
@@ -428,12 +433,14 @@ func createMultitenantAlertmanager(cfg *MultitenantAlertmanagerConfig, fallbackC
428433
return am, nil
429434
}
430435

436+
// handlerForGRPCServer acts as a handler for gRPC server to serve
437+
// the serveRequest() via the standard ServeHTTP.
431438
type handlerForGRPCServer struct {
432439
am *MultitenantAlertmanager
433440
}
434441

435442
func (h *handlerForGRPCServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
436-
h.am.serveHTTPHelper(w, req)
443+
h.am.serveRequest(w, req)
437444
}
438445

439446
func (am *MultitenantAlertmanager) starting(ctx context.Context) (err error) {
@@ -770,16 +777,16 @@ func (am *MultitenantAlertmanager) ServeHTTP(w http.ResponseWriter, req *http.Re
770777

771778
// If sharding is not enabled or Distributor does not support this path,
772779
// it is served by this instance.
773-
am.serveHTTPHelper(w, req)
780+
am.serveRequest(w, req)
774781
}
775782

776-
// HandleRequest serves the Alertmanager's web UI and API sent via gRPC.
783+
// HandleRequest implements gRPC Alertmanager service, which receives request from AlertManager-Distributor.
777784
func (am *MultitenantAlertmanager) HandleRequest(ctx context.Context, in *httpgrpc.HTTPRequest) (*httpgrpc.HTTPResponse, error) {
778785
return am.grpcServer.Handle(ctx, in)
779786
}
780787

781-
// serveHTTPHelper serves the Alertmanager's web UI and API.
782-
func (am *MultitenantAlertmanager) serveHTTPHelper(w http.ResponseWriter, req *http.Request) {
788+
// serveRequest serves the Alertmanager's web UI and API.
789+
func (am *MultitenantAlertmanager) serveRequest(w http.ResponseWriter, req *http.Request) {
783790
userID, err := tenant.TenantID(req.Context())
784791
if err != nil {
785792
http.Error(w, err.Error(), http.StatusUnauthorized)

0 commit comments

Comments
 (0)