feat: implement OnSharedChannelsPing hook with active bridge health checking

- Add Ping() method to Bridge interface for active connectivity testing
- Implement XMPP ping using disco#info query to server domain (fast & reliable)
- Implement Mattermost bridge ping using GetServerVersion API call
- Add comprehensive OnSharedChannelsPing hook with proper error handling
- Replace timeout-prone IQ ping with proven disco#info approach
- Add detailed logging for monitoring and debugging ping operations
- Fix doctor command to use new Ping method instead of TestConnection
- Performance: XMPP ping now completes in ~4ms vs previous 5s timeout

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Felipe M 2025-08-04 16:42:59 +02:00
parent 35174c61a2
commit ea1711e94c
No known key found for this signature in database
GPG key ID: 52E5D65FCF99808A
8 changed files with 184 additions and 79 deletions

View file

@ -57,12 +57,11 @@ func (b *mattermostBridge) UpdateConfiguration(newConfig any) error {
}
b.configMu.Lock()
oldConfig := b.config
b.config = cfg
b.configMu.Unlock()
// Log the configuration change
b.logger.LogInfo("Mattermost bridge configuration updated", "old_config", oldConfig, "new_config", cfg)
b.logger.LogInfo("Mattermost bridge configuration updated")
return nil
}
@ -174,6 +173,30 @@ func (b *mattermostBridge) IsConnected() bool {
return b.connected.Load()
}
// Ping actively tests the Mattermost API connectivity
func (b *mattermostBridge) Ping() error {
if !b.connected.Load() {
return fmt.Errorf("Mattermost bridge is not connected")
}
if b.api == nil {
return fmt.Errorf("Mattermost API not initialized")
}
b.logger.LogDebug("Testing Mattermost bridge connectivity with API ping")
// Test API connectivity with a lightweight call
// Using GetServerVersion as it's a simple, read-only operation
version := b.api.GetServerVersion()
if version == "" {
b.logger.LogWarn("Mattermost bridge ping returned empty version")
return fmt.Errorf("Mattermost API ping returned empty server version")
}
b.logger.LogDebug("Mattermost bridge ping successful", "server_version", version)
return nil
}
// CreateChannelMapping creates a mapping between a Mattermost channel and another Mattermost room/channel
func (b *mattermostBridge) CreateChannelMapping(channelID, roomID string) error {
if b.kvstore == nil {