| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2017-02-15 21:29:20 +08:00
										 |  |  | 	"crypto/tls" | 
					
						
							| 
									
										
										
										
											2020-11-19 20:34:28 +08:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2017-04-27 14:54:21 +08:00
										 |  |  | 	"net" | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	"net/http" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"path" | 
					
						
							| 
									
										
										
										
											2020-10-19 23:35:31 +08:00
										 |  |  | 	"path/filepath" | 
					
						
							| 
									
										
										
										
											2021-02-16 00:55:41 +08:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 	"sync" | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-02 21:52:30 +08:00
										 |  |  | 	"github.com/prometheus/client_golang/prometheus" | 
					
						
							|  |  |  | 	"github.com/prometheus/client_golang/prometheus/promhttp" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-06 10:56:17 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/api/avatar" | 
					
						
							| 
									
										
										
										
											2019-01-16 21:53:59 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/api/routing" | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	httpstatic "github.com/grafana/grafana/pkg/api/static" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/bus" | 
					
						
							| 
									
										
										
										
											2017-04-25 23:17:45 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/components/simplejson" | 
					
						
							| 
									
										
										
										
											2022-12-13 18:03:36 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/db" | 
					
						
							| 
									
										
										
										
											2022-06-15 20:59:40 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/kvstore" | 
					
						
							| 
									
										
										
										
											2019-06-13 16:55:38 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/localcache" | 
					
						
							| 
									
										
										
										
											2019-05-13 14:45:54 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/log" | 
					
						
							| 
									
										
										
										
											2019-04-08 19:31:46 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/remotecache" | 
					
						
							| 
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/tracing" | 
					
						
							| 
									
										
										
										
											2022-04-05 02:36:15 +08:00
										 |  |  | 	loginpkg "github.com/grafana/grafana/pkg/login" | 
					
						
							| 
									
										
										
										
											2021-08-31 01:39:55 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/login/social" | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/middleware" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/middleware/csrf" | 
					
						
							| 
									
										
										
										
											2021-03-22 20:22:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/plugins" | 
					
						
							| 
									
										
										
										
											2023-01-27 22:08:17 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/plugins/pluginscdn" | 
					
						
							| 
									
										
											  
											
												Reconcile coremodels, entities, objects under new kind framework (#56492)
* Update thema to latest
* Deal with s/Library/*Runtime/
* Commit new, working results of codegen
* We like pointers now
* Always take runtime arg for NewBase()
* Sketchy handwavy pass at entity meta framework
* Little nibbles
* Update pkg/framework/coremodel/entityframework.cue
Co-authored-by: Artur Wierzbicki <wierzbicki.artur.94@gmail.com>
* Move file into new framework location
* Introduce loaders, Go code
* Complete rename to kind
* Flesh out framework, add svg/dashboard examples
* Cruft removal
* Remove generated kind go files from gitignore
* Refine maturity concept, add SlotKind
* Update embed and go deps
* Export PrefixWithGrafanaCUE
* Make the loader actually work, holy crap
* Many small tweaks to type.cue
* Add Apache 2 licensing exceptions for kinds
* Add new kinds dir, start of generator
* Roll back to earlier oapi-codegen
* Introduce new grafana-specific CUE loaders
* Introduce new tidy code generators framework
* Catch up kind framework with tinkering
* Add slices for the generators
* Add write/verify step to main generator
* Many renames
* Split up kind framework cue files
* Use kind.Decl within generated kinds
* Create kind.SomeDecl wrapper type to cache lineages
* Better names again
* Get one generated implemented, hopefully
* Copy dashboard schema into new kind.cue
* Small fixes to make the initial gen work
* Put svg kind in its new home
* Add generated Go dashboard type
* More renames and cleanups
* Add base kind registry and generator
* Stop blacklisting *_gen.go files
This is not the Go best practice, anyway. All we actually want to ignore
for enterprise is generated wire files.
* Change codegen output directories
pkg/kind -> pkg/kinds
pkg/registry/kindreg -> pkg/registry/corekind
* Rename pkg/framework/kind to pkg/kindsys
* Add core structured kind generator
* Add plural and machine names to kind spec
* Copy playlist over to kind system
* Consolidate kindsys files
* Add raw kind generator
* Update CODEOWNERS for kind framework
* Touch up comments a bit
* More docs tweaks
* Remove generated types to reduce noise for review
* Split each generator into its own file
* Rename Slot kind to Composable kind
* Add handwavy types for customkind loading
* Guard against init calls to framework loader
* First pass at doc on extending the kind system
* Improve attribute example in docs
* Fix wire imports
* Add basic TS types generator
* Fix composable kind category def
* No need for a separate file with generate directive
* Catch dashboard schema up
* Rename generator types to something saner and generic
* Make version configurable in ts/go generators
* Add CommonMeta to ease property access
* Add kindsys prop indicating whether lineage is group
* Put all kind categories back in a single file
* Finish with kindsys group props
* Refactor maturity progression per discussion
- Replace "committed" with "merged"
- All kindcats can use all maturity levels, at least for now
* Convert ts veneer index generator to modular system
* Move over to new jennywrites framework
* Strip down old coremodel generator
* Use public version of jennywrites
* Pull latest thema
* Commit generated Go types
* Add header injection postprocessor
* Move sdboyer/jennywrites to grafana/codejen
* Tweak header output
* Remove dashboard and playlist coremodels
* Fix up backend dashboards devenv test
* Fix TS import patterns to new gen filename
* Update internal imports, remove coremodel registry
* Fix compilation errors, wire generation
* Export and replace the prefix dropper
* More Go struct and field name changes
* Last name fixes, hopefully
* Fix lint errors
* Last lint error
Co-authored-by: Artur Wierzbicki <wierzbicki.artur.94@gmail.com>
											
										 
											2022-11-11 04:36:40 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/registry/corekind" | 
					
						
							| 
									
										
										
										
											2021-04-06 21:49:09 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/accesscontrol" | 
					
						
							| 
									
										
										
										
											2021-03-22 20:22:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/alerting" | 
					
						
							| 
									
										
										
										
											2022-09-19 15:54:37 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/annotations" | 
					
						
							| 
									
										
										
										
											2022-08-02 22:55:19 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/apikey" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/auth" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/services/authn" | 
					
						
							| 
									
										
										
										
											2021-08-31 01:39:55 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/cleanup" | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/contexthandler" | 
					
						
							| 
									
										
										
										
											2022-08-30 02:44:55 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/correlations" | 
					
						
							| 
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/dashboards" | 
					
						
							| 
									
										
										
										
											2022-02-17 16:31:26 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/dashboardsnapshots" | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	dashver "github.com/grafana/grafana/pkg/services/dashboardversion" | 
					
						
							| 
									
										
										
										
											2021-03-18 01:10:40 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/datasourceproxy" | 
					
						
							| 
									
										
										
										
											2018-10-26 16:40:33 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/datasources" | 
					
						
							| 
									
										
										
										
											2022-02-28 16:54:56 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/datasources/permissions" | 
					
						
							| 
									
										
										
										
											2021-08-31 01:39:55 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/encryption" | 
					
						
							| 
									
										
										
										
											2022-01-27 01:44:20 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/featuremgmt" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/folder" | 
					
						
							| 
									
										
										
										
											2018-10-12 17:26:42 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/hooks" | 
					
						
							| 
									
										
										
										
											2021-08-31 01:39:55 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/libraryelements" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/services/librarypanels" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/licensing" | 
					
						
							| 
									
										
										
										
											2021-03-22 20:22:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/live" | 
					
						
							| 
									
										
										
										
											2021-04-26 18:17:49 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/live/pushhttp" | 
					
						
							| 
									
										
										
										
											2019-06-13 22:47:52 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/login" | 
					
						
							| 
									
										
										
										
											2022-09-02 00:08:42 +08:00
										 |  |  | 	loginAttempt "github.com/grafana/grafana/pkg/services/loginattempt" | 
					
						
							| 
									
										
										
										
											2022-09-23 04:04:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/navtree" | 
					
						
							| 
									
										
										
										
											2021-08-31 01:39:55 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/ngalert" | 
					
						
							| 
									
										
										
										
											2022-02-03 17:33:46 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/notifications" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/oauthtoken" | 
					
						
							| 
									
										
										
										
											2022-08-24 01:26:21 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/org" | 
					
						
							| 
									
										
										
										
											2022-07-18 17:26:35 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/playlist" | 
					
						
							| 
									
										
										
										
											2022-03-11 01:38:04 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/plugindashboards" | 
					
						
							| 
									
										
										
										
											2023-03-08 00:22:30 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/pluginsintegration/plugincontext" | 
					
						
							|  |  |  | 	pluginSettings "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginsettings" | 
					
						
							| 
									
										
										
										
											2022-04-21 21:03:17 +08:00
										 |  |  | 	pref "github.com/grafana/grafana/pkg/services/preference" | 
					
						
							| 
									
										
										
										
											2020-03-25 21:14:24 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/provisioning" | 
					
						
							| 
									
										
										
										
											2022-07-07 07:51:44 +08:00
										 |  |  | 	publicdashboardsApi "github.com/grafana/grafana/pkg/services/publicdashboards/api" | 
					
						
							| 
									
										
										
										
											2022-01-26 22:48:41 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/query" | 
					
						
							| 
									
										
										
										
											2022-01-29 00:55:09 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/queryhistory" | 
					
						
							| 
									
										
										
										
											2022-08-30 02:44:55 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/quota" | 
					
						
							| 
									
										
										
										
											2018-05-24 21:26:27 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/rendering" | 
					
						
							| 
									
										
										
										
											2021-03-22 20:22:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/search" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/searchV2" | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/searchusers" | 
					
						
							| 
									
										
										
										
											2021-11-05 00:47:21 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/secrets" | 
					
						
							| 
									
										
										
										
											2022-08-30 02:44:55 +08:00
										 |  |  | 	secretsKV "github.com/grafana/grafana/pkg/services/secrets/kvstore" | 
					
						
							| 
									
										
										
										
											2022-08-25 04:24:50 +08:00
										 |  |  | 	spm "github.com/grafana/grafana/pkg/services/secrets/kvstore/migrations" | 
					
						
							| 
									
										
										
										
											2022-01-26 22:48:41 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/serviceaccounts" | 
					
						
							| 
									
										
										
										
											2021-03-22 20:22:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/shorturls" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/services/sqlstore" | 
					
						
							| 
									
										
										
										
											2022-05-19 20:32:10 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/star" | 
					
						
							| 
									
										
										
										
											2023-01-25 22:58:54 +08:00
										 |  |  | 	starApi "github.com/grafana/grafana/pkg/services/star/api" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/stats" | 
					
						
							| 
									
										
										
										
											2022-03-18 01:19:23 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/store" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/store/entity/httpentitystore" | 
					
						
							| 
									
										
										
										
											2022-09-21 20:04:01 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/tag" | 
					
						
							| 
									
										
										
										
											2022-09-21 00:58:04 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/team" | 
					
						
							| 
									
										
										
										
											2022-01-07 20:38:00 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/teamguardian" | 
					
						
							| 
									
										
										
										
											2022-08-13 00:13:23 +08:00
										 |  |  | 	tempUser "github.com/grafana/grafana/pkg/services/temp_user" | 
					
						
							| 
									
										
										
										
											2022-01-26 22:48:41 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/thumbs" | 
					
						
							| 
									
										
										
										
											2021-11-01 17:53:33 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/updatechecker" | 
					
						
							| 
									
										
										
										
											2022-07-16 00:06:44 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/user" | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/validations" | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/setting" | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/web" | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-23 05:13:46 +08:00
										 |  |  | type HTTPServer struct { | 
					
						
							| 
									
										
										
										
											2022-01-24 21:41:18 +08:00
										 |  |  | 	log              log.Logger | 
					
						
							|  |  |  | 	web              *web.Mux | 
					
						
							|  |  |  | 	context          context.Context | 
					
						
							|  |  |  | 	httpSrv          *http.Server | 
					
						
							|  |  |  | 	middlewares      []web.Handler | 
					
						
							|  |  |  | 	namedMiddlewares []routing.RegisterNamedMiddleware | 
					
						
							| 
									
										
										
										
											2022-06-14 22:07:41 +08:00
										 |  |  | 	bus              bus.Bus | 
					
						
							| 
									
										
										
										
											2017-02-06 16:40:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	PluginContextProvider        *plugincontext.Provider | 
					
						
							|  |  |  | 	RouteRegister                routing.RouteRegister | 
					
						
							|  |  |  | 	RenderService                rendering.Service | 
					
						
							|  |  |  | 	Cfg                          *setting.Cfg | 
					
						
							|  |  |  | 	Features                     *featuremgmt.FeatureManager | 
					
						
							|  |  |  | 	SettingsProvider             setting.Provider | 
					
						
							|  |  |  | 	HooksService                 *hooks.HooksService | 
					
						
							| 
									
										
										
										
											2022-09-23 04:04:48 +08:00
										 |  |  | 	navTreeService               navtree.Service | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	CacheService                 *localcache.CacheService | 
					
						
							|  |  |  | 	DataSourceCache              datasources.CacheService | 
					
						
							| 
									
										
										
										
											2022-11-18 16:56:06 +08:00
										 |  |  | 	AuthTokenService             auth.UserTokenService | 
					
						
							| 
									
										
										
										
											2022-07-16 00:06:44 +08:00
										 |  |  | 	QuotaService                 quota.Service | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	RemoteCacheService           *remotecache.RemoteCache | 
					
						
							|  |  |  | 	ProvisioningService          provisioning.ProvisioningService | 
					
						
							|  |  |  | 	Login                        login.Service | 
					
						
							| 
									
										
										
										
											2023-01-24 00:53:43 +08:00
										 |  |  | 	License                      licensing.Licensing | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	AccessControl                accesscontrol.AccessControl | 
					
						
							|  |  |  | 	DataProxy                    *datasourceproxy.DataSourceProxyService | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	PluginRequestValidator       validations.PluginRequestValidator | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	pluginClient                 plugins.Client | 
					
						
							|  |  |  | 	pluginStore                  plugins.Store | 
					
						
							| 
									
										
										
										
											2022-09-23 20:27:01 +08:00
										 |  |  | 	pluginInstaller              plugins.Installer | 
					
						
							| 
									
										
										
										
											2023-03-29 18:55:55 +08:00
										 |  |  | 	pluginFileStore              plugins.FileStore | 
					
						
							| 
									
										
										
										
											2022-03-11 01:38:04 +08:00
										 |  |  | 	pluginDashboardService       plugindashboards.Service | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	pluginStaticRouteResolver    plugins.StaticRouteResolver | 
					
						
							|  |  |  | 	pluginErrorResolver          plugins.ErrorResolver | 
					
						
							|  |  |  | 	SearchService                search.Service | 
					
						
							|  |  |  | 	ShortURLService              shorturls.Service | 
					
						
							|  |  |  | 	QueryHistoryService          queryhistory.Service | 
					
						
							| 
									
										
										
										
											2022-07-25 22:19:07 +08:00
										 |  |  | 	CorrelationsService          correlations.Service | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	Live                         *live.GrafanaLive | 
					
						
							|  |  |  | 	LivePushGateway              *pushhttp.Gateway | 
					
						
							|  |  |  | 	ThumbService                 thumbs.Service | 
					
						
							| 
									
										
										
										
											2022-07-29 14:26:44 +08:00
										 |  |  | 	StorageService               store.StorageService | 
					
						
							| 
									
										
										
										
											2022-12-01 05:42:42 +08:00
										 |  |  | 	httpEntityStore              httpentitystore.HTTPEntityStore | 
					
						
							| 
									
										
										
										
											2022-09-23 07:02:09 +08:00
										 |  |  | 	SearchV2HTTPService          searchV2.SearchHTTPService | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	ContextHandler               *contexthandler.ContextHandler | 
					
						
							| 
									
										
										
										
											2022-12-13 18:03:36 +08:00
										 |  |  | 	SQLStore                     db.DB | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	AlertEngine                  *alerting.AlertEngine | 
					
						
							|  |  |  | 	AlertNG                      *ngalert.AlertNG | 
					
						
							|  |  |  | 	LibraryPanelService          librarypanels.Service | 
					
						
							|  |  |  | 	LibraryElementService        libraryelements.Service | 
					
						
							|  |  |  | 	SocialService                social.Service | 
					
						
							|  |  |  | 	Listener                     net.Listener | 
					
						
							|  |  |  | 	EncryptionService            encryption.Internal | 
					
						
							|  |  |  | 	SecretsService               secrets.Service | 
					
						
							| 
									
										
										
										
											2022-08-11 03:47:03 +08:00
										 |  |  | 	secretsPluginManager         plugins.SecretsPluginManager | 
					
						
							| 
									
										
										
										
											2022-08-30 02:44:55 +08:00
										 |  |  | 	secretsStore                 secretsKV.SecretsKVStore | 
					
						
							|  |  |  | 	secretsMigrator              secrets.Migrator | 
					
						
							| 
									
										
										
										
											2022-09-07 03:21:25 +08:00
										 |  |  | 	secretsPluginMigrator        spm.SecretMigrationProvider | 
					
						
							| 
									
										
										
										
											2022-02-11 22:52:14 +08:00
										 |  |  | 	DataSourcesService           datasources.DataSourceService | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	cleanUpService               *cleanup.CleanUpService | 
					
						
							|  |  |  | 	tracer                       tracing.Tracer | 
					
						
							|  |  |  | 	grafanaUpdateChecker         *updatechecker.GrafanaService | 
					
						
							|  |  |  | 	pluginsUpdateChecker         *updatechecker.PluginsService | 
					
						
							|  |  |  | 	searchUsersService           searchusers.Service | 
					
						
							|  |  |  | 	teamGuardian                 teamguardian.TeamGuardian | 
					
						
							| 
									
										
										
										
											2023-03-17 02:39:17 +08:00
										 |  |  | 	queryDataService             query.Service | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	serviceAccountsService       serviceaccounts.Service | 
					
						
							|  |  |  | 	authInfoService              login.AuthInfoService | 
					
						
							| 
									
										
										
										
											2022-04-05 02:36:15 +08:00
										 |  |  | 	authenticator                loginpkg.Authenticator | 
					
						
							| 
									
										
										
										
											2022-05-10 21:48:47 +08:00
										 |  |  | 	teamPermissionsService       accesscontrol.TeamPermissionsService | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 	NotificationService          *notifications.NotificationService | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 	DashboardService             dashboards.DashboardService | 
					
						
							| 
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 |  |  | 	dashboardProvisioningService dashboards.DashboardProvisioningService | 
					
						
							| 
									
										
										
										
											2022-10-11 03:47:53 +08:00
										 |  |  | 	folderService                folder.Service | 
					
						
							| 
									
										
										
										
											2022-02-28 16:54:56 +08:00
										 |  |  | 	DatasourcePermissionsService permissions.DatasourcePermissionsService | 
					
						
							| 
									
										
										
										
											2022-02-17 01:54:29 +08:00
										 |  |  | 	AlertNotificationService     *alerting.AlertNotificationService | 
					
						
							| 
									
										
										
										
											2022-06-15 01:41:29 +08:00
										 |  |  | 	dashboardsnapshotsService    dashboardsnapshots.Service | 
					
						
							| 
									
										
										
										
											2022-09-09 15:44:50 +08:00
										 |  |  | 	PluginSettings               pluginSettings.Service | 
					
						
							| 
									
										
										
										
											2022-04-06 10:56:17 +08:00
										 |  |  | 	AvatarCacheServer            *avatar.AvatarCacheServer | 
					
						
							| 
									
										
										
										
											2022-04-21 21:03:17 +08:00
										 |  |  | 	preferenceService            pref.Service | 
					
						
							| 
									
										
										
										
											2022-06-02 21:52:30 +08:00
										 |  |  | 	Csrf                         csrf.Service | 
					
						
							| 
									
										
										
										
											2022-05-10 21:48:47 +08:00
										 |  |  | 	folderPermissionsService     accesscontrol.FolderPermissionsService | 
					
						
							|  |  |  | 	dashboardPermissionsService  accesscontrol.DashboardPermissionsService | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	dashboardVersionService      dashver.Service | 
					
						
							| 
									
										
										
										
											2022-07-07 07:51:44 +08:00
										 |  |  | 	PublicDashboardsApi          *publicdashboardsApi.Api | 
					
						
							| 
									
										
										
										
											2022-05-19 20:32:10 +08:00
										 |  |  | 	starService                  star.Service | 
					
						
							| 
									
										
											  
											
												Reconcile coremodels, entities, objects under new kind framework (#56492)
* Update thema to latest
* Deal with s/Library/*Runtime/
* Commit new, working results of codegen
* We like pointers now
* Always take runtime arg for NewBase()
* Sketchy handwavy pass at entity meta framework
* Little nibbles
* Update pkg/framework/coremodel/entityframework.cue
Co-authored-by: Artur Wierzbicki <wierzbicki.artur.94@gmail.com>
* Move file into new framework location
* Introduce loaders, Go code
* Complete rename to kind
* Flesh out framework, add svg/dashboard examples
* Cruft removal
* Remove generated kind go files from gitignore
* Refine maturity concept, add SlotKind
* Update embed and go deps
* Export PrefixWithGrafanaCUE
* Make the loader actually work, holy crap
* Many small tweaks to type.cue
* Add Apache 2 licensing exceptions for kinds
* Add new kinds dir, start of generator
* Roll back to earlier oapi-codegen
* Introduce new grafana-specific CUE loaders
* Introduce new tidy code generators framework
* Catch up kind framework with tinkering
* Add slices for the generators
* Add write/verify step to main generator
* Many renames
* Split up kind framework cue files
* Use kind.Decl within generated kinds
* Create kind.SomeDecl wrapper type to cache lineages
* Better names again
* Get one generated implemented, hopefully
* Copy dashboard schema into new kind.cue
* Small fixes to make the initial gen work
* Put svg kind in its new home
* Add generated Go dashboard type
* More renames and cleanups
* Add base kind registry and generator
* Stop blacklisting *_gen.go files
This is not the Go best practice, anyway. All we actually want to ignore
for enterprise is generated wire files.
* Change codegen output directories
pkg/kind -> pkg/kinds
pkg/registry/kindreg -> pkg/registry/corekind
* Rename pkg/framework/kind to pkg/kindsys
* Add core structured kind generator
* Add plural and machine names to kind spec
* Copy playlist over to kind system
* Consolidate kindsys files
* Add raw kind generator
* Update CODEOWNERS for kind framework
* Touch up comments a bit
* More docs tweaks
* Remove generated types to reduce noise for review
* Split each generator into its own file
* Rename Slot kind to Composable kind
* Add handwavy types for customkind loading
* Guard against init calls to framework loader
* First pass at doc on extending the kind system
* Improve attribute example in docs
* Fix wire imports
* Add basic TS types generator
* Fix composable kind category def
* No need for a separate file with generate directive
* Catch dashboard schema up
* Rename generator types to something saner and generic
* Make version configurable in ts/go generators
* Add CommonMeta to ease property access
* Add kindsys prop indicating whether lineage is group
* Put all kind categories back in a single file
* Finish with kindsys group props
* Refactor maturity progression per discussion
- Replace "committed" with "merged"
- All kindcats can use all maturity levels, at least for now
* Convert ts veneer index generator to modular system
* Move over to new jennywrites framework
* Strip down old coremodel generator
* Use public version of jennywrites
* Pull latest thema
* Commit generated Go types
* Add header injection postprocessor
* Move sdboyer/jennywrites to grafana/codejen
* Tweak header output
* Remove dashboard and playlist coremodels
* Fix up backend dashboards devenv test
* Fix TS import patterns to new gen filename
* Update internal imports, remove coremodel registry
* Fix compilation errors, wire generation
* Export and replace the prefix dropper
* More Go struct and field name changes
* Last name fixes, hopefully
* Fix lint errors
* Last lint error
Co-authored-by: Artur Wierzbicki <wierzbicki.artur.94@gmail.com>
											
										 
											2022-11-11 04:36:40 +08:00
										 |  |  | 	Kinds                        *corekind.Base | 
					
						
							| 
									
										
										
										
											2022-07-18 17:26:35 +08:00
										 |  |  | 	playlistService              playlist.Service | 
					
						
							| 
									
										
										
										
											2022-08-02 22:55:19 +08:00
										 |  |  | 	apiKeyService                apikey.Service | 
					
						
							| 
									
										
										
										
											2022-06-15 20:59:40 +08:00
										 |  |  | 	kvStore                      kvstore.KVStore | 
					
						
							| 
									
										
										
										
											2023-01-27 22:08:17 +08:00
										 |  |  | 	pluginsCDNService            *pluginscdn.Service | 
					
						
							| 
									
										
										
										
											2022-08-30 02:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-01 04:45:41 +08:00
										 |  |  | 	userService            user.Service | 
					
						
							|  |  |  | 	tempUserService        tempUser.Service | 
					
						
							| 
									
										
										
										
											2022-09-27 20:46:03 +08:00
										 |  |  | 	dashboardThumbsService thumbs.DashboardThumbService | 
					
						
							| 
									
										
										
										
											2022-09-01 04:45:41 +08:00
										 |  |  | 	loginAttemptService    loginAttempt.Service | 
					
						
							|  |  |  | 	orgService             org.Service | 
					
						
							| 
									
										
										
										
											2022-09-21 00:58:04 +08:00
										 |  |  | 	teamService            team.Service | 
					
						
							| 
									
										
										
										
											2022-09-01 04:45:41 +08:00
										 |  |  | 	accesscontrolService   accesscontrol.Service | 
					
						
							| 
									
										
										
										
											2022-09-19 15:54:37 +08:00
										 |  |  | 	annotationsRepo        annotations.Repository | 
					
						
							| 
									
										
										
										
											2022-09-21 20:04:01 +08:00
										 |  |  | 	tagService             tag.Service | 
					
						
							| 
									
										
										
										
											2022-10-19 00:17:28 +08:00
										 |  |  | 	oauthTokenService      oauthtoken.OAuthTokenService | 
					
						
							| 
									
										
										
										
											2022-12-01 01:11:07 +08:00
										 |  |  | 	statsService           stats.Service | 
					
						
							| 
									
										
										
										
											2023-01-17 16:11:45 +08:00
										 |  |  | 	authnService           authn.Service | 
					
						
							| 
									
										
										
										
											2023-01-25 22:58:54 +08:00
										 |  |  | 	starApi                *starApi.API | 
					
						
							| 
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type ServerOptions struct { | 
					
						
							|  |  |  | 	Listener net.Listener | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-14 22:07:41 +08:00
										 |  |  | func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routing.RouteRegister, bus bus.Bus, | 
					
						
							| 
									
										
										
										
											2023-01-24 00:53:43 +08:00
										 |  |  | 	renderService rendering.Service, licensing licensing.Licensing, hooksService *hooks.HooksService, | 
					
						
							| 
									
										
										
										
											2021-11-29 21:21:54 +08:00
										 |  |  | 	cacheService *localcache.CacheService, sqlStore *sqlstore.SQLStore, alertEngine *alerting.AlertEngine, | 
					
						
							| 
									
										
										
										
											2023-01-24 04:10:14 +08:00
										 |  |  | 	pluginRequestValidator validations.PluginRequestValidator, pluginStaticRouteResolver plugins.StaticRouteResolver, | 
					
						
							| 
									
										
										
										
											2022-03-11 01:38:04 +08:00
										 |  |  | 	pluginDashboardService plugindashboards.Service, pluginStore plugins.Store, pluginClient plugins.Client, | 
					
						
							| 
									
										
										
										
											2022-09-23 20:27:01 +08:00
										 |  |  | 	pluginErrorResolver plugins.ErrorResolver, pluginInstaller plugins.Installer, settingsProvider setting.Provider, | 
					
						
							| 
									
										
										
										
											2022-11-18 16:56:06 +08:00
										 |  |  | 	dataSourceCache datasources.CacheService, userTokenService auth.UserTokenService, | 
					
						
							| 
									
										
										
										
											2022-07-25 22:19:07 +08:00
										 |  |  | 	cleanUpService *cleanup.CleanUpService, shortURLService shorturls.Service, queryHistoryService queryhistory.Service, correlationsService correlations.Service, | 
					
						
							| 
									
										
										
										
											2022-01-29 00:55:09 +08:00
										 |  |  | 	thumbService thumbs.Service, remoteCache *remotecache.RemoteCache, provisioningService provisioning.ProvisioningService, | 
					
						
							| 
									
										
										
										
											2022-04-05 02:36:15 +08:00
										 |  |  | 	loginService login.Service, authenticator loginpkg.Authenticator, accessControl accesscontrol.AccessControl, | 
					
						
							| 
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 |  |  | 	dataSourceProxy *datasourceproxy.DataSourceProxyService, searchService *search.SearchService, | 
					
						
							|  |  |  | 	live *live.GrafanaLive, livePushGateway *pushhttp.Gateway, plugCtxProvider *plugincontext.Provider, | 
					
						
							| 
									
										
										
										
											2022-01-27 01:44:20 +08:00
										 |  |  | 	contextHandler *contexthandler.ContextHandler, features *featuremgmt.FeatureManager, | 
					
						
							| 
									
										
										
										
											2022-06-07 08:52:44 +08:00
										 |  |  | 	alertNG *ngalert.AlertNG, libraryPanelService librarypanels.Service, libraryElementService libraryelements.Service, | 
					
						
							| 
									
										
										
										
											2023-03-02 01:42:53 +08:00
										 |  |  | 	quotaService quota.Service, socialService social.Service, tracer tracing.Tracer, | 
					
						
							| 
									
										
										
										
											2022-01-31 23:06:16 +08:00
										 |  |  | 	encryptionService encryption.Internal, grafanaUpdateChecker *updatechecker.GrafanaService, | 
					
						
							|  |  |  | 	pluginsUpdateChecker *updatechecker.PluginsService, searchUsersService searchusers.Service, | 
					
						
							| 
									
										
										
										
											2023-03-29 18:55:55 +08:00
										 |  |  | 	dataSourcesService datasources.DataSourceService, queryDataService query.Service, pluginFileStore plugins.FileStore, | 
					
						
							| 
									
										
										
										
											2023-02-08 16:32:59 +08:00
										 |  |  | 	teamGuardian teamguardian.TeamGuardian, serviceaccountsService serviceaccounts.Service, | 
					
						
							| 
									
										
										
										
											2022-12-01 05:42:42 +08:00
										 |  |  | 	authInfoService login.AuthInfoService, storageService store.StorageService, httpEntityStore httpentitystore.HTTPEntityStore, | 
					
						
							| 
									
										
										
										
											2022-02-17 01:54:29 +08:00
										 |  |  | 	notificationService *notifications.NotificationService, dashboardService dashboards.DashboardService, | 
					
						
							| 
									
										
										
										
											2022-10-11 03:47:53 +08:00
										 |  |  | 	dashboardProvisioningService dashboards.DashboardProvisioningService, folderService folder.Service, | 
					
						
							| 
									
										
										
										
											2022-02-28 16:54:56 +08:00
										 |  |  | 	datasourcePermissionsService permissions.DatasourcePermissionsService, alertNotificationService *alerting.AlertNotificationService, | 
					
						
							| 
									
										
										
										
											2023-03-11 20:28:12 +08:00
										 |  |  | 	dashboardsnapshotsService dashboardsnapshots.Service, pluginSettings pluginSettings.Service, | 
					
						
							| 
									
										
										
										
											2022-08-01 23:56:36 +08:00
										 |  |  | 	avatarCacheServer *avatar.AvatarCacheServer, preferenceService pref.Service, | 
					
						
							| 
									
										
										
										
											2022-05-10 21:48:47 +08:00
										 |  |  | 	teamsPermissionsService accesscontrol.TeamPermissionsService, folderPermissionsService accesscontrol.FolderPermissionsService, | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	dashboardPermissionsService accesscontrol.DashboardPermissionsService, dashboardVersionService dashver.Service, | 
					
						
							| 
									
										
											  
											
												Reconcile coremodels, entities, objects under new kind framework (#56492)
* Update thema to latest
* Deal with s/Library/*Runtime/
* Commit new, working results of codegen
* We like pointers now
* Always take runtime arg for NewBase()
* Sketchy handwavy pass at entity meta framework
* Little nibbles
* Update pkg/framework/coremodel/entityframework.cue
Co-authored-by: Artur Wierzbicki <wierzbicki.artur.94@gmail.com>
* Move file into new framework location
* Introduce loaders, Go code
* Complete rename to kind
* Flesh out framework, add svg/dashboard examples
* Cruft removal
* Remove generated kind go files from gitignore
* Refine maturity concept, add SlotKind
* Update embed and go deps
* Export PrefixWithGrafanaCUE
* Make the loader actually work, holy crap
* Many small tweaks to type.cue
* Add Apache 2 licensing exceptions for kinds
* Add new kinds dir, start of generator
* Roll back to earlier oapi-codegen
* Introduce new grafana-specific CUE loaders
* Introduce new tidy code generators framework
* Catch up kind framework with tinkering
* Add slices for the generators
* Add write/verify step to main generator
* Many renames
* Split up kind framework cue files
* Use kind.Decl within generated kinds
* Create kind.SomeDecl wrapper type to cache lineages
* Better names again
* Get one generated implemented, hopefully
* Copy dashboard schema into new kind.cue
* Small fixes to make the initial gen work
* Put svg kind in its new home
* Add generated Go dashboard type
* More renames and cleanups
* Add base kind registry and generator
* Stop blacklisting *_gen.go files
This is not the Go best practice, anyway. All we actually want to ignore
for enterprise is generated wire files.
* Change codegen output directories
pkg/kind -> pkg/kinds
pkg/registry/kindreg -> pkg/registry/corekind
* Rename pkg/framework/kind to pkg/kindsys
* Add core structured kind generator
* Add plural and machine names to kind spec
* Copy playlist over to kind system
* Consolidate kindsys files
* Add raw kind generator
* Update CODEOWNERS for kind framework
* Touch up comments a bit
* More docs tweaks
* Remove generated types to reduce noise for review
* Split each generator into its own file
* Rename Slot kind to Composable kind
* Add handwavy types for customkind loading
* Guard against init calls to framework loader
* First pass at doc on extending the kind system
* Improve attribute example in docs
* Fix wire imports
* Add basic TS types generator
* Fix composable kind category def
* No need for a separate file with generate directive
* Catch dashboard schema up
* Rename generator types to something saner and generic
* Make version configurable in ts/go generators
* Add CommonMeta to ease property access
* Add kindsys prop indicating whether lineage is group
* Put all kind categories back in a single file
* Finish with kindsys group props
* Refactor maturity progression per discussion
- Replace "committed" with "merged"
- All kindcats can use all maturity levels, at least for now
* Convert ts veneer index generator to modular system
* Move over to new jennywrites framework
* Strip down old coremodel generator
* Use public version of jennywrites
* Pull latest thema
* Commit generated Go types
* Add header injection postprocessor
* Move sdboyer/jennywrites to grafana/codejen
* Tweak header output
* Remove dashboard and playlist coremodels
* Fix up backend dashboards devenv test
* Fix TS import patterns to new gen filename
* Update internal imports, remove coremodel registry
* Fix compilation errors, wire generation
* Export and replace the prefix dropper
* More Go struct and field name changes
* Last name fixes, hopefully
* Fix lint errors
* Last lint error
Co-authored-by: Artur Wierzbicki <wierzbicki.artur.94@gmail.com>
											
										 
											2022-11-11 04:36:40 +08:00
										 |  |  | 	starService star.Service, csrfService csrf.Service, basekinds *corekind.Base, | 
					
						
							| 
									
										
										
										
											2022-08-25 04:24:50 +08:00
										 |  |  | 	playlistService playlist.Service, apiKeyService apikey.Service, kvStore kvstore.KVStore, | 
					
						
							| 
									
										
										
										
											2022-08-30 02:44:55 +08:00
										 |  |  | 	secretsMigrator secrets.Migrator, secretsPluginManager plugins.SecretsPluginManager, secretsService secrets.Service, | 
					
						
							| 
									
										
										
										
											2022-09-07 03:21:25 +08:00
										 |  |  | 	secretsPluginMigrator spm.SecretMigrationProvider, secretsStore secretsKV.SecretsKVStore, | 
					
						
							| 
									
										
										
										
											2022-09-21 00:58:04 +08:00
										 |  |  | 	publicDashboardsApi *publicdashboardsApi.Api, userService user.Service, tempUserService tempUser.Service, | 
					
						
							|  |  |  | 	loginAttemptService loginAttempt.Service, orgService org.Service, teamService team.Service, | 
					
						
							| 
									
										
										
										
											2022-09-27 20:46:03 +08:00
										 |  |  | 	accesscontrolService accesscontrol.Service, dashboardThumbsService thumbs.DashboardThumbService, navTreeService navtree.Service, | 
					
						
							| 
									
										
										
										
											2023-03-21 00:00:14 +08:00
										 |  |  | 	annotationRepo annotations.Repository, tagService tag.Service, searchv2HTTPService searchV2.SearchHTTPService, oauthTokenService oauthtoken.OAuthTokenService, | 
					
						
							| 
									
										
										
										
											2023-02-03 12:39:54 +08:00
										 |  |  | 	statsService stats.Service, authnService authn.Service, pluginsCDNService *pluginscdn.Service, | 
					
						
							| 
									
										
										
										
											2023-01-25 22:58:54 +08:00
										 |  |  | 	starApi *starApi.API, | 
					
						
							| 
									
										
										
										
											2022-08-24 19:29:17 +08:00
										 |  |  | ) (*HTTPServer, error) { | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	web.Env = cfg.Env | 
					
						
							|  |  |  | 	m := web.New() | 
					
						
							| 
									
										
										
										
											2018-05-01 21:51:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 |  |  | 	hs := &HTTPServer{ | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		Cfg:                          cfg, | 
					
						
							|  |  |  | 		RouteRegister:                routeRegister, | 
					
						
							| 
									
										
										
										
											2022-06-14 22:07:41 +08:00
										 |  |  | 		bus:                          bus, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		RenderService:                renderService, | 
					
						
							|  |  |  | 		License:                      licensing, | 
					
						
							|  |  |  | 		HooksService:                 hooksService, | 
					
						
							|  |  |  | 		CacheService:                 cacheService, | 
					
						
							|  |  |  | 		SQLStore:                     sqlStore, | 
					
						
							|  |  |  | 		AlertEngine:                  alertEngine, | 
					
						
							|  |  |  | 		PluginRequestValidator:       pluginRequestValidator, | 
					
						
							| 
									
										
										
										
											2022-09-23 20:27:01 +08:00
										 |  |  | 		pluginInstaller:              pluginInstaller, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		pluginClient:                 pluginClient, | 
					
						
							|  |  |  | 		pluginStore:                  pluginStore, | 
					
						
							|  |  |  | 		pluginStaticRouteResolver:    pluginStaticRouteResolver, | 
					
						
							| 
									
										
										
										
											2022-03-11 01:38:04 +08:00
										 |  |  | 		pluginDashboardService:       pluginDashboardService, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		pluginErrorResolver:          pluginErrorResolver, | 
					
						
							| 
									
										
										
										
											2023-03-29 18:55:55 +08:00
										 |  |  | 		pluginFileStore:              pluginFileStore, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		grafanaUpdateChecker:         grafanaUpdateChecker, | 
					
						
							|  |  |  | 		pluginsUpdateChecker:         pluginsUpdateChecker, | 
					
						
							|  |  |  | 		SettingsProvider:             settingsProvider, | 
					
						
							|  |  |  | 		DataSourceCache:              dataSourceCache, | 
					
						
							|  |  |  | 		AuthTokenService:             userTokenService, | 
					
						
							|  |  |  | 		cleanUpService:               cleanUpService, | 
					
						
							|  |  |  | 		ShortURLService:              shortURLService, | 
					
						
							|  |  |  | 		QueryHistoryService:          queryHistoryService, | 
					
						
							| 
									
										
										
										
											2022-07-25 22:19:07 +08:00
										 |  |  | 		CorrelationsService:          correlationsService, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		Features:                     features, | 
					
						
							|  |  |  | 		ThumbService:                 thumbService, | 
					
						
							| 
									
										
										
										
											2022-03-18 01:19:23 +08:00
										 |  |  | 		StorageService:               storageService, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		RemoteCacheService:           remoteCache, | 
					
						
							|  |  |  | 		ProvisioningService:          provisioningService, | 
					
						
							|  |  |  | 		Login:                        loginService, | 
					
						
							|  |  |  | 		AccessControl:                accessControl, | 
					
						
							|  |  |  | 		DataProxy:                    dataSourceProxy, | 
					
						
							| 
									
										
										
										
											2022-09-23 07:02:09 +08:00
										 |  |  | 		SearchV2HTTPService:          searchv2HTTPService, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		SearchService:                searchService, | 
					
						
							|  |  |  | 		Live:                         live, | 
					
						
							|  |  |  | 		LivePushGateway:              livePushGateway, | 
					
						
							|  |  |  | 		PluginContextProvider:        plugCtxProvider, | 
					
						
							|  |  |  | 		ContextHandler:               contextHandler, | 
					
						
							|  |  |  | 		AlertNG:                      alertNG, | 
					
						
							|  |  |  | 		LibraryPanelService:          libraryPanelService, | 
					
						
							|  |  |  | 		LibraryElementService:        libraryElementService, | 
					
						
							|  |  |  | 		QuotaService:                 quotaService, | 
					
						
							|  |  |  | 		tracer:                       tracer, | 
					
						
							|  |  |  | 		log:                          log.New("http.server"), | 
					
						
							|  |  |  | 		web:                          m, | 
					
						
							|  |  |  | 		Listener:                     opts.Listener, | 
					
						
							|  |  |  | 		SocialService:                socialService, | 
					
						
							|  |  |  | 		EncryptionService:            encryptionService, | 
					
						
							|  |  |  | 		SecretsService:               secretsService, | 
					
						
							| 
									
										
										
										
											2022-08-11 03:47:03 +08:00
										 |  |  | 		secretsPluginManager:         secretsPluginManager, | 
					
						
							| 
									
										
										
										
											2022-08-30 02:44:55 +08:00
										 |  |  | 		secretsMigrator:              secretsMigrator, | 
					
						
							|  |  |  | 		secretsPluginMigrator:        secretsPluginMigrator, | 
					
						
							|  |  |  | 		secretsStore:                 secretsStore, | 
					
						
							| 
									
										
										
										
											2022-12-01 05:42:42 +08:00
										 |  |  | 		httpEntityStore:              httpEntityStore, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		DataSourcesService:           dataSourcesService, | 
					
						
							|  |  |  | 		searchUsersService:           searchUsersService, | 
					
						
							|  |  |  | 		teamGuardian:                 teamGuardian, | 
					
						
							|  |  |  | 		queryDataService:             queryDataService, | 
					
						
							|  |  |  | 		serviceAccountsService:       serviceaccountsService, | 
					
						
							|  |  |  | 		authInfoService:              authInfoService, | 
					
						
							| 
									
										
										
										
											2022-04-05 02:36:15 +08:00
										 |  |  | 		authenticator:                authenticator, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		NotificationService:          notificationService, | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 		DashboardService:             dashboardService, | 
					
						
							| 
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 |  |  | 		dashboardProvisioningService: dashboardProvisioningService, | 
					
						
							|  |  |  | 		folderService:                folderService, | 
					
						
							| 
									
										
										
										
											2022-02-09 21:01:32 +08:00
										 |  |  | 		DatasourcePermissionsService: datasourcePermissionsService, | 
					
						
							| 
									
										
										
										
											2022-05-10 21:48:47 +08:00
										 |  |  | 		teamPermissionsService:       teamsPermissionsService, | 
					
						
							| 
									
										
										
										
											2022-02-17 01:54:29 +08:00
										 |  |  | 		AlertNotificationService:     alertNotificationService, | 
					
						
							| 
									
										
										
										
											2022-06-15 01:41:29 +08:00
										 |  |  | 		dashboardsnapshotsService:    dashboardsnapshotsService, | 
					
						
							| 
									
										
										
										
											2022-02-25 18:29:18 +08:00
										 |  |  | 		PluginSettings:               pluginSettings, | 
					
						
							| 
									
										
										
										
											2022-04-06 10:56:17 +08:00
										 |  |  | 		AvatarCacheServer:            avatarCacheServer, | 
					
						
							| 
									
										
										
										
											2022-04-21 21:03:17 +08:00
										 |  |  | 		preferenceService:            preferenceService, | 
					
						
							| 
									
										
										
										
											2022-06-02 21:52:30 +08:00
										 |  |  | 		Csrf:                         csrfService, | 
					
						
							| 
									
										
										
										
											2022-05-10 21:48:47 +08:00
										 |  |  | 		folderPermissionsService:     folderPermissionsService, | 
					
						
							|  |  |  | 		dashboardPermissionsService:  dashboardPermissionsService, | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 		dashboardVersionService:      dashboardVersionService, | 
					
						
							| 
									
										
										
										
											2022-05-19 20:32:10 +08:00
										 |  |  | 		starService:                  starService, | 
					
						
							| 
									
										
											  
											
												Reconcile coremodels, entities, objects under new kind framework (#56492)
* Update thema to latest
* Deal with s/Library/*Runtime/
* Commit new, working results of codegen
* We like pointers now
* Always take runtime arg for NewBase()
* Sketchy handwavy pass at entity meta framework
* Little nibbles
* Update pkg/framework/coremodel/entityframework.cue
Co-authored-by: Artur Wierzbicki <wierzbicki.artur.94@gmail.com>
* Move file into new framework location
* Introduce loaders, Go code
* Complete rename to kind
* Flesh out framework, add svg/dashboard examples
* Cruft removal
* Remove generated kind go files from gitignore
* Refine maturity concept, add SlotKind
* Update embed and go deps
* Export PrefixWithGrafanaCUE
* Make the loader actually work, holy crap
* Many small tweaks to type.cue
* Add Apache 2 licensing exceptions for kinds
* Add new kinds dir, start of generator
* Roll back to earlier oapi-codegen
* Introduce new grafana-specific CUE loaders
* Introduce new tidy code generators framework
* Catch up kind framework with tinkering
* Add slices for the generators
* Add write/verify step to main generator
* Many renames
* Split up kind framework cue files
* Use kind.Decl within generated kinds
* Create kind.SomeDecl wrapper type to cache lineages
* Better names again
* Get one generated implemented, hopefully
* Copy dashboard schema into new kind.cue
* Small fixes to make the initial gen work
* Put svg kind in its new home
* Add generated Go dashboard type
* More renames and cleanups
* Add base kind registry and generator
* Stop blacklisting *_gen.go files
This is not the Go best practice, anyway. All we actually want to ignore
for enterprise is generated wire files.
* Change codegen output directories
pkg/kind -> pkg/kinds
pkg/registry/kindreg -> pkg/registry/corekind
* Rename pkg/framework/kind to pkg/kindsys
* Add core structured kind generator
* Add plural and machine names to kind spec
* Copy playlist over to kind system
* Consolidate kindsys files
* Add raw kind generator
* Update CODEOWNERS for kind framework
* Touch up comments a bit
* More docs tweaks
* Remove generated types to reduce noise for review
* Split each generator into its own file
* Rename Slot kind to Composable kind
* Add handwavy types for customkind loading
* Guard against init calls to framework loader
* First pass at doc on extending the kind system
* Improve attribute example in docs
* Fix wire imports
* Add basic TS types generator
* Fix composable kind category def
* No need for a separate file with generate directive
* Catch dashboard schema up
* Rename generator types to something saner and generic
* Make version configurable in ts/go generators
* Add CommonMeta to ease property access
* Add kindsys prop indicating whether lineage is group
* Put all kind categories back in a single file
* Finish with kindsys group props
* Refactor maturity progression per discussion
- Replace "committed" with "merged"
- All kindcats can use all maturity levels, at least for now
* Convert ts veneer index generator to modular system
* Move over to new jennywrites framework
* Strip down old coremodel generator
* Use public version of jennywrites
* Pull latest thema
* Commit generated Go types
* Add header injection postprocessor
* Move sdboyer/jennywrites to grafana/codejen
* Tweak header output
* Remove dashboard and playlist coremodels
* Fix up backend dashboards devenv test
* Fix TS import patterns to new gen filename
* Update internal imports, remove coremodel registry
* Fix compilation errors, wire generation
* Export and replace the prefix dropper
* More Go struct and field name changes
* Last name fixes, hopefully
* Fix lint errors
* Last lint error
Co-authored-by: Artur Wierzbicki <wierzbicki.artur.94@gmail.com>
											
										 
											2022-11-11 04:36:40 +08:00
										 |  |  | 		Kinds:                        basekinds, | 
					
						
							| 
									
										
										
										
											2022-07-18 17:26:35 +08:00
										 |  |  | 		playlistService:              playlistService, | 
					
						
							| 
									
										
										
										
											2022-08-02 22:55:19 +08:00
										 |  |  | 		apiKeyService:                apiKeyService, | 
					
						
							| 
									
										
										
										
											2022-06-15 20:59:40 +08:00
										 |  |  | 		kvStore:                      kvStore, | 
					
						
							| 
									
										
										
										
											2022-07-07 07:51:44 +08:00
										 |  |  | 		PublicDashboardsApi:          publicDashboardsApi, | 
					
						
							| 
									
										
										
										
											2022-07-16 00:06:44 +08:00
										 |  |  | 		userService:                  userService, | 
					
						
							| 
									
										
										
										
											2022-08-13 00:13:23 +08:00
										 |  |  | 		tempUserService:              tempUserService, | 
					
						
							| 
									
										
										
										
											2022-09-01 04:45:41 +08:00
										 |  |  | 		dashboardThumbsService:       dashboardThumbsService, | 
					
						
							| 
									
										
										
										
											2022-08-17 14:34:23 +08:00
										 |  |  | 		loginAttemptService:          loginAttemptService, | 
					
						
							| 
									
										
										
										
											2022-08-24 01:26:21 +08:00
										 |  |  | 		orgService:                   orgService, | 
					
						
							| 
									
										
										
										
											2022-09-21 00:58:04 +08:00
										 |  |  | 		teamService:                  teamService, | 
					
						
							| 
									
										
										
										
											2022-09-23 04:04:48 +08:00
										 |  |  | 		navTreeService:               navTreeService, | 
					
						
							| 
									
										
										
										
											2022-08-24 19:29:17 +08:00
										 |  |  | 		accesscontrolService:         accesscontrolService, | 
					
						
							| 
									
										
										
										
											2022-09-19 15:54:37 +08:00
										 |  |  | 		annotationsRepo:              annotationRepo, | 
					
						
							| 
									
										
										
										
											2022-09-21 20:04:01 +08:00
										 |  |  | 		tagService:                   tagService, | 
					
						
							| 
									
										
										
										
											2022-10-19 00:17:28 +08:00
										 |  |  | 		oauthTokenService:            oauthTokenService, | 
					
						
							| 
									
										
										
										
											2022-12-01 01:11:07 +08:00
										 |  |  | 		statsService:                 statsService, | 
					
						
							| 
									
										
										
										
											2023-01-17 16:11:45 +08:00
										 |  |  | 		authnService:                 authnService, | 
					
						
							| 
									
										
										
										
											2023-01-27 22:08:17 +08:00
										 |  |  | 		pluginsCDNService:            pluginsCDNService, | 
					
						
							| 
									
										
										
										
											2023-01-25 22:58:54 +08:00
										 |  |  | 		starApi:                      starApi, | 
					
						
							| 
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if hs.Listener != nil { | 
					
						
							|  |  |  | 		hs.log.Debug("Using provided listener") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-01 22:01:43 +08:00
										 |  |  | 	hs.registerRoutes() | 
					
						
							| 
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 00:33:21 +08:00
										 |  |  | 	// Register access control scope resolver for annotations
 | 
					
						
							| 
									
										
										
										
											2022-09-19 15:54:37 +08:00
										 |  |  | 	hs.AccessControl.RegisterScopeAttributeResolver(AnnotationTypeScopeResolver(hs.annotationsRepo)) | 
					
						
							| 
									
										
										
										
											2022-03-19 00:33:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 21:11:22 +08:00
										 |  |  | 	if err := hs.declareFixedRoles(); err != nil { | 
					
						
							|  |  |  | 		return nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return hs, nil | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | func (hs *HTTPServer) AddMiddleware(middleware web.Handler) { | 
					
						
							| 
									
										
										
										
											2020-07-23 15:54:07 +08:00
										 |  |  | 	hs.middlewares = append(hs.middlewares, middleware) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-24 21:41:18 +08:00
										 |  |  | func (hs *HTTPServer) AddNamedMiddleware(middleware routing.RegisterNamedMiddleware) { | 
					
						
							|  |  |  | 	hs.namedMiddlewares = append(hs.namedMiddlewares, middleware) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 21:51:15 +08:00
										 |  |  | func (hs *HTTPServer) Run(ctx context.Context) error { | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	hs.context = ctx | 
					
						
							| 
									
										
										
										
											2018-07-02 14:35:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-01 22:01:43 +08:00
										 |  |  | 	hs.applyRoutes() | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-16 00:55:41 +08:00
										 |  |  | 	// Remove any square brackets enclosing IPv6 addresses, a format we support for backwards compatibility
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	host := strings.TrimSuffix(strings.TrimPrefix(hs.Cfg.HTTPAddr, "["), "]") | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 	hs.httpSrv = &http.Server{ | 
					
						
							| 
									
										
										
										
											2021-03-19 18:21:52 +08:00
										 |  |  | 		Addr:        net.JoinHostPort(host, hs.Cfg.HTTPPort), | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 		Handler:     hs.web, | 
					
						
							| 
									
										
										
										
											2021-03-19 18:21:52 +08:00
										 |  |  | 		ReadTimeout: hs.Cfg.ReadTimeout, | 
					
						
							| 
									
										
										
										
											2019-10-22 19:07:43 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 	switch hs.Cfg.Protocol { | 
					
						
							| 
									
										
										
										
											2020-10-02 21:45:45 +08:00
										 |  |  | 	case setting.HTTP2Scheme: | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 		if err := hs.configureHttp2(); err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-10-02 21:45:45 +08:00
										 |  |  | 	case setting.HTTPSScheme: | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 		if err := hs.configureHttps(); err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-12-01 16:53:27 +08:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 16:41:10 +08:00
										 |  |  | 	listener, err := hs.getListener() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return err | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-22 21:14:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 	hs.log.Info("HTTP Server Listen", "address", listener.Addr().String(), "protocol", | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 		hs.Cfg.Protocol, "subUrl", hs.Cfg.AppSubURL, "socket", hs.Cfg.SocketPath) | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var wg sync.WaitGroup | 
					
						
							|  |  |  | 	wg.Add(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// handle http shutdown on server context done
 | 
					
						
							|  |  |  | 	go func() { | 
					
						
							| 
									
										
										
										
											2019-11-27 20:42:15 +08:00
										 |  |  | 		defer wg.Done() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 		<-ctx.Done() | 
					
						
							|  |  |  | 		if err := hs.httpSrv.Shutdown(context.Background()); err != nil { | 
					
						
							|  |  |  | 			hs.log.Error("Failed to shutdown server", "error", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 	switch hs.Cfg.Protocol { | 
					
						
							| 
									
										
										
										
											2020-10-02 21:45:45 +08:00
										 |  |  | 	case setting.HTTPScheme, setting.SocketScheme: | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 		if err := hs.httpSrv.Serve(listener); err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-19 20:34:28 +08:00
										 |  |  | 			if errors.Is(err, http.ErrServerClosed) { | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 				hs.log.Debug("server was shutdown gracefully") | 
					
						
							|  |  |  | 				return nil | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-10-02 21:45:45 +08:00
										 |  |  | 	case setting.HTTP2Scheme, setting.HTTPSScheme: | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 		if err := hs.httpSrv.ServeTLS(listener, hs.Cfg.CertFile, hs.Cfg.KeyFile); err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-19 20:34:28 +08:00
										 |  |  | 			if errors.Is(err, http.ErrServerClosed) { | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 				hs.log.Debug("server was shutdown gracefully") | 
					
						
							|  |  |  | 				return nil | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return err | 
					
						
							| 
									
										
										
										
											2017-04-27 14:54:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 		panic(fmt.Sprintf("Unhandled protocol %q", hs.Cfg.Protocol)) | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 	wg.Wait() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 16:41:10 +08:00
										 |  |  | func (hs *HTTPServer) getListener() (net.Listener, error) { | 
					
						
							|  |  |  | 	if hs.Listener != nil { | 
					
						
							|  |  |  | 		return hs.Listener, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 	switch hs.Cfg.Protocol { | 
					
						
							| 
									
										
										
										
											2020-10-02 21:45:45 +08:00
										 |  |  | 	case setting.HTTPScheme, setting.HTTPSScheme, setting.HTTP2Scheme: | 
					
						
							| 
									
										
										
										
											2020-08-21 16:41:10 +08:00
										 |  |  | 		listener, err := net.Listen("tcp", hs.httpSrv.Addr) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2022-06-07 04:30:31 +08:00
										 |  |  | 			return nil, fmt.Errorf("failed to open listener on address %s: %w", hs.httpSrv.Addr, err) | 
					
						
							| 
									
										
										
										
											2020-08-21 16:41:10 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return listener, nil | 
					
						
							| 
									
										
										
										
											2020-10-02 21:45:45 +08:00
										 |  |  | 	case setting.SocketScheme: | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 		listener, err := net.ListenUnix("unix", &net.UnixAddr{Name: hs.Cfg.SocketPath, Net: "unix"}) | 
					
						
							| 
									
										
										
										
											2020-08-21 16:41:10 +08:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2022-06-07 04:30:31 +08:00
										 |  |  | 			return nil, fmt.Errorf("failed to open listener for socket %s: %w", hs.Cfg.SocketPath, err) | 
					
						
							| 
									
										
										
										
											2020-08-21 16:41:10 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Make socket writable by group
 | 
					
						
							| 
									
										
										
										
											2020-12-10 18:53:21 +08:00
										 |  |  | 		// nolint:gosec
 | 
					
						
							| 
									
										
										
										
											2022-11-01 22:04:01 +08:00
										 |  |  | 		if err := os.Chmod(hs.Cfg.SocketPath, os.FileMode(hs.Cfg.SocketMode)); err != nil { | 
					
						
							|  |  |  | 			return nil, fmt.Errorf("failed to change socket mode %d: %w", hs.Cfg.SocketMode, err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// golang.org/pkg/os does not have chgrp
 | 
					
						
							|  |  |  | 		// Changing the gid of a file without privileges requires that the target group is in the group of the process and that the process is the file owner
 | 
					
						
							|  |  |  | 		if err := os.Chown(hs.Cfg.SocketPath, -1, hs.Cfg.SocketGid); err != nil { | 
					
						
							|  |  |  | 			return nil, fmt.Errorf("failed to change socket group id %d: %w", hs.Cfg.SocketGid, err) | 
					
						
							| 
									
										
										
										
											2020-08-21 16:41:10 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return listener, nil | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 		hs.log.Error("Invalid protocol", "protocol", hs.Cfg.Protocol) | 
					
						
							|  |  |  | 		return nil, fmt.Errorf("invalid protocol %q", hs.Cfg.Protocol) | 
					
						
							| 
									
										
										
										
											2020-08-21 16:41:10 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | func (hs *HTTPServer) configureHttps() error { | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if hs.Cfg.CertFile == "" { | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 		return errors.New("cert_file cannot be empty when using HTTPS") | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if hs.Cfg.KeyFile == "" { | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 		return errors.New("cert_key cannot be empty when using HTTPS") | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if _, err := os.Stat(hs.Cfg.CertFile); os.IsNotExist(err) { | 
					
						
							|  |  |  | 		return fmt.Errorf(`cannot find SSL cert_file at %q`, hs.Cfg.CertFile) | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if _, err := os.Stat(hs.Cfg.KeyFile); os.IsNotExist(err) { | 
					
						
							|  |  |  | 		return fmt.Errorf(`cannot find SSL key_file at %q`, hs.Cfg.KeyFile) | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 21:29:20 +08:00
										 |  |  | 	tlsCfg := &tls.Config{ | 
					
						
							| 
									
										
										
										
											2022-03-04 00:48:26 +08:00
										 |  |  | 		MinVersion: tls.VersionTLS12, | 
					
						
							| 
									
										
										
										
											2017-02-15 21:29:20 +08:00
										 |  |  | 		CipherSuites: []uint16{ | 
					
						
							| 
									
										
										
										
											2020-02-19 01:58:36 +08:00
										 |  |  | 			tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | 
					
						
							|  |  |  | 			tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | 
					
						
							|  |  |  | 			tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, | 
					
						
							|  |  |  | 			tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | 
					
						
							| 
									
										
										
										
											2017-02-15 21:29:20 +08:00
										 |  |  | 			tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, | 
					
						
							| 
									
										
										
										
											2020-02-19 01:58:36 +08:00
										 |  |  | 			tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, | 
					
						
							| 
									
										
										
										
											2017-02-15 21:29:20 +08:00
										 |  |  | 			tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, | 
					
						
							| 
									
										
										
										
											2020-02-19 01:58:36 +08:00
										 |  |  | 			tls.TLS_RSA_WITH_AES_128_GCM_SHA256, | 
					
						
							|  |  |  | 			tls.TLS_RSA_WITH_AES_256_GCM_SHA384, | 
					
						
							|  |  |  | 			tls.TLS_RSA_WITH_AES_128_CBC_SHA, | 
					
						
							|  |  |  | 			tls.TLS_RSA_WITH_AES_256_CBC_SHA, | 
					
						
							| 
									
										
										
										
											2017-02-15 21:29:20 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-18 05:10:12 +08:00
										 |  |  | 	hs.httpSrv.TLSConfig = tlsCfg | 
					
						
							| 
									
										
										
										
											2018-04-17 02:22:12 +08:00
										 |  |  | 	hs.httpSrv.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler)) | 
					
						
							| 
									
										
										
										
											2017-06-18 05:10:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | func (hs *HTTPServer) configureHttp2() error { | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if hs.Cfg.CertFile == "" { | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 		return errors.New("cert_file cannot be empty when using HTTP2") | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if hs.Cfg.KeyFile == "" { | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 		return errors.New("cert_key cannot be empty when using HTTP2") | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if _, err := os.Stat(hs.Cfg.CertFile); os.IsNotExist(err) { | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 		return fmt.Errorf("cannot find SSL cert_file at %q", hs.Cfg.CertFile) | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if _, err := os.Stat(hs.Cfg.KeyFile); os.IsNotExist(err) { | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 		return fmt.Errorf("cannot find SSL key_file at %q", hs.Cfg.KeyFile) | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tlsCfg := &tls.Config{ | 
					
						
							| 
									
										
										
										
											2022-03-04 00:48:26 +08:00
										 |  |  | 		MinVersion: tls.VersionTLS12, | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | 		CipherSuites: []uint16{ | 
					
						
							|  |  |  | 			tls.TLS_CHACHA20_POLY1305_SHA256, | 
					
						
							|  |  |  | 			tls.TLS_AES_128_GCM_SHA256, | 
					
						
							|  |  |  | 			tls.TLS_AES_256_GCM_SHA384, | 
					
						
							|  |  |  | 			tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | 
					
						
							|  |  |  | 			tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | 
					
						
							| 
									
										
										
										
											2020-02-19 01:58:36 +08:00
										 |  |  | 			tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | 			tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | 
					
						
							| 
									
										
										
										
											2020-02-19 01:58:36 +08:00
										 |  |  | 			tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, | 
					
						
							|  |  |  | 			tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		NextProtos: []string{"h2", "http/1.1"}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	hs.httpSrv.TLSConfig = tlsCfg | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 19:07:21 +08:00
										 |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2019-08-16 23:06:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-02 14:35:50 +08:00
										 |  |  | func (hs *HTTPServer) applyRoutes() { | 
					
						
							|  |  |  | 	// start with middlewares & static routes
 | 
					
						
							|  |  |  | 	hs.addMiddlewaresAndStaticRoutes() | 
					
						
							|  |  |  | 	// then add view routes & api routes
 | 
					
						
							| 
									
										
										
										
											2022-01-24 21:41:18 +08:00
										 |  |  | 	hs.RouteRegister.Register(hs.web, hs.namedMiddlewares...) | 
					
						
							| 
									
										
										
										
											2018-07-02 14:35:50 +08:00
										 |  |  | 	// lastly not found route
 | 
					
						
							| 
									
										
										
										
											2022-08-25 16:11:27 +08:00
										 |  |  | 	hs.web.NotFound(middleware.ProvideRouteOperationName("notfound"), middleware.ReqSignedIn, hs.NotFoundHandler) | 
					
						
							| 
									
										
										
										
											2018-07-02 14:35:50 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() { | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	m := hs.web | 
					
						
							| 
									
										
										
										
											2018-07-02 14:35:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-20 18:10:12 +08:00
										 |  |  | 	m.Use(middleware.RequestTracing(hs.tracer)) | 
					
						
							| 
									
										
										
										
											2022-02-03 01:48:46 +08:00
										 |  |  | 	m.Use(middleware.RequestMetrics(hs.Features)) | 
					
						
							| 
									
										
										
										
											2021-04-20 21:22:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-25 20:35:21 +08:00
										 |  |  | 	m.UseMiddleware(middleware.Logger(hs.Cfg)) | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if hs.Cfg.EnableGzip { | 
					
						
							| 
									
										
										
										
											2021-08-10 19:29:46 +08:00
										 |  |  | 		m.UseMiddleware(middleware.Gziper()) | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-09 20:58:50 +08:00
										 |  |  | 	m.UseMiddleware(middleware.Recovery(hs.Cfg)) | 
					
						
							| 
									
										
										
										
											2022-07-14 02:28:59 +08:00
										 |  |  | 	m.UseMiddleware(hs.Csrf.Middleware()) | 
					
						
							| 
									
										
										
										
											2017-11-15 20:51:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	hs.mapStatic(m, hs.Cfg.StaticRootPath, "build", "public/build") | 
					
						
							| 
									
										
										
										
											2022-02-08 20:38:43 +08:00
										 |  |  | 	hs.mapStatic(m, hs.Cfg.StaticRootPath, "", "public", "/public/views/swagger.html") | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	hs.mapStatic(m, hs.Cfg.StaticRootPath, "robots.txt", "robots.txt") | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if hs.Cfg.ImageUploadProvider == "local" { | 
					
						
							| 
									
										
										
										
											2018-05-24 21:26:27 +08:00
										 |  |  | 		hs.mapStatic(m, hs.Cfg.ImagesDir, "", "/public/img/attachments") | 
					
						
							| 
									
										
										
										
											2017-12-31 06:01:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-01 01:12:34 +08:00
										 |  |  | 	if len(hs.Cfg.CustomResponseHeaders) > 0 { | 
					
						
							|  |  |  | 		m.Use(middleware.AddCustomResponseHeaders(hs.Cfg)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 	m.Use(middleware.AddDefaultResponseHeaders(hs.Cfg)) | 
					
						
							| 
									
										
										
										
											2019-05-06 15:22:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if hs.Cfg.ServeFromSubPath && hs.Cfg.AppSubURL != "" { | 
					
						
							|  |  |  | 		m.SetURLPrefix(hs.Cfg.AppSubURL) | 
					
						
							| 
									
										
										
										
											2019-05-27 23:47:29 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	m.UseMiddleware(web.Renderer(filepath.Join(hs.Cfg.StaticRootPath, "views"), "[[", "]]")) | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-02 13:14:26 +08:00
										 |  |  | 	// These endpoints are used for monitoring the Grafana instance
 | 
					
						
							| 
									
										
										
										
											2020-10-21 17:06:19 +08:00
										 |  |  | 	// and should not be redirected or rejected.
 | 
					
						
							| 
									
										
										
										
											2020-10-02 13:14:26 +08:00
										 |  |  | 	m.Use(hs.healthzHandler) | 
					
						
							|  |  |  | 	m.Use(hs.apiHealthHandler) | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | 	m.Use(hs.metricsEndpoint) | 
					
						
							| 
									
										
										
										
											2022-03-29 17:18:26 +08:00
										 |  |  | 	m.Use(hs.pluginMetricsEndpoint) | 
					
						
							| 
									
										
										
										
											2022-09-12 18:04:43 +08:00
										 |  |  | 	m.Use(hs.frontendLogEndpoints()) | 
					
						
							| 
									
										
										
										
											2020-10-02 13:14:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-25 20:35:21 +08:00
										 |  |  | 	m.UseMiddleware(hs.ContextHandler.Middleware) | 
					
						
							| 
									
										
										
										
											2022-09-27 19:58:49 +08:00
										 |  |  | 	m.Use(middleware.OrgRedirect(hs.Cfg, hs.userService)) | 
					
						
							| 
									
										
										
										
											2023-03-08 20:35:54 +08:00
										 |  |  | 	if !hs.Features.IsEnabled(featuremgmt.FlagAuthnService) { | 
					
						
							|  |  |  | 		m.Use(accesscontrol.LoadPermissionsMiddleware(hs.accesscontrolService)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// needs to be after context handler
 | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 	if hs.Cfg.EnforceDomain { | 
					
						
							| 
									
										
										
										
											2020-12-16 02:09:04 +08:00
										 |  |  | 		m.Use(middleware.ValidateHostHeader(hs.Cfg)) | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:42:32 +08:00
										 |  |  | 	m.Use(middleware.HandleNoCacheHeader) | 
					
						
							| 
									
										
										
										
											2022-11-17 01:11:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if hs.Cfg.CSPEnabled || hs.Cfg.CSPReportOnlyEnabled { | 
					
						
							|  |  |  | 		m.UseMiddleware(middleware.ContentSecurityPolicy(hs.Cfg, hs.log)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-07-23 15:54:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for _, mw := range hs.middlewares { | 
					
						
							|  |  |  | 		m.Use(mw) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | func (hs *HTTPServer) metricsEndpoint(ctx *web.Context) { | 
					
						
							| 
									
										
										
										
											2018-09-13 20:36:16 +08:00
										 |  |  | 	if !hs.Cfg.MetricsEndpointEnabled { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-12 13:27:47 +08:00
										 |  |  | 	if ctx.Req.Method != http.MethodGet || ctx.Req.URL.Path != "/metrics" { | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 02:15:18 +08:00
										 |  |  | 	if hs.metricsEndpointBasicAuthEnabled() && !BasicAuthenticatedRequest(ctx.Req, hs.Cfg.MetricsEndpointBasicAuthUsername, hs.Cfg.MetricsEndpointBasicAuthPassword) { | 
					
						
							| 
									
										
										
										
											2018-11-15 06:37:32 +08:00
										 |  |  | 		ctx.Resp.WriteHeader(http.StatusUnauthorized) | 
					
						
							|  |  |  | 		return | 
					
						
							| 
									
										
										
										
											2018-11-15 04:42:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-15 13:33:48 +08:00
										 |  |  | 	promhttp. | 
					
						
							| 
									
										
										
										
											2020-12-01 22:04:59 +08:00
										 |  |  | 		HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{EnableOpenMetrics: true}). | 
					
						
							| 
									
										
										
										
											2021-09-01 17:18:30 +08:00
										 |  |  | 		ServeHTTP(ctx.Resp, ctx.Req) | 
					
						
							| 
									
										
										
										
											2017-09-07 04:24:10 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 19:03:18 +08:00
										 |  |  | // healthzHandler always return 200 - Ok if Grafana's web server is running
 | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | func (hs *HTTPServer) healthzHandler(ctx *web.Context) { | 
					
						
							| 
									
										
										
										
											2020-10-02 13:14:26 +08:00
										 |  |  | 	notHeadOrGet := ctx.Req.Method != http.MethodGet && ctx.Req.Method != http.MethodHead | 
					
						
							|  |  |  | 	if notHeadOrGet || ctx.Req.URL.Path != "/healthz" { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 	ctx.Resp.WriteHeader(http.StatusOK) | 
					
						
							|  |  |  | 	if _, err := ctx.Resp.Write([]byte("Ok")); err != nil { | 
					
						
							| 
									
										
										
										
											2020-09-18 19:03:18 +08:00
										 |  |  | 		hs.log.Error("could not write to response", "err", err) | 
					
						
							| 
									
										
										
										
											2017-04-25 23:17:45 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-09-18 19:03:18 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-25 23:17:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-18 19:03:18 +08:00
										 |  |  | // apiHealthHandler will return ok if Grafana's web server is running and it
 | 
					
						
							| 
									
										
										
										
											2020-10-21 17:06:19 +08:00
										 |  |  | // can access the database. If the database cannot be accessed it will return
 | 
					
						
							| 
									
										
										
										
											2020-09-18 19:03:18 +08:00
										 |  |  | // http status code 503.
 | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | func (hs *HTTPServer) apiHealthHandler(ctx *web.Context) { | 
					
						
							| 
									
										
										
										
											2020-10-02 13:14:26 +08:00
										 |  |  | 	notHeadOrGet := ctx.Req.Method != http.MethodGet && ctx.Req.Method != http.MethodHead | 
					
						
							|  |  |  | 	if notHeadOrGet || ctx.Req.URL.Path != "/api/health" { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-25 23:17:45 +08:00
										 |  |  | 	data := simplejson.New() | 
					
						
							| 
									
										
										
										
											2017-04-25 23:23:38 +08:00
										 |  |  | 	data.Set("database", "ok") | 
					
						
							| 
									
										
										
										
											2020-06-17 13:39:50 +08:00
										 |  |  | 	if !hs.Cfg.AnonymousHideVersion { | 
					
						
							| 
									
										
										
										
											2021-03-10 19:41:29 +08:00
										 |  |  | 		data.Set("version", hs.Cfg.BuildVersion) | 
					
						
							|  |  |  | 		data.Set("commit", hs.Cfg.BuildCommit) | 
					
						
							| 
									
										
										
										
											2020-06-17 13:39:50 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-25 23:17:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-11 20:35:03 +08:00
										 |  |  | 	if !hs.databaseHealthy(ctx.Req.Context()) { | 
					
						
							| 
									
										
										
										
											2017-04-25 23:24:36 +08:00
										 |  |  | 		data.Set("database", "failing") | 
					
						
							| 
									
										
										
										
											2017-05-10 21:23:59 +08:00
										 |  |  | 		ctx.Resp.Header().Set("Content-Type", "application/json; charset=UTF-8") | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 		ctx.Resp.WriteHeader(http.StatusServiceUnavailable) | 
					
						
							| 
									
										
										
										
											2017-05-10 21:23:59 +08:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		ctx.Resp.Header().Set("Content-Type", "application/json; charset=UTF-8") | 
					
						
							| 
									
										
										
										
											2022-12-02 03:51:12 +08:00
										 |  |  | 		ctx.Resp.WriteHeader(http.StatusOK) | 
					
						
							| 
									
										
										
										
											2017-04-25 23:17:45 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-18 20:58:08 +08:00
										 |  |  | 	dataBytes, err := data.EncodePretty() | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		hs.log.Error("Failed to encode data", "err", err) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-09 00:57:53 +08:00
										 |  |  | 	if _, err := ctx.Resp.Write(dataBytes); err != nil { | 
					
						
							|  |  |  | 		hs.log.Error("Failed to write to response", "err", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-25 23:17:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 20:38:43 +08:00
										 |  |  | func (hs *HTTPServer) mapStatic(m *web.Mux, rootDir string, dir string, prefix string, exclude ...string) { | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	headers := func(c *web.Context) { | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 		c.Resp.Header().Set("Cache-Control", "public, max-age=3600") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 19:54:00 +08:00
										 |  |  | 	if prefix == "public/build" { | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 		headers = func(c *web.Context) { | 
					
						
							| 
									
										
										
										
											2018-05-08 19:54:00 +08:00
										 |  |  | 			c.Resp.Header().Set("Cache-Control", "public, max-age=31536000") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 18:44:44 +08:00
										 |  |  | 	if hs.Cfg.Env == setting.Dev { | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 		headers = func(c *web.Context) { | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 			c.Resp.Header().Set("Cache-Control", "max-age=0, must-revalidate, no-cache") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m.Use(httpstatic.Static( | 
					
						
							|  |  |  | 		path.Join(rootDir, dir), | 
					
						
							|  |  |  | 		httpstatic.StaticOptions{ | 
					
						
							|  |  |  | 			SkipLogging: true, | 
					
						
							|  |  |  | 			Prefix:      prefix, | 
					
						
							|  |  |  | 			AddHeaders:  headers, | 
					
						
							| 
									
										
										
										
											2022-02-08 20:38:43 +08:00
										 |  |  | 			Exclude:     exclude, | 
					
						
							| 
									
										
										
										
											2016-12-21 21:36:32 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	)) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-20 02:15:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (hs *HTTPServer) metricsEndpointBasicAuthEnabled() bool { | 
					
						
							|  |  |  | 	return hs.Cfg.MetricsEndpointBasicAuthUsername != "" && hs.Cfg.MetricsEndpointBasicAuthPassword != "" | 
					
						
							|  |  |  | } |