Merge pull request #1 from valitydev/ft/TD-74

TD-74::add filter to show pod's url in kibana
This commit is contained in:
Ivan Martynyuk 2022-02-17 10:48:48 +03:00 committed by GitHub
commit 9b3a8b128f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 8 deletions

View File

@ -55,3 +55,6 @@ communications:
webhook:
enabled: false
url: 'WEBHOOK_URL' # e.g https://example.com:80
podLogsDashboard:
url: "KIBANA_URL" # url with '%s' to fill it with pod name, e.g. https://kibana-url.com/?query:(language:kuery,query:'kubernetes.pod.name:%20%22%s%22')

View File

@ -132,12 +132,13 @@ type Namespaces struct {
// CommunicationsConfig channels to send events to
type CommunicationsConfig struct {
Slack Slack
Mattermost Mattermost
Discord Discord
Webhook Webhook
Teams Teams
ElasticSearch ElasticSearch
Slack Slack
Mattermost Mattermost
Discord Discord
Webhook Webhook
Teams Teams
ElasticSearch ElasticSearch
PodLogsDashboard PodLogsDashboard
}
// Slack configuration to authentication and send notifications
@ -211,6 +212,12 @@ type Webhook struct {
URL string
}
// PodLogsDashboard configuration containing URL template with pod name mask
//to fill and send if errors occurred
type PodLogsDashboard struct {
URL string
}
// Kubectl configuration for executing commands inside cluster
type Kubectl struct {
Enabled bool

View File

@ -55,6 +55,7 @@ type Event struct {
Recommendations []string
Warnings []string
LogsUrlMsg string
}
// LevelMap is a map of event type to Level

View File

@ -0,0 +1,54 @@
package filters
import (
"fmt"
"github.com/infracloudio/botkube/pkg/config"
"github.com/infracloudio/botkube/pkg/events"
"github.com/infracloudio/botkube/pkg/filterengine"
"github.com/infracloudio/botkube/pkg/log"
"github.com/infracloudio/botkube/pkg/utils"
coreV1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"reflect"
)
const (
Message = "You can see your pod's errors in kibana:"
)
type DeployErrorsChecker struct {
Description string
}
func (d DeployErrorsChecker) Run(object interface{}, event *events.Event) {
if event.Kind != "Pod" || event.Type != config.ErrorEvent {
return
}
commConfig, confErr := config.NewCommunicationsConfig()
if confErr != nil {
log.Errorf("Error in loading configuration. %s", confErr.Error())
return
}
if commConfig == nil {
log.Errorf("Error in loading configuration.")
return
}
var podObj coreV1.Pod
err := utils.TransformIntoTypedObject(object.(*unstructured.Unstructured), &podObj)
if err != nil {
log.Errorf("Unable to transform object type: %v, into type: %v", reflect.TypeOf(object), reflect.TypeOf(podObj))
}
searchUrlTemplate := commConfig.Communications.PodLogsDashboard.URL
event.LogsUrlMsg = fmt.Sprintf(Message+"[LOGS URL]("+searchUrlTemplate+")", podObj.Name)
}
func (d DeployErrorsChecker) Describe() string {
return d.Description
}
// Register filter
func init() {
filterengine.DefaultFilterEngine.Register(DeployErrorsChecker{
Description: "Checks if errors occurred while deployment and adds link to kibana for that pod.",
})
}

View File

@ -22,12 +22,11 @@ package notify
import (
"encoding/json"
"fmt"
"strconv"
"github.com/infracloudio/botkube/pkg/config"
"github.com/infracloudio/botkube/pkg/events"
"github.com/infracloudio/botkube/pkg/log"
"github.com/nlopes/slack"
"strconv"
)
var attachmentColor = map[config.Level]string{
@ -317,6 +316,9 @@ func FormatShortMessage(event events.Event) (msg string) {
}
}
if len(event.LogsUrlMsg) > 0 {
msg += fmt.Sprintf("\n%s", event.LogsUrlMsg)
}
// Add message in the attachment if there is any
if len(additionalMsg) > 0 {
msg += fmt.Sprintf("```\n%s```", additionalMsg)