@oneuptime/common 12.0.5 → 12.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Models/DatabaseModels/AIRun.ts +33 -0
- package/Models/DatabaseModels/DataSource.ts +744 -0
- package/Models/DatabaseModels/Index.ts +3 -0
- package/Models/DatabaseModels/ProjectCallSMSConfig.ts +10 -2
- package/Models/DatabaseModels/User.ts +2 -0
- package/Models/DatabaseModels/UserOnCallLog.ts +2 -0
- package/Models/DatabaseModels/UserOnCallLogTimeline.ts +2 -0
- package/Models/DatabaseModels/UserSession.ts +2 -0
- package/Models/DatabaseModels/UserTotpAuth.ts +6 -4
- package/Models/DatabaseModels/UserWebAuthn.ts +5 -3
- package/Server/API/AIInsightAPI.ts +47 -4
- package/Server/API/AIInvestigationAPI.ts +25 -0
- package/Server/API/DashboardAPI.ts +176 -492
- package/Server/API/DataSourceAPI.ts +268 -0
- package/Server/API/StatusPageAPI.ts +11 -1
- package/Server/API/UserAPI.ts +119 -0
- package/Server/Infrastructure/ClickhouseConfig.ts +59 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1786303472848-AddDataSourceTable.ts +39 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1786600000000-AddInvestigationAnalysisTldr.ts +24 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1786700000000-DropProjectCallSMSConfigCredentialUniques.ts +76 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +6 -0
- package/Server/Infrastructure/Queue.ts +26 -0
- package/Server/Infrastructure/QueueWorker.ts +17 -0
- package/Server/Middleware/TelemetryIngest.ts +8 -3
- package/Server/Services/AIInsightService.ts +132 -12
- package/Server/Services/AIRunService.ts +34 -0
- package/Server/Services/AIService.ts +17 -2
- package/Server/Services/AlertService.ts +38 -32
- package/Server/Services/AnalyticsDatabaseService.ts +8 -4
- package/Server/Services/DataSourceService.ts +200 -0
- package/Server/Services/HostService.ts +92 -0
- package/Server/Services/IncidentService.ts +45 -0
- package/Server/Services/Index.ts +2 -0
- package/Server/Services/MonitorService.ts +49 -0
- package/Server/Services/MonitorStatusService.ts +166 -0
- package/Server/Services/OpenTelemetryIngestService.ts +255 -184
- package/Server/Services/RumSessionPinService.ts +7 -21
- package/Server/Services/StatusPageSubscriberService.ts +13 -0
- package/Server/Services/UserService.ts +280 -9
- package/Server/Static/Vendor/README.md +62 -0
- package/Server/Static/Vendor/fonts/InterVariable.woff2 +0 -0
- package/Server/Static/Vendor/highlight/highlight.min.js +1244 -0
- package/Server/Static/Vendor/highlight/languages/apache.min.js +15 -0
- package/Server/Static/Vendor/highlight/languages/bash.min.js +21 -0
- package/Server/Static/Vendor/highlight/languages/c.min.js +41 -0
- package/Server/Static/Vendor/highlight/languages/cpp.min.js +47 -0
- package/Server/Static/Vendor/highlight/languages/csharp.min.js +49 -0
- package/Server/Static/Vendor/highlight/languages/css.min.js +31 -0
- package/Server/Static/Vendor/highlight/languages/diff.min.js +9 -0
- package/Server/Static/Vendor/highlight/languages/dns.min.js +11 -0
- package/Server/Static/Vendor/highlight/languages/dockerfile.min.js +8 -0
- package/Server/Static/Vendor/highlight/languages/go.min.js +20 -0
- package/Server/Static/Vendor/highlight/languages/graphql.min.js +12 -0
- package/Server/Static/Vendor/highlight/languages/http.min.js +14 -0
- package/Server/Static/Vendor/highlight/languages/ini.min.js +15 -0
- package/Server/Static/Vendor/highlight/languages/java.min.js +38 -0
- package/Server/Static/Vendor/highlight/languages/javascript.min.js +81 -0
- package/Server/Static/Vendor/highlight/languages/json.min.js +8 -0
- package/Server/Static/Vendor/highlight/languages/kotlin.min.js +46 -0
- package/Server/Static/Vendor/highlight/languages/lua.min.js +15 -0
- package/Server/Static/Vendor/highlight/languages/makefile.min.js +14 -0
- package/Server/Static/Vendor/highlight/languages/nginx.min.js +21 -0
- package/Server/Static/Vendor/highlight/languages/perl.min.js +41 -0
- package/Server/Static/Vendor/highlight/languages/php.min.js +59 -0
- package/Server/Static/Vendor/highlight/languages/powershell.min.js +39 -0
- package/Server/Static/Vendor/highlight/languages/python.min.js +42 -0
- package/Server/Static/Vendor/highlight/languages/r.min.js +26 -0
- package/Server/Static/Vendor/highlight/languages/ruby.min.js +54 -0
- package/Server/Static/Vendor/highlight/languages/rust.min.js +27 -0
- package/Server/Static/Vendor/highlight/languages/scala.min.js +28 -0
- package/Server/Static/Vendor/highlight/languages/sql.min.js +21 -0
- package/Server/Static/Vendor/highlight/languages/swift.min.js +68 -0
- package/Server/Static/Vendor/highlight/languages/typescript.min.js +99 -0
- package/Server/Static/Vendor/highlight/languages/xml.min.js +29 -0
- package/Server/Static/Vendor/highlight/languages/yaml.min.js +28 -0
- package/Server/Static/Vendor/highlight/styles/github-dark.min.css +10 -0
- package/Server/Static/Vendor/highlight/styles/vs2015.min.css +1 -0
- package/Server/Static/Vendor/tailwind/tailwind-3.4.5.js +21028 -0
- package/Server/Types/Database/Permissions/BasePermission.ts +7 -0
- package/Server/Types/Database/Permissions/DeletePermission.ts +2 -0
- package/Server/Types/Database/Permissions/ReadPermission.ts +3 -0
- package/Server/Types/Database/Permissions/TenantPermission.ts +101 -16
- package/Server/Utils/AI/CodeFix/FixRunBudget.ts +2 -2
- package/Server/Utils/AI/SRE/AIInvestigationEngine.ts +90 -11
- package/Server/Utils/AI/SRE/AlertInvestigationRunner.ts +1 -0
- package/Server/Utils/AI/SRE/IncidentInvestigationRunner.ts +1 -0
- package/Server/Utils/AI/SRE/Insights/Detectors/ExceptionIdentity.ts +125 -0
- package/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.ts +25 -15
- package/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.ts +256 -57
- package/Server/Utils/AI/SRE/Insights/InsightStore.ts +76 -18
- package/Server/Utils/AI/SRE/InvestigationTldr.ts +352 -0
- package/Server/Utils/AnalyticsDatabase/InsertDedupContext.ts +7 -2
- package/Server/Utils/Dashboard/PublicDashboardResourceListPolicy.ts +1793 -0
- package/Server/Utils/Dashboard/PublicDashboardViewConfig.ts +65 -0
- package/Server/Utils/DataSource/ConnectorRegistry.ts +53 -0
- package/Server/Utils/DataSource/Connectors/ClickHouseConnector.ts +338 -0
- package/Server/Utils/DataSource/Connectors/ElasticsearchConnector.ts +717 -0
- package/Server/Utils/DataSource/Connectors/LokiConnector.ts +606 -0
- package/Server/Utils/DataSource/Connectors/MySqlConnector.ts +307 -0
- package/Server/Utils/DataSource/Connectors/PostgresConnector.ts +260 -0
- package/Server/Utils/DataSource/Connectors/PrometheusConnector.ts +555 -0
- package/Server/Utils/DataSource/Connectors/RestApiConnector.ts +597 -0
- package/Server/Utils/DataSource/Connectors/SqlServerConnector.ts +318 -0
- package/Server/Utils/DataSource/EgressGuard.ts +446 -0
- package/Server/Utils/DataSource/HttpFetch.ts +221 -0
- package/Server/Utils/DataSource/SqlQueryGuard.ts +383 -0
- package/Server/Utils/DataSource/SqlResultShaper.ts +372 -0
- package/Server/Utils/DataSource/Types.ts +93 -0
- package/Server/Utils/Database/PostgresErrorTranslator.ts +172 -17
- package/Server/Utils/InProcessMemo.ts +141 -0
- package/Server/Utils/InstanceHealth/TelemetryIngestion.ts +628 -0
- package/Server/Utils/Monitor/MonitorMetricUtil.ts +58 -0
- package/Server/Utils/Monitor/MonitorResource.ts +14 -0
- package/Server/Utils/Response.ts +12 -1
- package/Server/Utils/SSRFProtection.ts +237 -0
- package/Server/Utils/StartServer.ts +8 -0
- package/Server/Utils/StatusPageSubscriberWebhook.ts +30 -0
- package/Server/Utils/Telemetry/CaptureSpan.ts +30 -18
- package/Server/Utils/Telemetry/IngestionTimestamp.ts +75 -0
- package/Server/Utils/Telemetry/ResourceHeartbeat.ts +99 -7
- package/Server/Utils/Telemetry/Telemetry.ts +112 -1
- package/Server/Utils/Telemetry.ts +104 -3
- package/Server/Utils/VendorAssets.ts +165 -0
- package/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.ts +28 -5
- package/Server/Utils/Workspace/Slack/Slack.ts +5 -0
- package/Server/Views/Partials/Head.ejs +21 -7
- package/Tests/App/AdminDashboard/AdminProjectsIdFilter.test.tsx +207 -0
- package/Tests/App/AdminDashboard/AdminUsersIdFilter.test.tsx +216 -0
- package/Tests/App/Dashboard/AIInsightViewActions.test.tsx +422 -0
- package/Tests/App/Dashboard/AddWidgetModal.test.tsx +10 -3
- package/Tests/App/Dashboard/AlertsSideMenu.test.tsx +387 -0
- package/Tests/App/Dashboard/ChatActivityFeed.test.tsx +199 -0
- package/Tests/App/Dashboard/DataSourceChartSyntheticConfig.test.tsx +736 -0
- package/Tests/App/Dashboard/DataSourceQueryEditor.test.tsx +868 -0
- package/Tests/App/Dashboard/DataSourceWidgetCatalog.test.ts +440 -0
- package/Tests/App/Dashboard/DataSourceWidgetFetching.test.tsx +2109 -0
- package/Tests/App/Dashboard/DataSourceWidgetViews.test.tsx +726 -0
- package/Tests/App/Dashboard/IncidentsSideMenu.test.tsx +447 -0
- package/Tests/App/Dashboard/InvestigationPanel.test.tsx +514 -3
- package/Tests/App/Dashboard/ProductMenuBreadcrumbs.test.tsx +391 -0
- package/Tests/App/Dashboard/ScheduledMaintenanceSideMenu.test.tsx +326 -0
- package/Tests/App/Dashboard/SideMenuHarness.tsx +187 -0
- package/Tests/App/Dashboard/WidgetCatalog.test.ts +6 -1
- package/Tests/App/StatusPage/StatusPageResourceExplorer.test.tsx +1858 -0
- package/Tests/Models/DatabaseModels/DataSourceModelSecrets.test.ts +70 -0
- package/Tests/Server/API/AIInvestigationAPI.test.ts +187 -0
- package/Tests/Server/API/DashboardPublicDataSourceStrip.test.ts +686 -0
- package/Tests/Server/API/DashboardPublicResourceListAPI.test.ts +585 -823
- package/Tests/Server/API/DataSourceAPIRoutes.test.ts +486 -0
- package/Tests/Server/API/StatusPageSubscriberOwnership.test.ts +291 -0
- package/Tests/Server/API/UserAuthenticationAPI.test.ts +641 -0
- package/Tests/Server/Infrastructure/ClickhouseKeepAliveOptions.test.ts +441 -0
- package/Tests/Server/Middleware/TelemetryIngestTokenLog.test.ts +140 -0
- package/Tests/Server/Services/AIInsightService.test.ts +266 -11
- package/Tests/Server/Services/AIRunAnalysisTldrPersistence.test.ts +160 -0
- package/Tests/Server/Services/AIServiceDailyBudget.test.ts +4 -0
- package/Tests/Server/Services/AlertMetricResourceAttributes.test.ts +352 -0
- package/Tests/Server/Services/DataSourceServiceSettings.test.ts +244 -0
- package/Tests/Server/Services/HostServiceFindOrCreateMemo.test.ts +397 -0
- package/Tests/Server/Services/HostServiceUpdateLastSeen.test.ts +41 -2
- package/Tests/Server/Services/IncidentMetricResourceAttributes.test.ts +408 -0
- package/Tests/Server/Services/MonitorStatusServiceDeleteReferenceCleanup.test.ts +351 -0
- package/Tests/Server/Services/MonitorStatusServiceValidation.test.ts +171 -0
- package/Tests/Server/Services/OpenTelemetryResourceRetentionMemo.test.ts +398 -0
- package/Tests/Server/Services/OpenTelemetryServiceResolutionCache.test.ts +19 -0
- package/Tests/Server/Services/ProjectCallSMSConfigCredentialUniqueness.test.ts +305 -0
- package/Tests/Server/Services/ResourceUpdateLastSeenLivenessFallback.test.ts +36 -1
- package/Tests/Server/Services/RumSessionPinUniqueViolationRecovery.test.ts +163 -0
- package/Tests/Server/Services/UserAuthenticationService.test.ts +973 -0
- package/Tests/Server/Types/Database/ObjectIdColumnQuery.test.ts +262 -0
- package/Tests/Server/Types/Database/Permissions/TenantPermission.test.ts +358 -0
- package/Tests/Server/Utils/AI/FixRunBudget.test.ts +2 -2
- package/Tests/Server/Utils/AI/Insights/ExceptionSpikeDetector.test.ts +6 -1
- package/Tests/Server/Utils/AI/Insights/InsightStore.test.ts +121 -4
- package/Tests/Server/Utils/AI/Insights/NewExceptionDetector.test.ts +361 -10
- package/Tests/Server/Utils/AI/InvestigationSettlement.test.ts +292 -0
- package/Tests/Server/Utils/AI/InvestigationTldr.test.ts +623 -0
- package/Tests/Server/Utils/AI/InvestigationTldrWiring.test.ts +98 -0
- package/Tests/Server/Utils/Dashboard/PublicDashboardResourceListPolicy.test.ts +857 -0
- package/Tests/Server/Utils/Dashboard/PublicDashboardViewConfig.test.ts +480 -0
- package/Tests/Server/Utils/DataSource/ClickHouseConnector.test.ts +759 -0
- package/Tests/Server/Utils/DataSource/ConnectorRegistry.test.ts +37 -0
- package/Tests/Server/Utils/DataSource/EgressGuard.test.ts +645 -0
- package/Tests/Server/Utils/DataSource/ElasticsearchConnector.test.ts +1206 -0
- package/Tests/Server/Utils/DataSource/HttpFetch.test.ts +616 -0
- package/Tests/Server/Utils/DataSource/LokiConnector.test.ts +970 -0
- package/Tests/Server/Utils/DataSource/MySqlConnector.test.ts +935 -0
- package/Tests/Server/Utils/DataSource/PostgresConnector.test.ts +854 -0
- package/Tests/Server/Utils/DataSource/PrometheusConnector.test.ts +881 -0
- package/Tests/Server/Utils/DataSource/RestApiConnector.test.ts +1020 -0
- package/Tests/Server/Utils/DataSource/SqlQueryGuard.test.ts +425 -0
- package/Tests/Server/Utils/DataSource/SqlResultShaper.test.ts +555 -0
- package/Tests/Server/Utils/DataSource/SqlServerConnector.test.ts +934 -0
- package/Tests/Server/Utils/Database/PostgresErrorTranslator.test.ts +228 -7
- package/Tests/Server/Utils/InProcessMemo.test.ts +292 -0
- package/Tests/Server/Utils/InstanceHealth/TelemetryIngestion.test.ts +960 -0
- package/Tests/Server/Utils/MicrosoftTeamsWebhookUrlValidation.test.ts +103 -0
- package/Tests/Server/Utils/Monitor/MonitorMetricResourceAttributes.test.ts +336 -0
- package/Tests/Server/Utils/OfflineAssetHygiene.test.ts +521 -0
- package/Tests/Server/Utils/ResponseRenderAnalytics.test.ts +143 -0
- package/Tests/Server/Utils/SSRFProtection.test.ts +193 -0
- package/Tests/Server/Utils/StatusPageSubscriberWebhook.test.ts +101 -0
- package/Tests/Server/Utils/TailwindBuildCopy.test.ts +225 -0
- package/Tests/Server/Utils/Telemetry/ResourceHeartbeatL1Memo.test.ts +355 -0
- package/Tests/Server/Utils/Telemetry/TelemetryFanInWriter.test.ts +128 -0
- package/Tests/Server/Utils/Telemetry/TelemetryUtilAttributeKeys.test.ts +381 -0
- package/Tests/Server/Utils/Telemetry.test.ts +87 -0
- package/Tests/Server/Utils/VendorAssetIntegrity.test.ts +343 -0
- package/Tests/Server/Utils/VendorAssets.test.ts +671 -0
- package/Tests/Server/Views/OfflineRender.test.ts +297 -0
- package/Tests/Types/Dashboard/DataSourceComponentTypes.test.ts +618 -0
- package/Tests/Types/DateClickhouseFormat.test.ts +192 -0
- package/Tests/Types/Password.test.ts +363 -0
- package/Tests/UI/Components/ConfirmModal.test.tsx +7 -0
- package/Tests/UI/Components/ErrorBoundary.test.tsx +53 -0
- package/Tests/UI/Components/Modal.test.tsx +281 -1
- package/Tests/UI/Components/ObjectIdFilterPipeline.test.tsx +396 -0
- package/Tests/UI/Components/StatusPage/ResourceGroupNavigator.test.tsx +1147 -0
- package/Tests/UI/Utils/Breadcrumb/fixtures/RealBreadcrumbTrails.ts +116 -1
- package/Tests/UI/Utils/Breadcrumb/fixtures/RealRoutePatterns.ts +2 -0
- package/Tests/Utils/Analytics.test.ts +23 -0
- package/Tests/Utils/Dashboard/Components/DashboardDataSourceComponents.test.ts +640 -0
- package/Tests/Utils/DataSource/DataSourceQueryText.test.ts +138 -0
- package/Tests/Utils/DataSource/DataSourceValueReducer.test.ts +526 -0
- package/Tests/Utils/Metrics/MetricResourceAttributeUtil.test.ts +691 -0
- package/Tests/Utils/StatusPage/GroupHierarchyView.test.ts +1452 -0
- package/Tests/Utils/StatusPage/ResourceExplorer.test.ts +931 -0
- package/Tests/Utils/Telemetry/CaptureSpanExportGating.test.ts +288 -0
- package/Tests/Utils/Telemetry/IngestionTimestamp.test.ts +170 -0
- package/Types/AI/AIInsightEvidence.ts +6 -0
- package/Types/Analytics/RevenueEvent.ts +31 -0
- package/Types/Dashboard/DashboardComponentType.ts +31 -0
- package/Types/Dashboard/DashboardComponents/DashboardDataSourceChartComponent.ts +27 -0
- package/Types/Dashboard/DashboardComponents/DashboardDataSourceGaugeComponent.ts +32 -0
- package/Types/Dashboard/DashboardComponents/DashboardDataSourceTableComponent.ts +30 -0
- package/Types/Dashboard/DashboardComponents/DashboardDataSourceValueComponent.ts +55 -0
- package/Types/DataSource/DataSourceLimits.ts +62 -0
- package/Types/DataSource/DataSourceQueryConfig.ts +41 -0
- package/Types/DataSource/DataSourceTableResult.ts +38 -0
- package/Types/DataSource/DataSourceType.ts +213 -0
- package/Types/Date.ts +43 -3
- package/Types/Password.ts +64 -0
- package/Types/Permission.ts +46 -0
- package/Types/UserAuthenticationStatus.ts +34 -0
- package/UI/Components/Button/Button.tsx +1 -1
- package/UI/Components/ErrorBoundary.tsx +459 -108
- package/UI/Components/Icon/Icon.tsx +10 -9
- package/UI/Components/Modal/ConfirmModal.tsx +6 -1
- package/UI/Components/Modal/Modal.tsx +267 -35
- package/UI/Components/Modal/ModalFooter.tsx +6 -1
- package/UI/Components/MoreMenu/MoreMenu.tsx +19 -4
- package/UI/Components/MoreMenu/MoreMenuItem.tsx +6 -1
- package/UI/Components/StatusPage/ResourceGrid.tsx +314 -0
- package/UI/Components/StatusPage/ResourceGroupNavigator.tsx +808 -0
- package/UI/Components/StatusPage/ResourceList.tsx +570 -0
- package/UI/Styles/Theme.css +18 -0
- package/UI/Utils/API/RequestOptions.ts +7 -0
- package/UI/Utils/AnalyticsModelAPI/AnalyticsModelAPI.ts +1 -0
- package/UI/Utils/ModelAPI/ModelAPI.ts +1 -0
- package/UI/Utils/TestDataSource.ts +61 -0
- package/UI/esbuild-config.js +45 -0
- package/Utils/Analytics.ts +15 -0
- package/Utils/Dashboard/Components/DashboardDataSourceChartComponent.ts +88 -0
- package/Utils/Dashboard/Components/DashboardDataSourceGaugeComponent.ts +123 -0
- package/Utils/Dashboard/Components/DashboardDataSourceShared.ts +16 -0
- package/Utils/Dashboard/Components/DashboardDataSourceTableComponent.ts +72 -0
- package/Utils/Dashboard/Components/DashboardDataSourceValueComponent.ts +126 -0
- package/Utils/Dashboard/Components/Index.ts +28 -0
- package/Utils/DataSource/DataSourceQueryText.ts +94 -0
- package/Utils/DataSource/DataSourceValueReducer.ts +156 -0
- package/Utils/Metrics/MetricResourceAttributeUtil.ts +380 -0
- package/Utils/NetworkDiscovery/ScanTargetUtil.ts +8 -6
- package/Utils/StatusPage/GroupHierarchyView.ts +931 -0
- package/Utils/StatusPage/ResourceExplorer.ts +853 -0
- package/build/dist/Models/DatabaseModels/AIRun.js +34 -0
- package/build/dist/Models/DatabaseModels/AIRun.js.map +1 -1
- package/build/dist/Models/DatabaseModels/DataSource.js +774 -0
- package/build/dist/Models/DatabaseModels/DataSource.js.map +1 -0
- package/build/dist/Models/DatabaseModels/Index.js +2 -0
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/ProjectCallSMSConfig.js +14 -4
- package/build/dist/Models/DatabaseModels/ProjectCallSMSConfig.js.map +1 -1
- package/build/dist/Models/DatabaseModels/User.js +2 -0
- package/build/dist/Models/DatabaseModels/User.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserOnCallLog.js +2 -0
- package/build/dist/Models/DatabaseModels/UserOnCallLog.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserOnCallLogTimeline.js +2 -0
- package/build/dist/Models/DatabaseModels/UserOnCallLogTimeline.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserSession.js +2 -0
- package/build/dist/Models/DatabaseModels/UserSession.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserTotpAuth.js +6 -4
- package/build/dist/Models/DatabaseModels/UserTotpAuth.js.map +1 -1
- package/build/dist/Models/DatabaseModels/UserWebAuthn.js +5 -3
- package/build/dist/Models/DatabaseModels/UserWebAuthn.js.map +1 -1
- package/build/dist/Server/API/AIInsightAPI.js +34 -4
- package/build/dist/Server/API/AIInsightAPI.js.map +1 -1
- package/build/dist/Server/API/AIInvestigationAPI.js +23 -0
- package/build/dist/Server/API/AIInvestigationAPI.js.map +1 -1
- package/build/dist/Server/API/DashboardAPI.js +119 -433
- package/build/dist/Server/API/DashboardAPI.js.map +1 -1
- package/build/dist/Server/API/DataSourceAPI.js +173 -0
- package/build/dist/Server/API/DataSourceAPI.js.map +1 -0
- package/build/dist/Server/API/StatusPageAPI.js +11 -1
- package/build/dist/Server/API/StatusPageAPI.js.map +1 -1
- package/build/dist/Server/API/UserAPI.js +94 -2
- package/build/dist/Server/API/UserAPI.js.map +1 -1
- package/build/dist/Server/Infrastructure/ClickhouseConfig.js +49 -0
- package/build/dist/Server/Infrastructure/ClickhouseConfig.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1786303472848-AddDataSourceTable.js +20 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1786303472848-AddDataSourceTable.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1786600000000-AddInvestigationAnalysisTldr.js +19 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1786600000000-AddInvestigationAnalysisTldr.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1786700000000-DropProjectCallSMSConfigCredentialUniques.js +64 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1786700000000-DropProjectCallSMSConfigCredentialUniques.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +6 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Infrastructure/Queue.js +27 -0
- package/build/dist/Server/Infrastructure/Queue.js.map +1 -1
- package/build/dist/Server/Infrastructure/QueueWorker.js +13 -0
- package/build/dist/Server/Infrastructure/QueueWorker.js.map +1 -1
- package/build/dist/Server/Middleware/TelemetryIngest.js +8 -3
- package/build/dist/Server/Middleware/TelemetryIngest.js.map +1 -1
- package/build/dist/Server/Services/AIInsightService.js +110 -10
- package/build/dist/Server/Services/AIInsightService.js.map +1 -1
- package/build/dist/Server/Services/AIRunService.js +34 -0
- package/build/dist/Server/Services/AIRunService.js.map +1 -1
- package/build/dist/Server/Services/AIService.js +16 -2
- package/build/dist/Server/Services/AIService.js.map +1 -1
- package/build/dist/Server/Services/AlertService.js +28 -35
- package/build/dist/Server/Services/AlertService.js.map +1 -1
- package/build/dist/Server/Services/AnalyticsDatabaseService.js +8 -4
- package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
- package/build/dist/Server/Services/DataSourceService.js +159 -0
- package/build/dist/Server/Services/DataSourceService.js.map +1 -0
- package/build/dist/Server/Services/HostService.js +74 -0
- package/build/dist/Server/Services/HostService.js.map +1 -1
- package/build/dist/Server/Services/IncidentService.js +35 -24
- package/build/dist/Server/Services/IncidentService.js.map +1 -1
- package/build/dist/Server/Services/Index.js +2 -0
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Services/MonitorService.js +45 -0
- package/build/dist/Server/Services/MonitorService.js.map +1 -1
- package/build/dist/Server/Services/MonitorStatusService.js +129 -0
- package/build/dist/Server/Services/MonitorStatusService.js.map +1 -1
- package/build/dist/Server/Services/OpenTelemetryIngestService.js +222 -159
- package/build/dist/Server/Services/OpenTelemetryIngestService.js.map +1 -1
- package/build/dist/Server/Services/RumSessionPinService.js +7 -15
- package/build/dist/Server/Services/RumSessionPinService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageSubscriberService.js +10 -0
- package/build/dist/Server/Services/StatusPageSubscriberService.js.map +1 -1
- package/build/dist/Server/Services/UserService.js +241 -10
- package/build/dist/Server/Services/UserService.js.map +1 -1
- package/build/dist/Server/Types/Database/Permissions/BasePermission.js +6 -0
- package/build/dist/Server/Types/Database/Permissions/BasePermission.js.map +1 -1
- package/build/dist/Server/Types/Database/Permissions/DeletePermission.js +1 -0
- package/build/dist/Server/Types/Database/Permissions/DeletePermission.js.map +1 -1
- package/build/dist/Server/Types/Database/Permissions/ReadPermission.js +2 -0
- package/build/dist/Server/Types/Database/Permissions/ReadPermission.js.map +1 -1
- package/build/dist/Server/Types/Database/Permissions/TenantPermission.js +68 -12
- package/build/dist/Server/Types/Database/Permissions/TenantPermission.js.map +1 -1
- package/build/dist/Server/Utils/AI/CodeFix/FixRunBudget.js +2 -2
- package/build/dist/Server/Utils/AI/CodeFix/FixRunBudget.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/AIInvestigationEngine.js +68 -8
- package/build/dist/Server/Utils/AI/SRE/AIInvestigationEngine.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/AlertInvestigationRunner.js +1 -0
- package/build/dist/Server/Utils/AI/SRE/AlertInvestigationRunner.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/IncidentInvestigationRunner.js +1 -0
- package/build/dist/Server/Utils/AI/SRE/IncidentInvestigationRunner.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionIdentity.js +97 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionIdentity.js.map +1 -0
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js +17 -15
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/ExceptionSpikeDetector.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js +178 -54
- package/build/dist/Server/Utils/AI/SRE/Insights/Detectors/NewExceptionDetector.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightStore.js +65 -16
- package/build/dist/Server/Utils/AI/SRE/Insights/InsightStore.js.map +1 -1
- package/build/dist/Server/Utils/AI/SRE/InvestigationTldr.js +303 -0
- package/build/dist/Server/Utils/AI/SRE/InvestigationTldr.js.map +1 -0
- package/build/dist/Server/Utils/AnalyticsDatabase/InsertDedupContext.js.map +1 -1
- package/build/dist/Server/Utils/Dashboard/PublicDashboardResourceListPolicy.js +1261 -0
- package/build/dist/Server/Utils/Dashboard/PublicDashboardResourceListPolicy.js.map +1 -0
- package/build/dist/Server/Utils/Dashboard/PublicDashboardViewConfig.js +47 -0
- package/build/dist/Server/Utils/Dashboard/PublicDashboardViewConfig.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/ConnectorRegistry.js +42 -0
- package/build/dist/Server/Utils/DataSource/ConnectorRegistry.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Connectors/ClickHouseConnector.js +187 -0
- package/build/dist/Server/Utils/DataSource/Connectors/ClickHouseConnector.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Connectors/ElasticsearchConnector.js +493 -0
- package/build/dist/Server/Utils/DataSource/Connectors/ElasticsearchConnector.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Connectors/LokiConnector.js +399 -0
- package/build/dist/Server/Utils/DataSource/Connectors/LokiConnector.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Connectors/MySqlConnector.js +195 -0
- package/build/dist/Server/Utils/DataSource/Connectors/MySqlConnector.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Connectors/PostgresConnector.js +149 -0
- package/build/dist/Server/Utils/DataSource/Connectors/PostgresConnector.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Connectors/PrometheusConnector.js +362 -0
- package/build/dist/Server/Utils/DataSource/Connectors/PrometheusConnector.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Connectors/RestApiConnector.js +342 -0
- package/build/dist/Server/Utils/DataSource/Connectors/RestApiConnector.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Connectors/SqlServerConnector.js +186 -0
- package/build/dist/Server/Utils/DataSource/Connectors/SqlServerConnector.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/EgressGuard.js +305 -0
- package/build/dist/Server/Utils/DataSource/EgressGuard.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/HttpFetch.js +134 -0
- package/build/dist/Server/Utils/DataSource/HttpFetch.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/SqlQueryGuard.js +331 -0
- package/build/dist/Server/Utils/DataSource/SqlQueryGuard.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/SqlResultShaper.js +280 -0
- package/build/dist/Server/Utils/DataSource/SqlResultShaper.js.map +1 -0
- package/build/dist/Server/Utils/DataSource/Types.js +2 -0
- package/build/dist/Server/Utils/DataSource/Types.js.map +1 -0
- package/build/dist/Server/Utils/Database/PostgresErrorTranslator.js +103 -9
- package/build/dist/Server/Utils/Database/PostgresErrorTranslator.js.map +1 -1
- package/build/dist/Server/Utils/InProcessMemo.js +113 -0
- package/build/dist/Server/Utils/InProcessMemo.js.map +1 -0
- package/build/dist/Server/Utils/InstanceHealth/TelemetryIngestion.js +406 -0
- package/build/dist/Server/Utils/InstanceHealth/TelemetryIngestion.js.map +1 -0
- package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js +34 -0
- package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorResource.js +14 -0
- package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
- package/build/dist/Server/Utils/Response.js +9 -1
- package/build/dist/Server/Utils/Response.js.map +1 -1
- package/build/dist/Server/Utils/SSRFProtection.js +192 -0
- package/build/dist/Server/Utils/SSRFProtection.js.map +1 -0
- package/build/dist/Server/Utils/StartServer.js +7 -0
- package/build/dist/Server/Utils/StartServer.js.map +1 -1
- package/build/dist/Server/Utils/StatusPageSubscriberWebhook.js +24 -0
- package/build/dist/Server/Utils/StatusPageSubscriberWebhook.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/CaptureSpan.js +25 -11
- package/build/dist/Server/Utils/Telemetry/CaptureSpan.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/IngestionTimestamp.js +32 -0
- package/build/dist/Server/Utils/Telemetry/IngestionTimestamp.js.map +1 -0
- package/build/dist/Server/Utils/Telemetry/ResourceHeartbeat.js +92 -5
- package/build/dist/Server/Utils/Telemetry/ResourceHeartbeat.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/Telemetry.js +92 -6
- package/build/dist/Server/Utils/Telemetry/Telemetry.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry.js +93 -6
- package/build/dist/Server/Utils/Telemetry.js.map +1 -1
- package/build/dist/Server/Utils/VendorAssets.js +121 -0
- package/build/dist/Server/Utils/VendorAssets.js.map +1 -0
- package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +25 -4
- package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js +5 -0
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
- package/build/dist/Types/Analytics/RevenueEvent.js +26 -0
- package/build/dist/Types/Analytics/RevenueEvent.js.map +1 -0
- package/build/dist/Types/Dashboard/DashboardComponentType.js +27 -0
- package/build/dist/Types/Dashboard/DashboardComponentType.js.map +1 -1
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardDataSourceChartComponent.js +2 -0
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardDataSourceChartComponent.js.map +1 -0
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardDataSourceGaugeComponent.js +2 -0
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardDataSourceGaugeComponent.js.map +1 -0
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardDataSourceTableComponent.js +2 -0
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardDataSourceTableComponent.js.map +1 -0
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardDataSourceValueComponent.js +16 -0
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardDataSourceValueComponent.js.map +1 -0
- package/build/dist/Types/DataSource/DataSourceLimits.js +47 -0
- package/build/dist/Types/DataSource/DataSourceLimits.js.map +1 -0
- package/build/dist/Types/DataSource/DataSourceQueryConfig.js +10 -0
- package/build/dist/Types/DataSource/DataSourceQueryConfig.js.map +1 -0
- package/build/dist/Types/DataSource/DataSourceTableResult.js +14 -0
- package/build/dist/Types/DataSource/DataSourceTableResult.js.map +1 -0
- package/build/dist/Types/DataSource/DataSourceType.js +183 -0
- package/build/dist/Types/DataSource/DataSourceType.js.map +1 -0
- package/build/dist/Types/Date.js +38 -3
- package/build/dist/Types/Date.js.map +1 -1
- package/build/dist/Types/Password.js +56 -0
- package/build/dist/Types/Password.js.map +1 -0
- package/build/dist/Types/Permission.js +42 -0
- package/build/dist/Types/Permission.js.map +1 -1
- package/build/dist/Types/UserAuthenticationStatus.js +2 -0
- package/build/dist/Types/UserAuthenticationStatus.js.map +1 -0
- package/build/dist/UI/Components/ErrorBoundary.js +388 -72
- package/build/dist/UI/Components/ErrorBoundary.js.map +1 -1
- package/build/dist/UI/Components/Icon/Icon.js +10 -4
- package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
- package/build/dist/UI/Components/Modal/ConfirmModal.js +1 -1
- package/build/dist/UI/Components/Modal/ConfirmModal.js.map +1 -1
- package/build/dist/UI/Components/Modal/Modal.js +178 -19
- package/build/dist/UI/Components/Modal/Modal.js.map +1 -1
- package/build/dist/UI/Components/Modal/ModalFooter.js +3 -1
- package/build/dist/UI/Components/Modal/ModalFooter.js.map +1 -1
- package/build/dist/UI/Components/MoreMenu/MoreMenu.js +9 -6
- package/build/dist/UI/Components/MoreMenu/MoreMenu.js.map +1 -1
- package/build/dist/UI/Components/MoreMenu/MoreMenuItem.js +7 -1
- package/build/dist/UI/Components/MoreMenu/MoreMenuItem.js.map +1 -1
- package/build/dist/UI/Components/StatusPage/ResourceGrid.js +119 -0
- package/build/dist/UI/Components/StatusPage/ResourceGrid.js.map +1 -0
- package/build/dist/UI/Components/StatusPage/ResourceGroupNavigator.js +354 -0
- package/build/dist/UI/Components/StatusPage/ResourceGroupNavigator.js.map +1 -0
- package/build/dist/UI/Components/StatusPage/ResourceList.js +203 -0
- package/build/dist/UI/Components/StatusPage/ResourceList.js.map +1 -0
- package/build/dist/UI/Utils/AnalyticsModelAPI/AnalyticsModelAPI.js +1 -6
- package/build/dist/UI/Utils/AnalyticsModelAPI/AnalyticsModelAPI.js.map +1 -1
- package/build/dist/UI/Utils/ModelAPI/ModelAPI.js +3 -8
- package/build/dist/UI/Utils/ModelAPI/ModelAPI.js.map +1 -1
- package/build/dist/UI/Utils/TestDataSource.js +39 -0
- package/build/dist/UI/Utils/TestDataSource.js.map +1 -0
- package/build/dist/Utils/Analytics.js +4 -0
- package/build/dist/Utils/Analytics.js.map +1 -1
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceChartComponent.js +79 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceChartComponent.js.map +1 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceGaugeComponent.js +111 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceGaugeComponent.js.map +1 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceShared.js +15 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceShared.js.map +1 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceTableComponent.js +62 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceTableComponent.js.map +1 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceValueComponent.js +112 -0
- package/build/dist/Utils/Dashboard/Components/DashboardDataSourceValueComponent.js.map +1 -0
- package/build/dist/Utils/Dashboard/Components/Index.js +16 -0
- package/build/dist/Utils/Dashboard/Components/Index.js.map +1 -1
- package/build/dist/Utils/DataSource/DataSourceQueryText.js +64 -0
- package/build/dist/Utils/DataSource/DataSourceQueryText.js.map +1 -0
- package/build/dist/Utils/DataSource/DataSourceValueReducer.js +124 -0
- package/build/dist/Utils/DataSource/DataSourceValueReducer.js.map +1 -0
- package/build/dist/Utils/Metrics/MetricResourceAttributeUtil.js +281 -0
- package/build/dist/Utils/Metrics/MetricResourceAttributeUtil.js.map +1 -0
- package/build/dist/Utils/NetworkDiscovery/ScanTargetUtil.js +8 -6
- package/build/dist/Utils/NetworkDiscovery/ScanTargetUtil.js.map +1 -1
- package/build/dist/Utils/StatusPage/GroupHierarchyView.js +560 -0
- package/build/dist/Utils/StatusPage/GroupHierarchyView.js.map +1 -0
- package/build/dist/Utils/StatusPage/ResourceExplorer.js +519 -0
- package/build/dist/Utils/StatusPage/ResourceExplorer.js.map +1 -0
- package/jest.config.json +1 -0
- package/package.json +5 -1
- package/tsconfig.json +12 -10
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { DATA_SOURCE_CONNECT_TIMEOUT_IN_MS, DATA_SOURCE_MAX_SERIES, DATA_SOURCE_MAX_TABLE_ROWS, DATA_SOURCE_MAX_TIME_SERIES_ROWS, DATA_SOURCE_QUERY_TIMEOUT_IN_MS, DataSourceLimitsUtil, } from "../../../../Types/DataSource/DataSourceLimits";
|
|
2
|
+
import DataSourceType from "../../../../Types/DataSource/DataSourceType";
|
|
3
|
+
import BadDataException from "../../../../Types/Exception/BadDataException";
|
|
4
|
+
import DataSourceHttpFetch from "../HttpFetch";
|
|
5
|
+
import SqlResultShaper from "../SqlResultShaper";
|
|
6
|
+
const NANOSECONDS_PER_MILLISECOND = BigInt(1000000);
|
|
7
|
+
// Optionally-signed base-10 integer string, the shape BigInt() accepts.
|
|
8
|
+
const INTEGER_STRING_REGEX = /^-?\d+$/;
|
|
9
|
+
/*
|
|
10
|
+
* Exact unix-nanosecond string for a Date. BigInt math keeps every digit:
|
|
11
|
+
* 1699999999999 ms * 1e6 is above 2^53, where float multiplication would
|
|
12
|
+
* round the tail off.
|
|
13
|
+
*/
|
|
14
|
+
export function toLokiNanoseconds(date) {
|
|
15
|
+
return (BigInt(date.getTime()) * NANOSECONDS_PER_MILLISECOND).toString();
|
|
16
|
+
}
|
|
17
|
+
/*
|
|
18
|
+
* Parse a Loki nanosecond timestamp (string in stream entries; tolerate a
|
|
19
|
+
* number for robustness). Returns null when unparseable. Strings are kept
|
|
20
|
+
* out of Number() entirely — 19-digit nanosecond epochs do not fit in a
|
|
21
|
+
* float.
|
|
22
|
+
*/
|
|
23
|
+
export function parseLokiNanoseconds(raw) {
|
|
24
|
+
if (typeof raw === "number" && Number.isFinite(raw)) {
|
|
25
|
+
return BigInt(Math.trunc(raw));
|
|
26
|
+
}
|
|
27
|
+
if (typeof raw !== "string") {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const trimmed = raw.trim();
|
|
31
|
+
if (!INTEGER_STRING_REGEX.test(trimmed)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return BigInt(trimmed);
|
|
35
|
+
}
|
|
36
|
+
/*
|
|
37
|
+
* Nanosecond epoch -> Date (millisecond precision; sub-millisecond digits
|
|
38
|
+
* are truncated). Division happens in BigInt space BEFORE converting to a
|
|
39
|
+
* Number so the millisecond value is exact.
|
|
40
|
+
*/
|
|
41
|
+
export function lokiNanosecondsToDate(raw) {
|
|
42
|
+
const nanoseconds = parseLokiNanoseconds(raw);
|
|
43
|
+
if (nanoseconds === null) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const date = new Date(Number(nanoseconds / NANOSECONDS_PER_MILLISECOND));
|
|
47
|
+
return isNaN(date.getTime()) ? null : date;
|
|
48
|
+
}
|
|
49
|
+
/*
|
|
50
|
+
* Validate the Loki response envelope ({ status: "success", data:
|
|
51
|
+
* { resultType, result } }) and return the data section. Throws
|
|
52
|
+
* operator-actionable BadDataExceptions for every malformed shape.
|
|
53
|
+
*/
|
|
54
|
+
export function parseLokiResponseData(bodyJson) {
|
|
55
|
+
if (bodyJson === null ||
|
|
56
|
+
bodyJson === undefined ||
|
|
57
|
+
typeof bodyJson !== "object" ||
|
|
58
|
+
Array.isArray(bodyJson)) {
|
|
59
|
+
throw new BadDataException("Loki did not return a JSON object. Check that the data source URL points at a Grafana Loki endpoint.");
|
|
60
|
+
}
|
|
61
|
+
const body = bodyJson;
|
|
62
|
+
if (body["status"] !== "success") {
|
|
63
|
+
const errorDetail = typeof body["error"] === "string" ? `: ${body["error"]}` : ".";
|
|
64
|
+
throw new BadDataException(`Loki query failed with status "${String(body["status"])}"${errorDetail}`);
|
|
65
|
+
}
|
|
66
|
+
const dataRaw = body["data"];
|
|
67
|
+
if (dataRaw === null ||
|
|
68
|
+
dataRaw === undefined ||
|
|
69
|
+
typeof dataRaw !== "object" ||
|
|
70
|
+
Array.isArray(dataRaw)) {
|
|
71
|
+
throw new BadDataException("Loki response is missing the data object. Check that the data source URL points at a Grafana Loki endpoint.");
|
|
72
|
+
}
|
|
73
|
+
const data = dataRaw;
|
|
74
|
+
const resultType = data["resultType"];
|
|
75
|
+
const result = data["result"];
|
|
76
|
+
if (typeof resultType !== "string" || !Array.isArray(result)) {
|
|
77
|
+
throw new BadDataException("Loki response is missing data.resultType or data.result.");
|
|
78
|
+
}
|
|
79
|
+
return { resultType: resultType, result: result };
|
|
80
|
+
}
|
|
81
|
+
/*
|
|
82
|
+
* Extract string labels from a metric/stream label object, skipping the
|
|
83
|
+
* given keys. Non-object inputs yield an empty label set.
|
|
84
|
+
*/
|
|
85
|
+
function extractLabels(raw, excludeKeys) {
|
|
86
|
+
const labels = {};
|
|
87
|
+
if (raw === null ||
|
|
88
|
+
raw === undefined ||
|
|
89
|
+
typeof raw !== "object" ||
|
|
90
|
+
Array.isArray(raw)) {
|
|
91
|
+
return labels;
|
|
92
|
+
}
|
|
93
|
+
const rawRecord = raw;
|
|
94
|
+
for (const key of Object.keys(rawRecord)) {
|
|
95
|
+
if (excludeKeys.includes(key)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const value = rawRecord[key];
|
|
99
|
+
if (value === null || value === undefined) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
labels[key] = String(value);
|
|
103
|
+
}
|
|
104
|
+
return labels;
|
|
105
|
+
}
|
|
106
|
+
/*
|
|
107
|
+
* One matrix sample: [unixSeconds (may be fractional), "value"]. Returns
|
|
108
|
+
* null for malformed or unplottable (NaN/Inf) samples so single bad points
|
|
109
|
+
* do not fail the whole chart.
|
|
110
|
+
*/
|
|
111
|
+
export function parseLokiMatrixPoint(raw) {
|
|
112
|
+
if (!Array.isArray(raw) || raw.length < 2) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const timestampRaw = raw[0];
|
|
116
|
+
const valueRaw = raw[1];
|
|
117
|
+
let seconds = null;
|
|
118
|
+
if (typeof timestampRaw === "number" && Number.isFinite(timestampRaw)) {
|
|
119
|
+
seconds = timestampRaw;
|
|
120
|
+
}
|
|
121
|
+
else if (typeof timestampRaw === "string" &&
|
|
122
|
+
timestampRaw.trim() !== "" &&
|
|
123
|
+
Number.isFinite(Number(timestampRaw))) {
|
|
124
|
+
seconds = Number(timestampRaw);
|
|
125
|
+
}
|
|
126
|
+
if (seconds === null || seconds <= 0) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
let value = null;
|
|
130
|
+
if (typeof valueRaw === "number") {
|
|
131
|
+
value = valueRaw;
|
|
132
|
+
}
|
|
133
|
+
else if (typeof valueRaw === "string" && valueRaw.trim() !== "") {
|
|
134
|
+
value = Number(valueRaw);
|
|
135
|
+
}
|
|
136
|
+
if (value === null || !Number.isFinite(value)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return { timestamp: new Date(Math.round(seconds * 1000)), value: value };
|
|
140
|
+
}
|
|
141
|
+
/*
|
|
142
|
+
* "matrix" result -> AggregatedResult. Labels (minus __name__) become the
|
|
143
|
+
* per-point `attributes` object the chart layer groups series on; series
|
|
144
|
+
* without labels omit `attributes` entirely (single unnamed series).
|
|
145
|
+
* Applies the series cap and the total-point cap, flagging `truncated`.
|
|
146
|
+
*/
|
|
147
|
+
export function lokiMatrixToTimeSeries(result) {
|
|
148
|
+
const data = [];
|
|
149
|
+
let truncated = false;
|
|
150
|
+
let seriesUsed = 0;
|
|
151
|
+
let rowCapHit = false;
|
|
152
|
+
for (const rawSeries of result) {
|
|
153
|
+
if (rawSeries === null ||
|
|
154
|
+
typeof rawSeries !== "object" ||
|
|
155
|
+
Array.isArray(rawSeries)) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (seriesUsed >= DATA_SOURCE_MAX_SERIES) {
|
|
159
|
+
truncated = true;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
seriesUsed += 1;
|
|
163
|
+
const series = rawSeries;
|
|
164
|
+
const labels = extractLabels(series["metric"], [
|
|
165
|
+
"__name__",
|
|
166
|
+
]);
|
|
167
|
+
const values = series["values"];
|
|
168
|
+
if (!Array.isArray(values)) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
for (const rawPoint of values) {
|
|
172
|
+
const parsed = parseLokiMatrixPoint(rawPoint);
|
|
173
|
+
if (!parsed) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (data.length >= DATA_SOURCE_MAX_TIME_SERIES_ROWS) {
|
|
177
|
+
truncated = true;
|
|
178
|
+
rowCapHit = true;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
const point = {
|
|
182
|
+
timestamp: parsed.timestamp,
|
|
183
|
+
value: parsed.value,
|
|
184
|
+
};
|
|
185
|
+
if (Object.keys(labels).length > 0) {
|
|
186
|
+
point["attributes"] = Object.assign({}, labels);
|
|
187
|
+
}
|
|
188
|
+
data.push(point);
|
|
189
|
+
}
|
|
190
|
+
if (rowCapHit) {
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return { data: data, truncated: truncated };
|
|
195
|
+
}
|
|
196
|
+
/*
|
|
197
|
+
* "streams" result -> flat table rows { timestamp: Date, line, ...stream
|
|
198
|
+
* labels }, sorted newest-first (interleaved across streams, the way a log
|
|
199
|
+
* table reads). The `timestamp` and `line` cells always hold the entry's
|
|
200
|
+
* real values — stream labels that happen to use those names are dropped
|
|
201
|
+
* rather than allowed to clobber them. Rows are NOT capped here; the caller
|
|
202
|
+
* clamps via SqlResultShaper so cap+1 fetches surface `truncated`.
|
|
203
|
+
*/
|
|
204
|
+
export function lokiStreamsToTableRows(result) {
|
|
205
|
+
const entries = [];
|
|
206
|
+
for (const rawStream of result) {
|
|
207
|
+
if (rawStream === null ||
|
|
208
|
+
typeof rawStream !== "object" ||
|
|
209
|
+
Array.isArray(rawStream)) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const stream = rawStream;
|
|
213
|
+
const labels = extractLabels(stream["stream"], []);
|
|
214
|
+
const values = stream["values"];
|
|
215
|
+
if (!Array.isArray(values)) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
for (const rawEntry of values) {
|
|
219
|
+
if (!Array.isArray(rawEntry) || rawEntry.length < 2) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const nanoseconds = parseLokiNanoseconds(rawEntry[0]);
|
|
223
|
+
if (nanoseconds === null) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const timestamp = new Date(Number(nanoseconds / NANOSECONDS_PER_MILLISECOND));
|
|
227
|
+
if (isNaN(timestamp.getTime())) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const lineRaw = rawEntry[1];
|
|
231
|
+
const row = {
|
|
232
|
+
timestamp: timestamp,
|
|
233
|
+
line: typeof lineRaw === "string" ? lineRaw : String(lineRaw !== null && lineRaw !== void 0 ? lineRaw : ""),
|
|
234
|
+
};
|
|
235
|
+
for (const key of Object.keys(labels)) {
|
|
236
|
+
if (key !== "timestamp" && key !== "line") {
|
|
237
|
+
row[key] = labels[key];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
entries.push({ order: nanoseconds, row: row });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
entries.sort((a, b) => {
|
|
244
|
+
if (a.order === b.order) {
|
|
245
|
+
return 0;
|
|
246
|
+
}
|
|
247
|
+
return a.order < b.order ? 1 : -1;
|
|
248
|
+
});
|
|
249
|
+
return entries.map((entry) => {
|
|
250
|
+
return entry.row;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/*
|
|
254
|
+
* "matrix" result -> flat table rows { timestamp: Date, value, ...labels }.
|
|
255
|
+
* As with streams, the reserved `timestamp`/`value` cells win over labels
|
|
256
|
+
* with the same name, and capping is left to the caller's SqlResultShaper
|
|
257
|
+
* pass.
|
|
258
|
+
*/
|
|
259
|
+
export function lokiMatrixToTableRows(result) {
|
|
260
|
+
const rows = [];
|
|
261
|
+
for (const rawSeries of result) {
|
|
262
|
+
if (rawSeries === null ||
|
|
263
|
+
typeof rawSeries !== "object" ||
|
|
264
|
+
Array.isArray(rawSeries)) {
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const series = rawSeries;
|
|
268
|
+
const labels = extractLabels(series["metric"], [
|
|
269
|
+
"__name__",
|
|
270
|
+
]);
|
|
271
|
+
const values = series["values"];
|
|
272
|
+
if (!Array.isArray(values)) {
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
for (const rawPoint of values) {
|
|
276
|
+
const parsed = parseLokiMatrixPoint(rawPoint);
|
|
277
|
+
if (!parsed) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const row = {
|
|
281
|
+
timestamp: parsed.timestamp,
|
|
282
|
+
value: parsed.value,
|
|
283
|
+
};
|
|
284
|
+
for (const key of Object.keys(labels)) {
|
|
285
|
+
if (key !== "timestamp" && key !== "value") {
|
|
286
|
+
row[key] = labels[key];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
rows.push(row);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return rows;
|
|
293
|
+
}
|
|
294
|
+
export default class LokiConnector {
|
|
295
|
+
/*
|
|
296
|
+
* The optional fetchFunction is a DI seam for tests. The default wrapper
|
|
297
|
+
* resolves DataSourceHttpFetch.fetch at CALL time so jest.spyOn on the
|
|
298
|
+
* static method also intercepts connectors constructed earlier.
|
|
299
|
+
*/
|
|
300
|
+
constructor(fetchFunction) {
|
|
301
|
+
this.dataSourceType = DataSourceType.Loki;
|
|
302
|
+
this.fetchFunction =
|
|
303
|
+
fetchFunction ||
|
|
304
|
+
((request) => {
|
|
305
|
+
return DataSourceHttpFetch.fetch(request);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
getBaseUrl(settings) {
|
|
309
|
+
if (!settings.url || settings.url.trim() === "") {
|
|
310
|
+
throw new BadDataException("Loki data source requires a URL (e.g. http://loki.example.com:3100).");
|
|
311
|
+
}
|
|
312
|
+
return settings.url.trim().replace(/\/+$/, "");
|
|
313
|
+
}
|
|
314
|
+
/*
|
|
315
|
+
* All egress goes through DataSourceHttpFetch, which runs the SSRF egress
|
|
316
|
+
* guard and pins validated addresses before dialing. Errors are
|
|
317
|
+
* sanitized so credentials can never surface in an API response.
|
|
318
|
+
*/
|
|
319
|
+
async fetchSanitized(settings, request) {
|
|
320
|
+
try {
|
|
321
|
+
return await this.fetchFunction(request);
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
throw new BadDataException(SqlResultShaper.sanitizeError(error, SqlResultShaper.collectSecrets(settings)));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async testConnection(settings) {
|
|
328
|
+
const baseUrl = this.getBaseUrl(settings);
|
|
329
|
+
const endDate = new Date();
|
|
330
|
+
const startDate = new Date(endDate.getTime() - 60 * 60 * 1000);
|
|
331
|
+
const params = new URLSearchParams();
|
|
332
|
+
params.set("start", toLokiNanoseconds(startDate));
|
|
333
|
+
params.set("end", toLokiNanoseconds(endDate));
|
|
334
|
+
const headers = DataSourceHttpFetch.buildAuthHeaders(settings);
|
|
335
|
+
const response = await this.fetchSanitized(settings, {
|
|
336
|
+
method: "GET",
|
|
337
|
+
url: `${baseUrl}/loki/api/v1/labels?${params.toString()}`,
|
|
338
|
+
headers: headers,
|
|
339
|
+
timeoutInMs: DATA_SOURCE_CONNECT_TIMEOUT_IN_MS,
|
|
340
|
+
});
|
|
341
|
+
const body = response.bodyJson;
|
|
342
|
+
if (body === null ||
|
|
343
|
+
body === undefined ||
|
|
344
|
+
typeof body !== "object" ||
|
|
345
|
+
Array.isArray(body) ||
|
|
346
|
+
body["status"] !== "success") {
|
|
347
|
+
throw new BadDataException('Connected to the host, but it did not respond like a Grafana Loki API (expected { "status": "success" } from /loki/api/v1/labels). Check the URL — it should be the Loki base URL, e.g. http://loki.example.com:3100.');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
async runRangeQuery(settings, query, window, limit) {
|
|
351
|
+
var _a;
|
|
352
|
+
if (!query || query.trim() === "") {
|
|
353
|
+
throw new BadDataException("Query is required.");
|
|
354
|
+
}
|
|
355
|
+
const baseUrl = this.getBaseUrl(settings);
|
|
356
|
+
const stepInSeconds = (_a = window.stepInSeconds) !== null && _a !== void 0 ? _a : DataSourceLimitsUtil.getStepInSeconds(window.startDate, window.endDate);
|
|
357
|
+
const params = new URLSearchParams();
|
|
358
|
+
params.set("query", query);
|
|
359
|
+
params.set("start", toLokiNanoseconds(window.startDate));
|
|
360
|
+
params.set("end", toLokiNanoseconds(window.endDate));
|
|
361
|
+
params.set("step", `${stepInSeconds}s`);
|
|
362
|
+
params.set("limit", limit.toString());
|
|
363
|
+
const headers = DataSourceHttpFetch.buildAuthHeaders(settings);
|
|
364
|
+
const response = await this.fetchSanitized(settings, {
|
|
365
|
+
method: "GET",
|
|
366
|
+
url: `${baseUrl}/loki/api/v1/query_range?${params.toString()}`,
|
|
367
|
+
headers: headers,
|
|
368
|
+
timeoutInMs: DATA_SOURCE_QUERY_TIMEOUT_IN_MS,
|
|
369
|
+
});
|
|
370
|
+
return parseLokiResponseData(response.bodyJson);
|
|
371
|
+
}
|
|
372
|
+
async queryTimeSeries(settings, query, window) {
|
|
373
|
+
const data = await this.runRangeQuery(settings, query, window, DATA_SOURCE_MAX_TIME_SERIES_ROWS + 1);
|
|
374
|
+
if (data.resultType === "streams") {
|
|
375
|
+
throw new BadDataException('This LogQL query returns raw log streams, which cannot be charted. Wrap it in a LogQL metric function such as rate() or count_over_time() — e.g. sum(rate({app="api"} [5m])) — or use the Table widget to view the log lines.');
|
|
376
|
+
}
|
|
377
|
+
if (data.resultType !== "matrix") {
|
|
378
|
+
throw new BadDataException(`Loki returned an unexpected result type "${data.resultType}" for a range query. Charts require a LogQL metric query that produces a matrix result.`);
|
|
379
|
+
}
|
|
380
|
+
return lokiMatrixToTimeSeries(data.result);
|
|
381
|
+
}
|
|
382
|
+
async queryTable(settings, query, window) {
|
|
383
|
+
const data = await this.runRangeQuery(settings, query, window, DATA_SOURCE_MAX_TABLE_ROWS + 1);
|
|
384
|
+
let rows;
|
|
385
|
+
if (data.resultType === "streams") {
|
|
386
|
+
rows = lokiStreamsToTableRows(data.result);
|
|
387
|
+
}
|
|
388
|
+
else if (data.resultType === "matrix") {
|
|
389
|
+
rows = lokiMatrixToTableRows(data.result);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
throw new BadDataException(`Loki returned an unexpected result type "${data.resultType}" for a range query. Expected "streams" (raw logs) or "matrix" (metric query).`);
|
|
393
|
+
}
|
|
394
|
+
return SqlResultShaper.rowsToTable(rows, {
|
|
395
|
+
maxRows: DATA_SOURCE_MAX_TABLE_ROWS,
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
//# sourceMappingURL=LokiConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LokiConnector.js","sourceRoot":"","sources":["../../../../../../Server/Utils/DataSource/Connectors/LokiConnector.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iCAAiC,EACjC,sBAAsB,EACtB,0BAA0B,EAC1B,gCAAgC,EAChC,+BAA+B,EAC/B,oBAAoB,GACrB,MAAM,+CAA+C,CAAC;AAEvD,OAAO,cAAc,MAAM,6CAA6C,CAAC;AACzE,OAAO,gBAAgB,MAAM,8CAA8C,CAAC;AAE5E,OAAO,mBAGN,MAAM,cAAc,CAAC;AACtB,OAAO,eAAe,MAAM,oBAAoB,CAAC;AAqCjD,MAAM,2BAA2B,GAAW,MAAM,CAAC,OAAO,CAAC,CAAC;AAE5D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YACxC,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,gBAAgB,CACxB,4CAA4C,IAAI,CAAC,UAAU,gFAAgF,CAC5I,CAAC;QACJ,CAAC;QAED,OAAO,eAAe,CAAC,WAAW,CAAC,IAAI,EAAE;YACvC,OAAO,EAAE,0BAA0B;SACpC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { createConnection, } from "mysql2/promise";
|
|
2
|
+
import { DATA_SOURCE_CONNECT_TIMEOUT_IN_MS, DATA_SOURCE_MAX_TABLE_ROWS, DATA_SOURCE_MAX_TIME_SERIES_ROWS, DATA_SOURCE_QUERY_TIMEOUT_IN_MS, } from "../../../../Types/DataSource/DataSourceLimits";
|
|
3
|
+
import DataSourceType from "../../../../Types/DataSource/DataSourceType";
|
|
4
|
+
import BadDataException from "../../../../Types/Exception/BadDataException";
|
|
5
|
+
import DataSourceEgressGuard from "../EgressGuard";
|
|
6
|
+
import SqlQueryGuard from "../SqlQueryGuard";
|
|
7
|
+
import SqlResultShaper from "../SqlResultShaper";
|
|
8
|
+
const defaultConnectionFactory = async (options) => {
|
|
9
|
+
const connection = await createConnection(options);
|
|
10
|
+
return {
|
|
11
|
+
query: async (sql) => {
|
|
12
|
+
const result = (await connection.query(sql));
|
|
13
|
+
return result;
|
|
14
|
+
},
|
|
15
|
+
end: () => {
|
|
16
|
+
return connection.end();
|
|
17
|
+
},
|
|
18
|
+
destroy: () => {
|
|
19
|
+
connection.destroy();
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export default class MySqlConnector {
|
|
24
|
+
constructor(connectionFactory) {
|
|
25
|
+
this.dataSourceType = DataSourceType.MySQL;
|
|
26
|
+
this.connectionFactory = connectionFactory || defaultConnectionFactory;
|
|
27
|
+
}
|
|
28
|
+
async testConnection(settings) {
|
|
29
|
+
const connection = await this.connect(settings);
|
|
30
|
+
try {
|
|
31
|
+
await connection.query("SELECT 1");
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new BadDataException(SqlResultShaper.sanitizeError(error, this.getSecrets(settings)));
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
await this.closeConnection(connection);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async queryTimeSeries(settings, query, window) {
|
|
41
|
+
const rows = await this.runReadOnlyQuery(settings, query, window, DATA_SOURCE_MAX_TIME_SERIES_ROWS);
|
|
42
|
+
return SqlResultShaper.rowsToTimeSeries(rows, {
|
|
43
|
+
maxRows: DATA_SOURCE_MAX_TIME_SERIES_ROWS,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async queryTable(settings, query, window) {
|
|
47
|
+
const rows = await this.runReadOnlyQuery(settings, query, window, DATA_SOURCE_MAX_TABLE_ROWS);
|
|
48
|
+
return SqlResultShaper.rowsToTable(rows, {
|
|
49
|
+
maxRows: DATA_SOURCE_MAX_TABLE_ROWS,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
getSecrets(settings) {
|
|
53
|
+
return [
|
|
54
|
+
settings.password,
|
|
55
|
+
settings.apiToken,
|
|
56
|
+
settings.databaseHost,
|
|
57
|
+
settings.username,
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
buildConnectionOptions(settings) {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
const options = {
|
|
63
|
+
host: settings.databaseHost,
|
|
64
|
+
port: (_a = settings.databasePort) !== null && _a !== void 0 ? _a : 3306,
|
|
65
|
+
connectTimeout: DATA_SOURCE_CONNECT_TIMEOUT_IN_MS,
|
|
66
|
+
/*
|
|
67
|
+
* NEVER true: stacked statements ("SELECT 1; DROP TABLE x") must be
|
|
68
|
+
* impossible at the driver level, as defense in depth beneath the
|
|
69
|
+
* SqlQueryGuard classifier and the read-only transaction.
|
|
70
|
+
*/
|
|
71
|
+
multipleStatements: false,
|
|
72
|
+
};
|
|
73
|
+
if (settings.databaseName !== undefined) {
|
|
74
|
+
options.database = settings.databaseName;
|
|
75
|
+
}
|
|
76
|
+
if (settings.username !== undefined) {
|
|
77
|
+
options.user = settings.username;
|
|
78
|
+
}
|
|
79
|
+
if (settings.password !== undefined) {
|
|
80
|
+
options.password = settings.password;
|
|
81
|
+
}
|
|
82
|
+
if (((_b = settings.additionalOptions) === null || _b === void 0 ? void 0 : _b["sslEnabled"]) === true) {
|
|
83
|
+
/*
|
|
84
|
+
* Certificate verification stays ON by default; only an explicit
|
|
85
|
+
* sslRejectUnauthorized === false disables it.
|
|
86
|
+
*/
|
|
87
|
+
options.ssl = {
|
|
88
|
+
rejectUnauthorized: ((_c = settings.additionalOptions) === null || _c === void 0 ? void 0 : _c["sslRejectUnauthorized"]) !== false,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return options;
|
|
92
|
+
}
|
|
93
|
+
/*
|
|
94
|
+
* Egress-validate the host, then open a driver connection. Called only
|
|
95
|
+
* after the query (when there is one) has already passed the read-only
|
|
96
|
+
* guard, so a rejected query never even dials the server.
|
|
97
|
+
*/
|
|
98
|
+
async connect(settings) {
|
|
99
|
+
if (!settings.databaseHost) {
|
|
100
|
+
throw new BadDataException("MySQL data source is missing a database host. Set the host in the data source settings.");
|
|
101
|
+
}
|
|
102
|
+
/*
|
|
103
|
+
* SSRF guard — must pass BEFORE any socket is opened towards the
|
|
104
|
+
* configured host.
|
|
105
|
+
*/
|
|
106
|
+
await DataSourceEgressGuard.assertHostnameAllowed(settings.databaseHost);
|
|
107
|
+
const options = this.buildConnectionOptions(settings);
|
|
108
|
+
try {
|
|
109
|
+
return await this.connectionFactory(options);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
throw new BadDataException(SqlResultShaper.sanitizeError(error, this.getSecrets(settings)));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/*
|
|
116
|
+
* Teardown: roll the read-only transaction back (harmless when none is
|
|
117
|
+
* open), then close. Every step is guarded — a wedged server must not
|
|
118
|
+
* turn cleanup into an unhandled rejection — with destroy() as the
|
|
119
|
+
* hard fallback when a graceful end() fails.
|
|
120
|
+
*/
|
|
121
|
+
async closeConnection(connection) {
|
|
122
|
+
try {
|
|
123
|
+
await connection.query("ROLLBACK");
|
|
124
|
+
}
|
|
125
|
+
catch (_a) {
|
|
126
|
+
/* Best effort — the transaction may already be gone. */
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
await connection.end();
|
|
130
|
+
}
|
|
131
|
+
catch (_b) {
|
|
132
|
+
try {
|
|
133
|
+
connection.destroy();
|
|
134
|
+
}
|
|
135
|
+
catch (_c) {
|
|
136
|
+
/* Best effort — the socket may already be gone. */
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async runReadOnlyQuery(settings, query, window, maxRows) {
|
|
141
|
+
const withMacros = SqlQueryGuard.applyTimeMacros(query, window.startDate, window.endDate);
|
|
142
|
+
/*
|
|
143
|
+
* The read-only classifier runs on the USER's query only. The session
|
|
144
|
+
* SET statements issued below are our own fixed strings and never pass
|
|
145
|
+
* through this guard — the guard's ban on the SET keyword applies to
|
|
146
|
+
* user queries, not to the connector's session setup.
|
|
147
|
+
*/
|
|
148
|
+
SqlQueryGuard.assertReadOnlyQuery(withMacros);
|
|
149
|
+
/* Drop a trailing semicolon; the statement runs bare. */
|
|
150
|
+
const finalSql = withMacros.replace(/;\s*$/, "");
|
|
151
|
+
const connection = await this.connect(settings);
|
|
152
|
+
try {
|
|
153
|
+
/*
|
|
154
|
+
* Best-effort server-side statement timeout. MAX_EXECUTION_TIME
|
|
155
|
+
* (milliseconds, SELECT-only) exists on MySQL 5.7.8+; MariaDB uses
|
|
156
|
+
* max_statement_time in seconds instead, so this statement can fail
|
|
157
|
+
* there — swallow the error and rely on the engine defaults rather
|
|
158
|
+
* than failing the query.
|
|
159
|
+
*/
|
|
160
|
+
try {
|
|
161
|
+
await connection.query(`SET SESSION MAX_EXECUTION_TIME = ${DATA_SOURCE_QUERY_TIMEOUT_IN_MS}`);
|
|
162
|
+
}
|
|
163
|
+
catch (_a) {
|
|
164
|
+
/* Non-fatal — variable unknown on MariaDB and older MySQL. */
|
|
165
|
+
}
|
|
166
|
+
/*
|
|
167
|
+
* Server-side row bound at cap+1 so the shaper can detect truncation.
|
|
168
|
+
* An explicit LIMIT in the user's query takes precedence over
|
|
169
|
+
* SQL_SELECT_LIMIT; the shaper's maxRows clamp is the authoritative
|
|
170
|
+
* cap either way.
|
|
171
|
+
*/
|
|
172
|
+
await connection.query(`SET SESSION SQL_SELECT_LIMIT = ${maxRows + 1}`);
|
|
173
|
+
/*
|
|
174
|
+
* Server-enforced read-only guarantee, independent of the query text
|
|
175
|
+
* classifier.
|
|
176
|
+
*/
|
|
177
|
+
await connection.query("START TRANSACTION READ ONLY");
|
|
178
|
+
const result = await connection.query(finalSql);
|
|
179
|
+
const rows = result[0];
|
|
180
|
+
return Array.isArray(rows)
|
|
181
|
+
? rows
|
|
182
|
+
: [];
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error instanceof BadDataException) {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
throw new BadDataException(SqlResultShaper.sanitizeError(error, this.getSecrets(settings)));
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
await this.closeConnection(connection);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=MySqlConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MySqlConnector.js","sourceRoot":"","sources":["../../../../../../Server/Utils/DataSource/Connectors/MySqlConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,iCAAiC,EACjC,0BAA0B,EAC1B,gCAAgC,EAChC,+BAA+B,G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