Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new monitor for Labeled Metric #154

Merged
merged 2 commits into from Apr 4, 2024

Conversation

mashiike
Copy link
Contributor

@mashiike mashiike commented Apr 2, 2024

In the current version, an error occurs when running the code below.

package main

import (
	"errors"
	"log"
	"os"

	"github.com/mackerelio/mackerel-client-go"
)

func main() {
	client := mackerel.NewClient(os.Getenv("MACKEREL_APIKEY"))
	monitor, err := client.GetMonitor(os.Getenv("MONITOR_ID")) // query monitor
	if err != nil {
		var apiError *mackerel.APIError
		if errors.As(err, &apiError) {
			log.Fatalf("API error: %#v", apiError)
		}
		log.Fatalf("%#v", err)
	}
	log.Printf("monitor: %v", monitor)
}
$ go run main.go 
2024/04/02 11:28:56 &mackerel.unknownMonitorTypeError{Type:"query"}
exit status 1

When I checked the API with Curl as shown below, it seemed to be able to be obtained successfully.

$  curl -H "X-Api-Key:$MACKEREL_APIKEY" https://api.mackerelio.com/api/v0/monitors/<monitor_id>
{"monitor":{"critical":300,"isMute":false,"legend":"","query":"test.my_counter","name":"my counter","warning":30,"id":"<monitor_id>","type":"query","operator":">"}}%     

Therefore, in this PR, we modified it to be compatible with query monitor.
By applying this PR, the execution result of the code at the beginning will be as follows.

$ go run main.go 
2024/04/02 11:27:47 monitor: &{<monitor_id> my counter  query false 0 test.my_counter > 0x1400018c4d0 0x1400018c4a8 }

Copy link
Member

@lufia lufia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@lufia lufia merged commit a304dae into mackerelio:master Apr 4, 2024
10 checks passed
@mashiike mashiike deleted the feature/get-query-monitor branch April 4, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants