github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/hooks/hooks.go (about) 1 package hooks 2 3 import ( 4 htmltemplate "html/template" 5 texttemplate "text/template" 6 7 "github.com/fasthttp/router" 8 commonconfig "github.com/siglens/siglens/pkg/config/common" 9 "github.com/siglens/siglens/pkg/utils" 10 "github.com/valyala/fasthttp" 11 ) 12 13 type Hooks struct { 14 StartupHook func() 15 HtmlSnippets HtmlSnippets 16 JsSnippets JsSnippets 17 18 // Startup 19 ServeStaticHook func(router *router.Router, htmlTemplate *htmltemplate.Template) 20 ParseTemplatesHook func(htmlTemplate *htmltemplate.Template, textTemplate *texttemplate.Template) 21 CheckLicenseHook func() 22 CheckOrgValidityHook func() 23 AfterConfigHook func(baseLogDir string) 24 ValidateDeploymentHook func() (commonconfig.DeploymentType, error) 25 GetNodeIdHook func() string 26 ExtractConfigHook func(yamlData []byte) (commonconfig.Configuration, error) 27 LogConfigHook func() 28 StartSiglensExtrasHook func(nodeID string) error 29 30 // Cluster health 31 IngestStatsHandlerHook func(ctx *fasthttp.RequestCtx, myid uint64) 32 StatsHandlerHook func(ctx *fasthttp.RequestCtx, myid uint64) 33 SetExtraIngestionStatsHook func(map[string]interface{}) 34 MiddlewareExtractOrgIdHook func(ctx *fasthttp.RequestCtx) (uint64, error) 35 AddMultinodeStatsHook func(indexData map[string]utils.ResultPerIndex, orgId uint64, 36 logsIncomingBytes *float64, logsOnDiskBytes *float64, logsEventCount *int64, 37 metricsIncomingBytes *uint64, metricsOnDiskBytes *uint64, metricsDatapointsCount *uint64, 38 queryCount *uint64, totalResponseTime *float64) 39 40 // Retention 41 ExtraRetentionCleanerHook func() error 42 InternalRetentionCleanerHook1 func() string 43 InternalRetentionCleanerHook2 func(string, int) 44 45 // Usage stats 46 GetQueryCountHook func() 47 WriteUsageStatsIfConditionHook func() bool 48 WriteUsageStatsElseExtraLogicHook func() 49 ForceFlushIfConditionHook func() bool 50 51 // Blobstore 52 InitBlobStoreExtrasHook func() (bool, error) 53 UploadSegmentFilesExtrasHook func(allFiles []string) (bool, error) 54 UploadIngestNodeExtrasHook func() (bool, error) 55 UploadQueryNodeExtrasHook func() (bool, error) 56 DeleteBlobExtrasHook func(filepath string) (bool, error) 57 DownloadAllIngestNodesDirExtrasHook func() (bool, error) 58 DownloadAllQueryNodesDirExtrasHook func() (bool, error) 59 DownloadSegmentBlobExtrasHook func(filename string) (bool, error) 60 GetFileSizeExtrasHook func(filename string) (bool, uint64) 61 DoesMetaFileExistExtrasHook func(filename string) (bool, bool, error) 62 63 // Server helpers 64 GetOrgIdHookQuery func(ctx *fasthttp.RequestCtx) (uint64, error) 65 GetOrgIdHook func(ctx *fasthttp.RequestCtx) (uint64, error) 66 ExtractKibanaRequestsHook func(kibanaIndices []string, qid uint64) map[string]interface{} 67 68 // Ingest server 69 IngestMiddlewareRecoveryHook func(ctx *fasthttp.RequestCtx) error 70 KibanaIngestHandlerHook func(ctx *fasthttp.RequestCtx) 71 GetIdsConditionHook func(ids []uint64) bool 72 ExtraIngestEndpointsHook func(router *router.Router, recovery func(next func(ctx *fasthttp.RequestCtx)) func(ctx *fasthttp.RequestCtx)) 73 74 // Query server 75 QueryMiddlewareRecoveryHook func(ctx *fasthttp.RequestCtx) error 76 ExtraQueryEndpointsHook func(router *router.Router, recovery func(next func(ctx *fasthttp.RequestCtx)) func(ctx *fasthttp.RequestCtx)) error 77 78 // Query summary 79 ShouldAddDistributedInfoHook func() bool 80 } 81 82 type HtmlSnippets struct { 83 RunCheck1 string 84 RunCheck2 string 85 RunCheck3 string 86 Button1 string 87 Popup1 string 88 89 OrgSettingsOrgName string 90 OrgSettingsRetentionPeriod string 91 OrgSettingsExtras string 92 93 Constants map[string]interface{} 94 } 95 96 type JsSnippets struct { 97 ClusterStatsExtraFunctions string 98 ClusterStatsExtraSetup string 99 ClusterStatsSetUserRole string 100 ClusterStatsAdminView string 101 ClusterStatsAdminButton string 102 ClusterStatsCallDisplayRows string 103 104 CommonExtraFunctions string 105 Button1Function string 106 107 SettingsExtraOnReadySetup string 108 SettingsRetentionDataThenBlock string 109 SettingsExtraFunctions string 110 111 TestDataSendData string 112 113 OrgUpperNavTabs string 114 OrgUpperNavUrls string 115 } 116 117 var GlobalHooks = Hooks{ 118 ParseTemplatesHook: func(htmlTemplate *htmltemplate.Template, textTemplate *texttemplate.Template) { 119 *htmlTemplate = *htmltemplate.Must(htmlTemplate.ParseGlob("./static/*.html")) 120 *textTemplate = *texttemplate.Must(textTemplate.ParseGlob("./static/js/*.js")) 121 }, 122 }