Skip to content

Conversation

@Hemaphat
Copy link

This PR was created by Google Jules and tested locally

This commit introduces a new alerting provider for Google Chat,
allowing you to receive incident notifications in your Google Chat spaces.

Key changes include:

  • Addition of GoogleChatProvider in pkg/common/googlechat.go to handle
    message construction and sending via webhooks.
  • A new message template config/googlechat_message.tmpl using Google Chat's
    Cards V2 format, adapted from the Slack template to support various
    alert sources and include an 'Acknowledge' button.
  • Configuration updates in config/config.yaml and pkg/config/config.go
    to define settings for the Google Chat provider (webhook URL, template
    path, enable flag, message properties).
  • Integration into pkg/common/factory_alert.go to make the Google Chat
    provider available.
  • Documentation updates in README.md and src/userguide/configuration.md
    explaining how to configure and use the new integration.

This commit also includes:

  • Implementation of a simple logger in pkg/utils/logger.go and refactoring
    of GoogleChatProvider to use this centralized logger.
  • Addition of JSON helper functions (escapeJsonString, buildJsonArray,
    buildJsonObjectMembers) to pkg/utils/func_maps.go to ensure robust
    JSON generation in templates.
  • Updates to unit tests to verify these new utility functions and logging.

google-labs-jules bot and others added 3 commits May 27, 2025 07:03
This commit introduces a new alerting provider for Google Chat,
allowing you to receive incident notifications in your Google Chat spaces.

Key changes include:
- Addition of `GoogleChatProvider` in `pkg/common/googlechat.go` to handle
  message construction and sending via webhooks.
- A new message template `config/googlechat_message.tmpl` using Google Chat's
  Cards V2 format, adapted from the Slack template to support various
  alert sources and include an 'Acknowledge' button.
- Configuration updates in `config/config.yaml` and `pkg/config/config.go`
  to define settings for the Google Chat provider (webhook URL, template
  path, enable flag, message properties).
- Integration into `pkg/common/factory_alert.go` to make the Google Chat
  provider available.
- Documentation updates in `README.md` and `src/userguide/configuration.md`
  explaining how to configure and use the new integration.
- Comprehensive unit tests in `pkg/common/googlechat_test.go` for the
  `GoogleChatProvider`, covering successful alert sending for resolved and
  unresolved incidents, as well as error handling for HTTP and template issues.

The Google Chat integration supports rich formatting and interactive
acknowledgment buttons, providing feature parity with the existing Slack
integration.
This commit introduces a new alerting provider for Google Chat,
allowing you to receive incident notifications in your Google Chat spaces.

Key changes include:
- Addition of `GoogleChatProvider` in `pkg/common/googlechat.go` to handle
  message construction and sending via webhooks.
- A new message template `config/googlechat_message.tmpl` using Google Chat's
  Cards V2 format, adapted from the Slack template to support various
  alert sources and include an 'Acknowledge' button.
- Configuration updates in `config/config.yaml` and `pkg/config/config.go`
  to define settings for the Google Chat provider (webhook URL, template
  path, enable flag, message properties).
- Integration into `pkg/common/factory_alert.go` to make the Google Chat
  provider available.
- Documentation updates in `README.md` and `src/userguide/configuration.md`
  explaining how to configure and use the new integration.
- Comprehensive unit tests in `pkg/common/googlechat_test.go` for the
  `GoogleChatProvider`.

This commit also includes:
- Implementation of a simple logger in `pkg/utils/logger.go` and refactoring
  of `GoogleChatProvider` to use this centralized logger.
- Addition of JSON helper functions (`escapeJsonString`, `buildJsonArray`,
  `buildJsonObjectMembers`) to `pkg/utils/func_maps.go` to ensure robust
  JSON generation in templates.
- Updates to unit tests to verify these new utility functions and logging.

The Google Chat integration supports rich formatting and interactive
acknowledgment buttons, providing feature parity with the existing Slack
integration.
@hoalongnatsu
Copy link
Member

Hi @Hemaphat. Thank you for this PR. However, could you please show me an image of the Google Chat result? I have not used Google Chat before, so I am unsure how it looks with the template.

@hoalongnatsu
Copy link
Member

Could you please review this pull request and test it? @nghiadaulau

@Hemaphat
Copy link
Author

Hi @hoalongnatsu it look like this from example payload in readme.

Screenshot 2568-05-28 at 00 32 32

@kai-vikki
Copy link
Contributor

Could you please review this pull request and test it? @nghiadaulau

Oke, let's me check

@nghiadaulau
Copy link
Member

nghiadaulau commented May 28, 2025

Hi @Hemaphat
First of all, your google chat integration code seems to work quite well. It would be better if you take a screenshot of the result sent to Google Chat with a response example of a Grafana alert like the one I just sent. Please send it as a file (with a link attached) so that the admin can edit the README.

Next, I see you have implemented a logger in utils. I think the logger you should implement in the /pkg/logger folder.

In this folder, the interface for the logger will be implemented in a separate file. Then, other loggers will be created to implement the logger interface (There are many types of loggers such as Go's default logger, ZapLogger, GrayLogger,...)

Next I found in your logger you are using infoLogger: log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile) this will show when the log line printed will always show where the log function is called instead of where you call the logger. For example when I call in cmd/main.go instead of logging to cmd/main.go it logs to logger. I think it is more efficient to use log.Llongfile.

I suggest you use zaplogger for better future.

Example interface:

package logger

type Fields = map[string]interface{}

type LogLevel int

const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarning
	LogLevelError
	LogLevelFatal
)

func (l LogLevel) String() string {
	switch l {
	case LogLevelDebug:
		return "debug"
	case LogLevelInfo:
		return "info"
	case LogLevelWarning:
		return "warning"
	case LogLevelError:
		return "error"
	case LogLevelFatal:
		return "fatal"
	default:
		return "info"
	}
}

type Logger interface {
	Debugf(message string, args ...interface{})
	Infof(message string, args ...interface{})
	Warnf(message string, args ...interface{})
	Errorf(message string, args ...interface{})
	Fatalf(message string, args ...interface{})
	// add more field to log
	With(key string, value interface{}) Logger
	Withs(Fields) Logger
	GetLevel() string
	Sync()
}
Screenshot 2025-05-28 at 21 36 25

cc @hoalongnatsu

@nghiadaulau
Copy link
Member

It's even better if when you init the logger, you can pass in the log level and enable, to control when to log the entire body and when not.

func New...(level LogLevel, enable bool) Logger {
///
...
}

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.

4 participants