mirror of
https://github.com/grafana/grafana.git
synced 2025-12-24 05:44:14 +08:00
* API: adds redirect helper to simplify http redirects (#19180) (cherry picked from commitdd794625dd) * Dashboard: Fixes back button styles in kiosk mode (#19165) Fixes: #18114 (cherry picked from commit38e948a1ad) * Menu: fix menu button in the mobile view (#19191) * replace "sandwich" (menu) button with logo(back home) if kiosk=tv * update navbar initialize padding-left befause menu button is overlapped by the navbar (cherry picked from commit5ef40b259d) * LDAP debug page: deduplicate errors (#19168) (cherry picked from commit6b2e95a1f2) * MSSQL: Revert usage of new connectionstring format (#19203) This reverts commit2514209from #18384. Reason is that it doesn't work due to xorm 0.7.1 which doesn't support this new connectionstring format. Fixes #19189 Ref #18384 Ref #17665 (cherry picked from commit0f524fc947) * Docker: Upgrade packages to resolve reported vulnerabilities (#19188) Fixes #19186 (cherry picked from commit4d96bc590f) * FieldDisplay: Update title variable syntax (#19217) (cherry picked from commit14f1cf29f0) * Cloudwatch: Fix autocomplete for Gamelift dimensions (#19145) (#19146) (cherry picked from commit79f8433675) * grafana/ui: Add disabled prop on LinkButton (#19192) (cherry picked from commitf445369d68) * plugins: expose whole rxjs to plugins (#19226) (cherry picked from commit98c95a8a83) * Snapshots: store DataFrameDTO instead of MutableDataFrame in snapshot data (#19247) (cherry picked from commitbe8097fca2) * grafana/toolkit: Add plugin scaffolding (#19207) (cherry picked from commit54ebf174a0) * Alerting: Truncate PagerDuty summary when greater than 1024 characters (#18730) Requests to PagerDuty fail with an HTTP 400 if the `summary` attribute contains more than 1024 characters, this fixes this. API spec: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2 Fixes #18727 (cherry picked from commit8a991244d5) * grafana/toolkit: Fix toolkit not building @grafana/toolkit (#19253) * Fix toolkit not building Weird TS didn't pick this up... * Update packages/grafana-toolkit/src/cli/index.ts (cherry picked from commit809e2ca3c7) * Docs: Update theming docs (#19248) (cherry picked from commit9feac7753b) * Explore: live tail UI fixes and improvements (#19187) (cherry picked from commitbf24cbba76) * Graphite: Changed range expansion from 1m to 1s (#19246) Fixes #11472 (cherry picked from commitd95318b325) * MySQL, Postgres, MSSQL: Only debug log when in development (#19239) Found some additional debug statements in relation to #19049 that can cause memory issues. Ref #19049 (cherry picked from commit19f3ec4891) * Vector: remove toJSON() from interface (#19254) (cherry picked from commit6787e7b5ab) * Update changelog task to generate toolkit changelog too (#19262) (cherry picked from commitb7752b8c02) * Dashboard: Hides alpha icon for visualization that is not in alpha/beta stage #19300 Fixes #19251 (cherry picked from commitf01836c17a) * Build: Split up task in the CI pipeline to ease running outside circleci (#18861) * build: make sign rpm packages not depend on checking out private key * build: move commands from circleci config into verify signed packages script * build: split update and publish of deb and rpm into two scripts * use files argument for sign and verify packages * validate files argument for sign and verify packages * update test publish of deb/rpm readme (cherry picked from commit4386604751) * Admin/user: fix textarea postion in 'Pending Invites' to avoid page scrolling (#19288) * hide textarea element after click 'Copy Invite' button on firefox (cherry picked from commit50b4695cf5) * Alerting: Prevents creating alerts from unsupported queries (#19250) * Refactor: Makes PanelEditor use state and shows validation message on AlerTab * Refactor: Makes validation message nicer looking * Refactor: Changes imports * Refactor: Removes conditional props * Refactor: Changes after feedback from PR review * Refactor: Removes unused action (cherry picked from commit9bd6ed887c) * Chore: Update Slate to 0.47.8 (#19197) * Chore: Update Slate to 0.47.8 Closes #17430 (cherry picked from commit68d6da77da) * DataLinks: Small UX improvements to DataLinksInput (#19313) Closes #19257 (cherry picked from commitfeb6bc6747) * Multi-LDAP: Do not fail-fast on invalid credentials (#19261) * Multi-LDAP: Do not fail-fast on invalid credentials When configuring LDAP authentication, it is very common to have multiple servers configured. When using user bind (authenticating with LDAP using the same credentials as the user authenticating to Grafana) we don't expect all the users to be on all LDAP servers. Because of this use-case, we should not fail-fast when authenticating on multiple LDAP server configurations. Instead, we should continue to try the credentials with the next LDAP server configured. Fixes #19066 (cherry picked from commit279249ef56) * Explore: Fix unsubscribing from Loki websocket (#19263) (cherry picked from commit4c1bc59889) * Plugins: Skips existence of module.js for renderer plugins (#19318) * Fix: Skips test for module.js for plugins of renderer type Fixes #19130 * Refactor: Changes after PR comments * Chore: Fixes go lint issue (cherry picked from commit75dcaecc99) * Keybindings: Improve esc / exit / blur logic (#19320) * Keybindings: Improve esc / exit / blur logic * Slight modifications * removed use of jquery (cherry picked from commit08cc4f0c8a) * Select: Set placeholder color (#19309) (cherry picked from commit2c9577fcc5) * Azure Monitor: Revert support for cross resource queries (#19115)" (#19346) This reverts commit88051258e9. (cherry picked from commit4dbedb8405) * Dashboard: Fix export for sharing when panels use default data source (#19315) * PanelModel: moved datasource: null away from defaults that are removed * Added unit test (cherry picked from commitac3fb6452d) * Heatmap: use DataFrame rather than LegacyResponseData (#19026) * merge master * TimeSeries: datasources with labels should export tags (not labels) (#18977) * merge master * export prometheus tags * Annotations: Add annotations support to Loki (#18949) * Explore: Unify background color for fresh logs (#18973) * Singlestat: render lines on the panel when sparklines are enabled (#18984) * Image rendering: Add deprecation warning when PhantomJS is used for rendering images (#18933) * Add deprecation warning * Update pkg/services/rendering/rendering.go Co-Authored-By: Marcus Efraimsson <marcus.efraimsson@gmail.com> * Units: Adding T,P,E,Z,and Y bytes (#18706) * Adding T and P for bytes Luckily, all the hard work was done before; just added in these prefixes for our production environment. * Future-proofing with other values (why not?) * Yottaflops? * Cutting back down to Peta sizes, except for hashes * Refactor: move ScopedVars to grafana/data (#18992) * Refactor: Move sql_engine to sub package of tsdb (#18991) this way importing the tsdb package does not come with xorm dependencies * use DataFrame in heatmaps * actually use the setting :) * remove unused timeSrv * merge with master / useDataFrames * fix test function * merge master * fix datasource type on snapshot * reuse DataFrame calcs from graph panel * update comments (cherry picked from commit2474511d03) * Explore: Do not send explicit maxDataPoints for logs. (#19235) (cherry picked from commitf203e82b40) * MySQL, Postgres, MSSQL: Fix validating query with template variables in alert (#19237) Adds support for validating query in alert for mysql, postgres and mssql. Fixes #13155 (cherry picked from commit96046a7ba6) * MySQL, Postgres: Update raw sql when query builder updates (#19209) Raw sql now updates when changing query using graphical query editor for mysql and postgres. Fixes #19063 (cherry picked from commit7c499ffdd8) * MySQL: Limit datasource error details returned from the backend (#19373) Only return certain mysql errors from backend. The following errors is returned as is from backend: error code 1064 (parse error) error code 1054 (bad column/field selected) error code 1146 (table not exists) Any other errors is logged and returned as a generic error. Restrict use of certain functions: Do not allow usage of the following in query: system_user() session_user() current_user() or current_user user() show grants Fixes #19360 (cherry picked from commit3de693af49) * SQL: Rewrite statistics query (#19178) * Rewrite statistics query (cherry picked from commit56f5106717) * Release v6.4.0-beta2 * ValueFormats: check for inf (#19376) (cherry picked from commit32b73bb496) * Build: Fix correct sort order of merged pr's in cherrypick task (#19379) (cherry picked from commitc4a03f482c)
100 lines
2.7 KiB
Go
100 lines
2.7 KiB
Go
package postgres
|
|
|
|
import (
|
|
"database/sql"
|
|
"net/url"
|
|
"strconv"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
"github.com/go-xorm/core"
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/tsdb"
|
|
"github.com/grafana/grafana/pkg/tsdb/sqleng"
|
|
)
|
|
|
|
func init() {
|
|
tsdb.RegisterTsdbQueryEndpoint("postgres", newPostgresQueryEndpoint)
|
|
}
|
|
|
|
func newPostgresQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
|
logger := log.New("tsdb.postgres")
|
|
|
|
cnnstr := generateConnectionString(datasource)
|
|
if setting.Env == setting.DEV {
|
|
logger.Debug("getEngine", "connection", cnnstr)
|
|
}
|
|
|
|
config := sqleng.SqlQueryEndpointConfiguration{
|
|
DriverName: "postgres",
|
|
ConnectionString: cnnstr,
|
|
Datasource: datasource,
|
|
MetricColumnTypes: []string{"UNKNOWN", "TEXT", "VARCHAR", "CHAR"},
|
|
}
|
|
|
|
queryResultTransformer := postgresQueryResultTransformer{
|
|
log: logger,
|
|
}
|
|
|
|
timescaledb := datasource.JsonData.Get("timescaledb").MustBool(false)
|
|
|
|
return sqleng.NewSqlQueryEndpoint(&config, &queryResultTransformer, newPostgresMacroEngine(timescaledb), logger)
|
|
}
|
|
|
|
func generateConnectionString(datasource *models.DataSource) string {
|
|
sslmode := datasource.JsonData.Get("sslmode").MustString("verify-full")
|
|
u := &url.URL{
|
|
Scheme: "postgres",
|
|
User: url.UserPassword(datasource.User, datasource.DecryptedPassword()),
|
|
Host: datasource.Url, Path: datasource.Database,
|
|
RawQuery: "sslmode=" + url.QueryEscape(sslmode),
|
|
}
|
|
|
|
return u.String()
|
|
}
|
|
|
|
type postgresQueryResultTransformer struct {
|
|
log log.Logger
|
|
}
|
|
|
|
func (t *postgresQueryResultTransformer) TransformQueryResult(columnTypes []*sql.ColumnType, rows *core.Rows) (tsdb.RowValues, error) {
|
|
values := make([]interface{}, len(columnTypes))
|
|
valuePtrs := make([]interface{}, len(columnTypes))
|
|
|
|
for i := 0; i < len(columnTypes); i++ {
|
|
valuePtrs[i] = &values[i]
|
|
}
|
|
|
|
if err := rows.Scan(valuePtrs...); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// convert types not handled by lib/pq
|
|
// unhandled types are returned as []byte
|
|
for i := 0; i < len(columnTypes); i++ {
|
|
if value, ok := values[i].([]byte); ok {
|
|
switch columnTypes[i].DatabaseTypeName() {
|
|
case "NUMERIC":
|
|
if v, err := strconv.ParseFloat(string(value), 64); err == nil {
|
|
values[i] = v
|
|
} else {
|
|
t.log.Debug("Rows", "Error converting numeric to float", value)
|
|
}
|
|
case "UNKNOWN", "CIDR", "INET", "MACADDR":
|
|
// char literals have type UNKNOWN
|
|
values[i] = string(value)
|
|
default:
|
|
t.log.Debug("Rows", "Unknown database type", columnTypes[i].DatabaseTypeName(), "value", value)
|
|
values[i] = string(value)
|
|
}
|
|
}
|
|
}
|
|
|
|
return values, nil
|
|
}
|
|
|
|
func (t *postgresQueryResultTransformer) TransformQueryError(err error) error {
|
|
return err
|
|
}
|