MCPcopy Index your code
hub / github.com/cortexproject/cortex / SetRuleGroup

Method SetRuleGroup

integration/e2ecortex/client.go:820–852  ·  view source on GitHub ↗

SetRuleGroup configures the provided rulegroup to the ruler.

(rulegroup rulefmt.RuleGroup, namespace string)

Source from the content-addressed store, hash-verified

818
819// SetRuleGroup configures the provided rulegroup to the ruler.
820func (c *Client) SetRuleGroup(rulegroup rulefmt.RuleGroup, namespace string) error {
821 // Create write request
822 data, err := yaml.Marshal(rulegroup)
823 if err != nil {
824 return err
825 }
826
827 // Create HTTP request
828 req, err := http.NewRequest("POST", fmt.Sprintf("http://%s/api/prom/rules/%s", c.rulerAddress, url.PathEscape(namespace)), bytes.NewReader(data))
829 if err != nil {
830 return err
831 }
832
833 req.Header.Set("Content-Type", "application/yaml")
834 req.Header.Set("X-Scope-OrgID", c.orgID)
835
836 ctx, cancel := context.WithTimeout(context.Background(), c.timeout)
837 defer cancel()
838
839 // Execute HTTP request
840 res, err := c.httpClient.Do(req.WithContext(ctx))
841 if err != nil {
842 return err
843 }
844
845 defer res.Body.Close()
846
847 if res.StatusCode != 202 {
848 return fmt.Errorf("unexpected status code: %d", res.StatusCode)
849 }
850
851 return nil
852}
853
854// GetRuleGroup gets a rule group.
855func (c *Client) GetRuleGroup(namespace string, groupName string) (*http.Response, error) {

Calls 4

SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
MarshalMethod · 0.45