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

feat: Add support for Prometheus AlertManager #89

Merged
merged 5 commits into from
Jul 15, 2024

Conversation

strahe
Copy link
Contributor

@strahe strahe commented Jul 12, 2024

#83

Added support for the Prometheus AlertManager, resulting in a change to the configuration file format:

Previously:

type CurioAlerting struct {
    // PagerDutyEventURL is the URL for PagerDuty.com Events API v2. Events sent to this API URL are ultimately
    // routed to a PagerDuty.com service and processed.
    // The default is sufficient for integration with the stock commercial PagerDuty.com company's service.
    PagerDutyEventURL string

    // PageDutyIntegrationKey is the integration key for a PagerDuty.com service. You can find this unique service
    // identifier on the integration page for the service.
    PageDutyIntegrationKey string

    // MinimumWalletBalance is the minimum balance for all active wallets. If the balance is below this value, an
    // alert will be triggered for the wallet.
    MinimumWalletBalance types.FIL
}

Now:

type CurioAlertingConfig struct {
    // MinimumWalletBalance is the minimum balance for all active wallets. If the balance is below this value, an
    // alert will be triggered for the wallet.
    MinimumWalletBalance types.FIL

    // PagerDutyConfig is the configuration for the PagerDuty alerting integration.
    PagerDuty PagerDutyConfig

    // PrometheusAlertManagerConfig is the configuration for the Prometheus AlertManager alerting integration.
    PrometheusAlertManager PrometheusAlertManagerConfig
}

type PagerDutyConfig struct {
	// Enable is a flag to enable or disable the PagerDuty integration.
	Enable bool

	// PagerDutyEventURL is URL for PagerDuty.com Events API v2 URL. Events sent to this API URL are ultimately
	// routed to a PagerDuty.com service and processed.
	// The default is sufficient for integration with the stock commercial PagerDuty.com company's service.
	PagerDutyEventURL string

	// PageDutyIntegrationKey is the integration key for a PagerDuty.com service. You can find this unique service
	// identifier in the integration page for the service.
	PageDutyIntegrationKey string
}

type PrometheusAlertManagerConfig struct {
	// Enable is a flag to enable or disable the Prometheus AlertManager integration.
	Enable bool

	// AlertManagerURL is the URL for the Prometheus AlertManager API v2 URL.
	AlertManagerURL string
}

@strahe strahe force-pushed the feat/prometheus-alertmanager branch from ad84607 to a7bb438 Compare July 12, 2024 06:07
@strahe
Copy link
Contributor Author

strahe commented Jul 12, 2024

Hi, @LexLuthr, this pr is ready for review

Copy link
Contributor

@LexLuthr LexLuthr left a comment

Choose a reason for hiding this comment

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

Code looks good!
I would ask if you could add a doc like https://github.com/filecoin-project/curio/blob/main/harmony/harmonytask/doc.go detailing how to add new plugins? I think it would be really helpful for others who might want to add another one.
Also, can you please test this and attach screenshots of prometheus alert?

@strahe strahe force-pushed the feat/prometheus-alertmanager branch from 5125b90 to 644d09e Compare July 15, 2024 03:52
@strahe
Copy link
Contributor Author

strahe commented Jul 15, 2024

cfg := config.PrometheusAlertManagerConfig{
	Enable:          true,
	AlertManagerURL: "http://10.122.6.17:9093/api/v2/alerts",
}
ap := plugin.NewPrometheusAlertManager(cfg)
err := ap.SendAlert(&plugin.AlertPayload{
	Time:     time.Now(),
	Severity: "critical",
	Source:   "curio",
	Summary:  "Curio Alert",
	Details: map[string]interface{}{
		"test": "test",
	},
})

In Prometheus Alertmanager:

image

Copy link
Contributor

@LexLuthr LexLuthr left a comment

Choose a reason for hiding this comment

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

Great job!! Thank you for the contribution.

@LexLuthr LexLuthr merged commit 147a77e into filecoin-project:main Jul 15, 2024
1 check passed
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.

2 participants