Thank you for your interest in contributing to the Perses SQL Plugin!
- Prerequisites
- Node.js >= 22
- npm >= 10
- Docker (for test databases)
- Install Dependencies
cd perses/plugins/sql npm install - Start Development Server
# In perses main repository, enable dev mode # Update config.yaml: plugin: enable_dev: true # Start backend ./bin/perses --config ./dev/config.yaml --log.level=debug # In a new terminal, start SQL plugin cd plugins/sql percli plugin start .
The SQL plugin consists of several components:
- Datasource Plugin (
src/datasources/sql-datasource/): Configuration UI for SQL datasourcesSQLDatasource.tsx- Plugin implementationSQLDatasourceEditor.tsx- UI editor componentsql-datasource-types.ts- TypeScript types
- Query Plugin (
src/queries/sql-time-series-query/): SQL Time Series Query editorSQLTimeSeriesQuery.tsx- Query plugin implementationSQLTimeSeriesQueryEditor.tsx- Query editor UIsql-time-series-query-types.ts- TypeScript types
- Explore Plugin (
src/explore/): SQL Explorer for interactive queryingSQLExplorer.tsx- Prometheus-style explorer with Table & Graph tabs- Uses
MultiQueryEditorandDataQueriesProviderfrom Perses plugin system - Supports TimeSeriesChart and TimeSeriesTable visualization
- Model (
src/model/): Utility functionsreplace-sql-builtin-variables.ts- SQL macro replacement ($__timeFilter, etc.)sql-client.ts- HTTP client for query execution
- SQL Proxy (
internal/api/impl/proxy/proxy.goin Perses main repository)- Handles all SQL queries via backend proxy
- Connects to databases (PostgreSQL, MySQL, MariaDB)
- Executes queries and returns JSON
- Handles authentication and TLS
- CUE Schemas (
schemas/)datasource/sql.cue- SQL datasource configuration validationsql-time-series-query/sql-time-series-query.cue- Query configuration validation
- Test Databases (
test-data/)- PostgreSQL sample data (
test-data/postgres/) - MySQL sample data (
test-data/mysql/) - MariaDB sample data (
test-data/mariadb/)
- PostgreSQL sample data (
- Update Backend (
internal/api/impl/proxy/proxy.goin Perses core)- Add driver support in
sqlOpen()function - Add driver-specific connection string handling
- Add driver support in
- Update Frontend Types (
src/datasources/sql-datasource/sql-datasource-types.ts)export type SQLDriver = 'postgres' | 'mysql' | 'mariadb' | 'your-driver';
- Update UI (
src/datasources/sql-datasource/SQLDatasourceEditor.tsx)- Add driver option to the Select component
- Add driver-specific configuration fields if needed
- Update CUE Schema (
schemas/datasource/sql.cue)- Add driver to allowed values
- Add Test Data (
test-data/your-driver/)- Create
init.sqlandsample-data.sql - Update
docker-compose.test.yaml
- Create
- Create Query Directory
mkdir -p src/queries/your-query-type
- Implement Query Plugin
- Create
YourQuery.tsxfollowingSQLTimeSeriesQuery.tsxpattern - Implement
getTimeSeriesData()or appropriate data fetching method - Create
YourQueryEditor.tsxfor UI
- Create
- Add Types
- Create
your-query-types.tswith spec interfaces
- Create
- Register Plugin
- Export from
src/queries/index.ts - Add to
package.jsonperses.plugins array - Add to
rsbuild.config.tsModule Federation exposes
- Export from
- Add CUE Schema
- Create
schemas/your-query-type/your-query-type.cue
- Create
SQL macros are processed in src/model/replace-sql-builtin-variables.ts.
Existing Macros:
$__timeFilter(column)- Generates WHERE clause for time range$__timeFrom- Start of time range$__timeTo- End of time range$__interval- Interval in seconds$__interval_ms- Interval in milliseconds To Add New Macro:
- Add macro processing logic in
replace-sql-builtin-variables.tsexport function replaceSQLBuiltinVariables(...) { // ...existing code... // Add your macro replacement query = query.replace(/\$__yourMacro/g, 'replacement'); return query; }
- Add tests in
replace-sql-builtin-variables.test.tsit('should replace $__yourMacro', () => { const result = replaceSQLBuiltinVariables('SELECT * WHERE $__yourMacro', ...); expect(result).toBe('SELECT * WHERE replacement'); });
- Document in README.md
# All tests
npm test
# Watch mode
npm test -- --watch
# With coverage
npm test -- --coveragenpm run type-check# Start all databases (PostgreSQL, MySQL, MariaDB)
make db-up
# Verify test data
make verify-all
# Stop databases
make db-down
# Clean all (including volumes)
make db-clean# PostgreSQL
make verify-postgres
# MySQL
make verify-mysql
# MariaDB
make verify-mariadb# Build the plugin
npm run build
# Build for Module Federation
npm run build-mf
# Type checking
npm run type-checkEdit files in src/ directory
# Start backend (in perses main repo)
./bin/perses --config ./dev/config.yaml --log.level=debug
# Start plugin (in plugins/sql)
percli plugin start .
# Plugin will rebuild automatically on file changes- Open browser to Perses UI
- Create/edit SQL datasource
- Create dashboard with SQL query
- Test Explore mode
npm test
npm run type-check- TypeScript for all new code
- Follow existing patterns in the codebase
- JSDoc comments for public APIs
- Functional components with React Hooks
- Named exports over default exports
// Copyright header
// ...
import { ... } from '...';
interface YourComponentProps {
// Props definition
}
export function YourComponent({ prop1, prop2 }: YourComponentProps): ReactElement {
// Component implementation
}- Components:
PascalCase.tsx - Types:
kebab-case-types.ts - Utilities:
kebab-case.ts - Tests:
*.test.tsor*.test.tsx
- Fork the Perses repository
- Create feature branch from
maingit checkout -b feature/your-feature-name
- Make your changes
- Write tests for new functionality
- Update documentation
- Follow code style guidelines
- Test your changes
npm test npm run type-check - Commit with clear messages
git commit -m "feat: add support for new SQL driver" - Push to your fork
git push origin feature/your-feature-name
- Create Pull Request to
perses/persesmain branch
Follow Conventional Commits:
feat:- New featurefix:- Bug fixdocs:- Documentation changestest:- Test changesrefactor:- Code refactoringchore:- Maintenance tasks
sql/
├── src/
│ ├── datasources/sql-datasource/ # Datasource plugin
│ ├── queries/sql-time-series-query/ # Query plugin
│ ├── explore/ # Explore plugin
│ └── model/ # Utilities
├── schemas/ # CUE validation schemas
├── test-data/ # Sample data for testing
├── __mocks__/ # Jest mocks
├── package.json # Plugin configuration
├── rsbuild.config.ts # Module Federation config
├── jest.config.ts # Test configuration
└── Makefile # Database management
# Start backend with debug logging
./bin/perses --config ./dev/config.yaml --log.level=debug# Plugin automatically shows build output
percli plugin start .- F12 to open DevTools
- Check Console for errors
- Check the Network tab for API calls
- Check backend is running
- Check plugin server is running (
percli plugin start .) - Check browser console for errors
- Verify Module Federation configuration
- Check database is running (
docker ps) - Verify connection settings in datasource config
- Check backend logs for detailed error messages
- Run
npm run type-check - Check imports are correct
- Ensure types are defined
- Issues: Open an issue in the Perses repository
- Discussions: Join Perses community discussions
- Documentation: Check Perses documentation
By contributing, you agree that your contributions will be licensed under the Apache License 2.0.