@@ -27,20 +27,19 @@ import (
2727 "github.com/cortexproject/cortex/pkg/ruler"
2828)
2929
30- var (
31- ErrNotFound = errors .New ("not found" )
32- )
30+ var ErrNotFound = errors .New ("not found" )
3331
3432// Client is a client used to interact with Cortex in integration tests
3533type Client struct {
36- alertmanagerClient promapi.Client
37- querierAddress string
38- rulerAddress string
39- distributorAddress string
40- timeout time.Duration
41- httpClient * http.Client
42- querierClient promv1.API
43- orgID string
34+ alertmanagerClient promapi.Client
35+ querierAddress string
36+ alertmanagerAddress string
37+ rulerAddress string
38+ distributorAddress string
39+ timeout time.Duration
40+ httpClient * http.Client
41+ querierClient promv1.API
42+ orgID string
4443}
4544
4645// NewClient makes a new Cortex client
@@ -61,13 +60,14 @@ func NewClient(
6160 }
6261
6362 c := & Client {
64- distributorAddress : distributorAddress ,
65- querierAddress : querierAddress ,
66- rulerAddress : rulerAddress ,
67- timeout : 5 * time .Second ,
68- httpClient : & http.Client {},
69- querierClient : promv1 .NewAPI (querierAPIClient ),
70- orgID : orgID ,
63+ distributorAddress : distributorAddress ,
64+ querierAddress : querierAddress ,
65+ alertmanagerAddress : alertmanagerAddress ,
66+ rulerAddress : rulerAddress ,
67+ timeout : 5 * time .Second ,
68+ httpClient : & http.Client {},
69+ querierClient : promv1 .NewAPI (querierAPIClient ),
70+ orgID : orgID ,
7171 }
7272
7373 if alertmanagerAddress != "" {
@@ -391,6 +391,32 @@ type userConfig struct {
391391 AlertmanagerConfig string `yaml:"alertmanager_config"`
392392}
393393
394+ // GetAlertmanagerStatusPage gets the status page of alertmanager.
395+ func (c * Client ) GetAlertmanagerStatusPage (ctx context.Context ) ([]byte , error ) {
396+ return c .getRawPage (ctx , "http://" + c .alertmanagerAddress + "/multitenant_alertmanager/status" )
397+ }
398+
399+ func (c * Client ) getRawPage (ctx context.Context , url string ) ([]byte , error ) {
400+ req , err := http .NewRequest (http .MethodGet , url , nil )
401+ if err != nil {
402+ return nil , err
403+ }
404+ resp , err := c .httpClient .Do (req .WithContext (ctx ))
405+ if err != nil {
406+ return nil , err
407+ }
408+ defer resp .Body .Close ()
409+
410+ content , err := ioutil .ReadAll (resp .Body )
411+ if err != nil {
412+ return nil , err
413+ }
414+ if resp .StatusCode / 100 != 2 {
415+ return nil , fmt .Errorf ("fetching page failed with status %d and content %v" , resp .StatusCode , string (content ))
416+ }
417+ return content , nil
418+ }
419+
394420// GetAlertmanagerConfig gets the status of an alertmanager instance
395421func (c * Client ) GetAlertmanagerConfig (ctx context.Context ) (* alertConfig.Config , error ) {
396422 u := c .alertmanagerClient .URL ("/api/prom/api/v1/status" , nil )
@@ -433,7 +459,6 @@ func (c *Client) SetAlertmanagerConfig(ctx context.Context, amConfig string, tem
433459 AlertmanagerConfig : amConfig ,
434460 TemplateFiles : templates ,
435461 })
436-
437462 if err != nil {
438463 return err
439464 }
0 commit comments