grafonnet icon indicating copy to clipboard operation
grafonnet copied to clipboard

Support Microsoft SQL Server Source

Open titt opened this issue 1 year ago • 1 comments

Currently, there are no query target helpers/functions for Microsoft SQL Server. It would be great to support Microsoft SQL Server as this data source is quite popular.

titt avatar May 30 '24 16:05 titt

I have created a short workaround by adding some file in the code deployed by the jb install:

  • vendor\custom\query\sql.libsonnet
local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';

{
  '#new':: d.func.new(
    'Creates a new Microsoft SQL Server query target for panels.',
    args=[
      d.arg('datasource', d.T.string),
	  d.arg('rawSql', d.T.string),
	  d.arg('format', d.T.string),
	  d.arg('rawEditor', d.T.bolean),
	  d.arg('rawQuery', d.T.bolean),
      d.arg('queryText', d.T.string),  
    ]
  ),
  new(datasource, rawSql, format='time_series', rawEditor=true, rawQuery=true, queryText=rawSql):
    self.withDatasource(datasource)
    + {
		format: format,
		rawSql: rawSql,
		rawEditor: rawEditor,
		rawQuery: rawQuery,
		queryText: queryText,
	  },

  '#withDatasource':: d.func.new(
    'Set the datasource for this query.',
    args=[
      d.arg('value', d.T.string),
    ]
  ),
  withDatasource(value): {
    datasource+: {
      type: 'Microsoft SQL Server',
      uid: value,
    },
  },
  '#withDatasourceMixin':: { ignore: true },
}
  • vendor/query.libsonnet
 // This file is generated, do not manually edit.
{
  '#': { help: 'grafonnet.query', name: 'query' },
  azureMonitor: import 'query/azureMonitor.libsonnet',
  cloudWatch: import 'query/cloudWatch.libsonnet',
  elasticsearch: import 'query/elasticsearch.libsonnet',
  expr: import 'query/expr.libsonnet',
  googleCloudMonitoring: import 'query/googleCloudMonitoring.libsonnet',
  grafanaPyroscope: import 'query/grafanaPyroscope.libsonnet',
  loki: import 'query/loki.libsonnet',
  parca: import 'query/parca.libsonnet',
  prometheus: import 'query/prometheus.libsonnet',
  tempo: import 'query/tempo.libsonnet',
  testData: import 'query/testData.libsonnet',
  sql: import 'query/sql.libsonnet'
}
  • \vendor\query\sql.libsonnet
// This file is generated, do not manually edit.
{
  '#': { help: 'grafonnet.query.sql', name: 'sql' },
  '#withDatasource': { 'function': { args: [{ default: null, enums: null, name: 'value', type: ['object'] }], help: "For mixed data sources the selected datasource is on the query level.\nFor non mixed scenarios this is undefined.\nTODO find a better way to do this ^ that's friendly to schema\nTODO this shouldn't be unknown but DataSourceRef | null" } },
  withDatasource(value): {
    datasource: value,
  },
  '#withDatasourceMixin': { 'function': { args: [{ default: null, enums: null, name: 'value', type: ['object'] }], help: "For mixed data sources the selected datasource is on the query level.\nFor non mixed scenarios this is undefined.\nTODO find a better way to do this ^ that's friendly to schema\nTODO this shouldn't be unknown but DataSourceRef | null" } },
  withDatasourceMixin(value): {
    datasource+: value,
  },
}
+ (import '../custom/query/sql.libsonnet')

titt avatar Jun 03 '24 15:06 titt