Resource store sql backend watch (#90480)

* Squashed commit of the following:

commit 3ae9aea0fdc5eef70e16e0ba26f817ca1883ebc9
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Wed Jul 17 23:21:07 2024 +0200

    Add group and resource to ListOptions

commit 638441a656d4098343fd72f1942c5845fb50f536
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Wed Jul 17 22:25:35 2024 +0200

    poll for resources independently

commit 4c4c88e2d6b69a589a03fc4ea3b287ef557d67a0
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Wed Jul 17 17:39:10 2024 +0200

    Update pkg/storage/unified/sql/data/resource_history_poll.sql

    Co-authored-by: Dan Cech <dcech@grafana.com>

commit 67f42dbfcaa6b92056c7e6e25f21e870b7fa08e6
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Wed Jul 17 16:01:13 2024 +0200

    Update pkg/storage/unified/sql/backend.go

    Co-authored-by: Dan Cech <dcech@grafana.com>

commit e869e829d07d6fce6f79f18679680d32fa9491f5
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Wed Jul 17 16:01:06 2024 +0200

    Update pkg/storage/unified/sql/backend.go

    Co-authored-by: Dan Cech <dcech@grafana.com>

commit 6e498c0cd7434007649fd8de30a7d17e1c425c42
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Tue Jul 16 16:47:35 2024 +0200

    Add watch working for multiple resources

commit 0da775e521
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Tue Jul 16 11:14:55 2024 +0200

    indent

commit e15d1d060c
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 15 14:41:15 2024 +0200

    reindent sql

commit a64f88b0ea
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Fri Jul 12 18:32:13 2024 +0200

    Update pkg/storage/unified/sql/backend.go

    Co-authored-by: Dan Cech <dcech@grafana.com>

commit dd383150bf
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Wed Jul 10 10:45:56 2024 +0200

    lint

commit ccf12406a6
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 9 15:25:54 2024 -0700

    merge main

commit 2b4b9f66d3
Merge: df72a61a52 079f0715aa
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 9 15:12:51 2024 -0700

    merge main

commit df72a61a52
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 9 15:06:32 2024 -0700

    clearnup against smaller upstream

commit 12257d9dfe
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 9 15:03:50 2024 -0700

    clearnup against smaller upstream

commit 07b804457e
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Tue Jul 9 21:41:30 2024 +0200

    listAtRevision should always use the token from the RV if present

commit 1fc1dd0914
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Tue Jul 9 19:45:44 2024 +0200

    Update pkg/storage/unified/sql/backend.go

commit 2207ef10de
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Tue Jul 9 19:44:35 2024 +0200

    Update pkg/storage/unified/sql/queries_test.go

commit 36d9099d1a
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Tue Jul 9 15:57:55 2024 +0200

    lint

commit 37e0745d7a
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Tue Jul 9 12:26:49 2024 +0200

    Fix missing rows.Close()

commit a6538fa8df
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 23:54:33 2024 +0200

    add resource_history_list test

commit e8214869de
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 23:51:14 2024 +0200

    add resource_history_list test

commit f6b32c94bd
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 23:42:46 2024 +0200

    improve tests for pagination

commit d305f1baf4
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 22:57:11 2024 +0200

    Add pagination

commit c8f516fc55
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 21:55:25 2024 +0200

    pagination first page

commit f3c554e668
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 12:16:16 2024 +0200

    watch

commit 68a0cf5d81
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 12:12:09 2024 +0200

    remove testdataJSON

commit d98da81a42
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 11:49:05 2024 +0200

    move sqltemplate

commit 80bf285216
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 10:49:25 2024 +0200

    watch from head

commit 396979bcf6
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 10:19:01 2024 +0200

    Cleanup

commit 26a2f947e8
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 10:04:13 2024 +0200

    basic list

commit 4275a01bc2
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 00:54:33 2024 +0200

    add watch

commit 75c25a527d
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 8 00:51:40 2024 +0200

    add watch

commit 774ae238cb
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Sun Jul 7 21:49:44 2024 +0200

    Implement SQL store

commit 95ffa3486b
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 20:30:42 2024 -0700

    cleanup

commit ab591cf4d1
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 20:25:12 2024 -0700

    cleanup

commit aa4901e206
Merge: 36f7610097 40cb4ac30f
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 20:16:34 2024 -0700

    merge upstream

commit 40cb4ac30f
Merge: 8f4b3062d6 fe201b6bb2
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 20:02:04 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store-bridge

commit 8f4b3062d6
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 19:23:40 2024 -0700

    fix lint

commit 428b90c14b
Merge: 9e5b88c6dd edc1f50c4e
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 18:46:30 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store-bridge

commit 9e5b88c6dd
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 15:56:28 2024 -0700

    add field selectors

commit 8dd8bc85a6
Merge: 59a142095f de06762852
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 15:44:27 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store-bridge

commit 59a142095f
Merge: 53f16521a7 f70f60efd0
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 14:45:35 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store-bridge

commit 53f16521a7
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 14:45:25 2024 -0700

    add doc.go

commit 9fa906ab80
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 14:45:14 2024 -0700

    add doc.go

commit 22d3f163df
Merge: d09979b332 411bab6d44
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 13:55:27 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store-bridge

commit d09979b332
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 13:55:12 2024 -0700

    check for deleted

commit ddcbc753d3
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 13:38:16 2024 -0700

    fix tabs to spaces

commit 2a4fedb6ee
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 10:58:43 2024 -0700

    remove sort parsing

commit e728b12ec0
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 10:56:22 2024 -0700

    remove watch tests -- key func complications

commit dc163d10cc
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jul 3 08:59:09 2024 -0700

    add resource store abstraction

commit 36f7610097
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 21:37:01 2024 -0700

    using basic storage engine

commit 26ef342b7e
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 21:24:53 2024 -0700

    renamed to basic

commit ddb5f125f0
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 18:21:59 2024 -0700

    add sqlobj basic implementation

commit 6a08224725
Merge: 04d57a99e5 5b6edc96d9
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 17:47:36 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store

commit 04d57a99e5
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 14:47:02 2024 -0700

    merge main

commit 33917141f0
Merge: 924c42f707 2a1b620c38
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 14:45:45 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store

commit 924c42f707
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 14:37:35 2024 -0700

    make list preparelist

commit 0db0e13248
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 14:37:28 2024 -0700

    make list preparelist

commit a3d9f8aab2
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 14:08:42 2024 -0700

    remove eventID

commit 8c1f60aa8b
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 14:08:34 2024 -0700

    remove eventID

commit abacd9aef2
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 07:36:07 2024 -0700

    split off blob store services

commit ddae2b4969
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jul 2 07:23:53 2024 -0700

    rename search service to index service

commit a984a4e4f9
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Mon Jul 1 17:03:23 2024 -0700

    more lint

commit b25e735c02
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Mon Jul 1 16:04:53 2024 -0700

    frontend refactors

commit 1fb97cf417
Merge: fe8a05c648 c3b5cabb14
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Mon Jul 1 15:02:34 2024 -0700

    minor lint fixes

commit fe8a05c648
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Mon Jul 1 08:12:28 2024 -0700

    minor lint fixes

commit 9f2aae1c48
Merge: ece478e12d 86466aec61
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Mon Jul 1 08:03:18 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store

commit ece478e12d
Merge: f472e95f92 55ba32bda7
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Mon Jul 1 01:41:29 2024 -0700

    Merge remote-tracking branch 'origin/main' into resource-store

commit f472e95f92
Author: Andres Martinez Gotor <andres.martinez@grafana.com>
Date:   Mon Jul 1 09:31:05 2024 +0200

    Adapt docs/sources/developers/plugins/plugin.schema.json codeowners (#89832)

commit 8674d705ea
Author: Sebastian Hiebl <bastidest@mailbox.org>
Date:   Sat Jun 29 01:13:34 2024 +0200

    TimeSeries: Expose option for "Bar width factor" (#77338)

    Co-authored-by: Leon Sorokin <leeoniya@gmail.com>

commit 52d476db05
Author: Leon Sorokin <leeoniya@gmail.com>
Date:   Thu Jun 27 18:58:49 2024 -0500

    Table: Don't error if first frame is field-less (empty response) (#89867)

commit cc5b4d6a94
Author: Simon Podlipsky <simon@podlipsky.net>
Date:   Fri Jun 28 00:53:43 2024 +0300

    Dockerfile: Fix go deps (#89857)

    Add missing deps

commit 7c86705b9b
Author: Adela Almasan <88068998+adela-almasan@users.noreply.github.com>
Date:   Thu Jun 27 15:49:20 2024 -0600

    VizTooltip: Hide tooltip options from when tooltip is hidden (#89864)

commit aa9299c4d7
Author: Isabel Matwawana <76437239+imatwawana@users.noreply.github.com>
Date:   Thu Jun 27 17:16:57 2024 -0400

    Docs: Add tooltip options to histogram v11.2 (#89863)

    Co-authored-by: Adela Almasan <88068998+adela-almasan@users.noreply.github.com>

commit f90168f500
Author: Nathan Marrs <nathanielmarrs@gmail.com>
Date:   Thu Jun 27 14:43:10 2024 -0600

    Chore: Lint json files in .github directory (#89861)

commit 0f65c06cfe
Author: Nathan Marrs <nathanielmarrs@gmail.com>
Date:   Thu Jun 27 14:22:15 2024 -0600

    Chore: Update DataViz github automation (#89852)

commit 058538287f
Author: Lucy Chen <140550297+lucychen-grafana@users.noreply.github.com>
Date:   Thu Jun 27 15:36:23 2024 -0400

    ShareModal: Export options (JSON) (#87082)

    * Adding new export button

    * Create Export as JSON drawer

    * update scene drawer and add css

    * update css

    * Update ExportAsJson to be regular react component

    * add tests to export menu and button

    * add tests

    * prettier and lint

    * fix translations

    * update translation

    * Apply suggestions from code review

    Co-authored-by: Juan Cabanas <juan.cabanas@grafana.com>

    * delete extra file

    * Update to use SceneObject

    * add spinner

    * Rename ExportAsJSON.tsx to ExportAsJson.tsx

    * update i18n

    * Upate texts

    * small fixes from code review

    * add space

    * i18n

    * fix build issues

    * changes from review feedback

    * update test

    * update test

    ---------

    Co-authored-by: Juan Cabanas <juan.cabanas@grafana.com>

commit 79092ebc6a
Author: Juan Cabanas <juan.cabanas@grafana.com>
Date:   Thu Jun 27 14:30:33 2024 -0300

    ShareDrawer: Schedule Report (#89802)

commit d842178c6a
Author: linoman <2051016+linoman@users.noreply.github.com>
Date:   Thu Jun 27 18:29:16 2024 +0200

    SAML: Add Azure AD configuration for SAML integration (#89767)

    * Add Azure AD configuration for SAML integration

commit 920756f797
Author: Ashley Harrison <ashley.harrison@grafana.com>
Date:   Thu Jun 27 16:43:43 2024 +0100

    Storybook: Add basic e2e verification test (#89779)

    * add very basic tests to verify storybook builds correctly

    * add storybook step to drone

    * reorder steps

    * drone tweaks

    * don't need host since it's set in env

    * don't need to wait

    * format build.star and readd wait

    * install netcat in CI

    * do a yarn install here to get correct bindings

    * refactoring to hopefully work better in CI

    * add wait-on

    * add verbose logging

    * localhost?

    * more logging

    * specify storybook host

    * ...

    * back to grafana-server

    * does this work? 🤔

    * run storybook e2e test after rgm-package so the backround process is running for less time

    * split into separate step

    * format

commit a760dad1e3
Author: Ivan Ortega Alba <ivanortegaalba@gmail.com>
Date:   Thu Jun 27 17:26:38 2024 +0200

    VizPanelManager: Adapt color palete after plugin change (#89790)

    * VizPanelManager: Adapt color palete after plugin change

    * Upgrade scenes

    * Remove broken code

    * Upgrade scenes version

    * linter

commit c8ce20a807
Author: Ida Štambuk <ida.stambuk@grafana.com>
Date:   Thu Jun 27 17:10:28 2024 +0200

    Cloudwatch: Round up endTime in GetMetricData to next minute (#89341)

    * Add cloudWatchRoundUpEndTime feature toggle

commit 17ebc9614b
Author: Kristina <kristina.durivage@grafana.com>
Date:   Thu Jun 27 09:46:49 2024 -0500

    Explore / Query Library : Show user data (#88258)

    * Add basic button for adding a query template

    * Add hook to create a template

    * Handle notifications

    * Add tags to invalidate cache

    * Generate translations

    * Updates types

    * Add tests

    * Simplify code

    * Add user to type

    * Add a better default title

    * bring in piotrs pr and try to add user data

    * Move out of metadata (reserved in k8s) and make new values exportable

    * Show user data

    * Fix bad merge

    * WIP

    * Add annotation data to FE

    * add (failing) test

    * Fix types and test

    * Cleanup

    * Enhance user data and send to component for display

    * Fix type

    * Fix expected values

    * fix betterer

    * Fix test

    * Remove user lookup

    * testing slug usage for api

    * Revert "testing slug usage for api"

    This reverts commit cc4556c3b7.

    * change types, display userid if login isnt returned

    * Simply display whatever is in property

    * skip test on removed logic

    * Try waiting for query to finish before eval

    * Revert "Try waiting for query to finish before eval"

    This reverts commit 6220cabd17.

    * Handle attribute not existing when storage type is file

    ---------

    Co-authored-by: Piotr Jamroz <pm.jamroz@gmail.com>

commit 91895e4835
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Thu Jun 27 17:43:59 2024 +0300

    Chore(deps): Bump github.com/alicebob/miniredis/v2 from 2.30.1 to 2.33.0 (#88588)

    Bumps [github.com/alicebob/miniredis/v2](https://github.com/alicebob/miniredis) from 2.30.1 to 2.33.0.
    - [Release notes](https://github.com/alicebob/miniredis/releases)
    - [Changelog](https://github.com/alicebob/miniredis/blob/master/CHANGELOG.md)
    - [Commits](https://github.com/alicebob/miniredis/compare/v2.30.1...v2.33.0)

    ---
    updated-dependencies:
    - dependency-name: github.com/alicebob/miniredis/v2
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit ed6c948db0
Author: kay delaney <45561153+kaydelaney@users.noreply.github.com>
Date:   Thu Jun 27 14:17:21 2024 +0100

    Dashboards: Change datemath parse logic so parsed dates always take timezone into account (#88182)

    * Dashboards: Change datemath parse logic so parsed dates always take timezone into account

commit 523d999414
Author: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com>
Date:   Thu Jun 27 14:00:42 2024 +0200

    Alerting: Use runtime data source for getting events from alert state history in the bar chart (#89307)

    * Use runtime data source for getting events from alert state history in the bar chart

    * extract translations

    * refactor

    * More refactor

    * Update events limit

    * Add info icon with tooltip info for label querying filter

    * Add translations

    * Create new useRuleHistoryRecords hook skipping extraction of common labels as they are not used

    * Fix test

    * update limit value for the events in the api to 5000

    * Use state for rows key

    * remove React import

    * Address review comments

    * Address review comments

    * run prettier

    * Remove duplicated handlers

commit c3337c39b1
Author: Laura Benz <48948963+L-M-K-B@users.noreply.github.com>
Date:   Thu Jun 27 14:00:12 2024 +0200

    RestoreDashboards: Add search (#89692)

    * feat: add search

    * feat: run i18n extraction

    * refactor: styling issue for smaller screen sizes

commit 06084f0ed1
Author: Alexander Zobnin <alexanderzobnin@gmail.com>
Date:   Thu Jun 27 13:57:06 2024 +0200

    Zanzana: Initial schema loading (#89492)

    * Zanzana: Dummy schema loading

    * Load authorzation model for client

    ---------

    Co-authored-by: Karl Persson <kalle.persson@grafana.com>

commit ddea4ba8b2
Author: ismail simsek <ismailsimsek09@gmail.com>
Date:   Thu Jun 27 13:33:35 2024 +0200

    Chore: Remove CancelablePromise (#89564)

    * Remove CancelablePromise.ts as it wasn't used in anywhere

    * Move cancelable-promise to the place where it is used

commit 177747ecda
Author: Jack Westbrook <jack.westbrook@gmail.com>
Date:   Thu Jun 27 12:42:42 2024 +0200

    Grafana/data: Remove barrel files part 1 (#89556)

    * chore(grafana-data): remove dataframe barrel file and update all imports and exports

    * chore(grafana-data): remove field barrel file and update imports n exports

    * chore(grafana-data): remove utils barrel file and update imports and exports

    * chore(grafana-data): remove tranformations barrel file and update imports n exports

    * chore(grafana-data): remove imports from root index.ts

    * chore(grafana-data): remove valueFormats barrel file and update imports n exports

    * chore(grafana-data): don't import from root barrel file

commit c3b16639bc
Author: Ashley Harrison <ashley.harrison@grafana.com>
Date:   Thu Jun 27 11:15:15 2024 +0100

    Keybinds E2E: simplify keybinds e2e even further (#89819)

    simplify keybinds e2e even further

commit 8b7a891db4
Author: AHeinlein <AHeinlein@users.noreply.github.com>
Date:   Thu Jun 27 12:07:30 2024 +0200

    Docs: Update LDAP doc for debug view (#89522)

    Update LDAP doc

    LDAP debug view does not work with single bind since there is no way to bind to the LDAP server and perform the search.

commit cb31a1b6ff
Author: Tom Ratcliffe <tom.ratcliffe@grafana.com>
Date:   Thu Jun 27 10:33:40 2024 +0100

    Alerting: Update warning message for Telegram parse_mode and default to empty value (#89630)

commit 3ef048cdd7
Author: Sergej-Vlasov <37613182+Sergej-Vlasov@users.noreply.github.com>
Date:   Thu Jun 27 12:06:07 2024 +0300

    DashboardScenes: Disable flaky new-datasource-variable e2e test (#89817)

    disable flaky new-datasource-variable e2e test

commit e09c1c7515
Author: brendamuir <100768211+brendamuir@users.noreply.github.com>
Date:   Thu Jun 27 10:10:34 2024 +0200

    Alerting docs: adds silence RBAC 11.1 (#89176)

    * Alerting docs: adds silence RBAC 11.1

    * ran prettier

    * Improve docs with new rule-specific silence RBAC information

    * Apply suggestions from code review

    Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

    * Apply suggestions from code review

    Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

    * prettier

    ---------

    Co-authored-by: Matt Jacobson <matthew.jacobson@grafana.com>
    Co-authored-by: Jack Baldry <jack.baldry@grafana.com>

commit 1aeceb9d9a
Author: Alexander Akhmetov <me@alx.cx>
Date:   Thu Jun 27 09:45:15 2024 +0200

    Alerting: Add setting for maximum allowed rule evaluation results (#89468)

    * Alerting: Add setting for maximum allowed rule evaluation results

    Added a new configuration setting `quota.alerting_rule_evaluation_results` to set the maximum number of alert rule evaluation results per rule. If the limit is exceeded, the evaluation will result in an error.

commit e96b1c0b42
Author: Georges Chaudy <chaudyg@gmail.com>
Date:   Mon Jul 1 10:32:37 2024 +0200

    Add unified-next-grpc (#89891)

commit afe0848d16
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 13:11:10 2024 +0300

    history UI

commit 2fab168fb1
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 12:08:46 2024 +0300

    history UI

commit 1043efe3db
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 11:26:42 2024 +0300

    rename to legacy

commit d452e53ce3
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 10:53:08 2024 +0300

    avoid key from context

commit 19496ceed5
Merge: b71329a8c3 be1414b36b
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 10:19:58 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit b71329a8c3
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 10:09:59 2024 +0300

    history in resource package

commit 37c6b56e4e
Merge: 80fa46b225 9056ff73f6
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 08:49:46 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 80fa46b225
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 08:49:24 2024 +0300

    history from SQL query

commit 4d49cc3118
Merge: 999cd506c0 ed13959e33
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 07:35:23 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 999cd506c0
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 01:20:29 2024 +0300

    now with dashboard history

commit 7345ece8ef
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 27 00:10:30 2024 +0300

    with dashboard service

commit 86a7064334
Merge: f68390bebf ba4f2713c5
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 26 16:04:23 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit f68390bebf
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 26 16:04:08 2024 +0300

    not rest.Storage

commit cfc192a2b5
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 26 12:53:57 2024 +0300

    more utils

commit 197a837e1e
Merge: 44a134f72b 4651506319
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 26 08:48:10 2024 +0300

    merge main

commit 44a134f72b
Merge: bac63d0edb f5d9c247d9
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Mon Jun 24 20:55:15 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit bac63d0edb
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 17:39:19 2024 +0300

    remove old comment

commit 37edc450a7
Merge: af38567ea5 b62f8c0f19
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 17:38:20 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit af38567ea5
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 14:55:40 2024 +0300

    remove unimplemented functions

commit ec925bab80
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 14:53:23 2024 +0300

    has a watch bridge... but not working

commit b771d38d78
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 11:13:35 2024 +0300

    with build changes

commit 37c2dade15
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 09:58:38 2024 +0300

    writing to SQL

commit bb7d6d44cd
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 09:24:44 2024 +0300

    with setup flags

commit c2c9449629
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 09:09:01 2024 +0300

    working

commit d67f83a1f3
Merge: b07c4e4210 61a102274d
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 07:49:24 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit b07c4e4210
Merge: 09741a3f49 b075926202
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 21 00:52:10 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 09741a3f49
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 20 23:05:13 2024 +0300

    merge main

commit 8a6d2e9b6e
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 20 22:50:08 2024 +0300

    merge main

commit 63ebf7b12e
Merge: 75d5ad465e 5e95c1bdf8
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 20 22:34:38 2024 +0300

    merge main

commit 75d5ad465e
Merge: 83df3bdec8 d988f5c3b0
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 20 22:26:33 2024 +0300

    merge main

commit 83df3bdec8
Merge: a115bb6214 27e800768e
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 20 18:07:48 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit a115bb6214
Merge: c17140f263 13e069b5af
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 20 17:05:36 2024 +0300

    merge main

commit c17140f263
Merge: 3a6e7dc3f0 5d328983a1
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 19 22:59:26 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 3a6e7dc3f0
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 19 22:09:33 2024 +0300

    go mod tidy

commit 040f392018
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 19 22:01:10 2024 +0300

    Storage: Add cdk blob support to ResourceStore (#89408)

commit 3e85f87db6
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 19 15:15:37 2024 +0300

    Storage(NG): Move message and operation from protobuf to annotations (#89359)

commit 0b29ca5eac
Merge: 0717e39ec2 b3907ca5ec
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 19 14:57:21 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 0717e39ec2
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jun 18 22:27:16 2024 +0300

    K8s: Rename origin.key to origin.hash (#89337)

commit 4b4afa1fa7
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jun 18 21:19:21 2024 +0300

    more cleanup

commit 9f6709c167
Merge: 7e171702f4 b0c043de5f
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jun 18 21:17:30 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 7e171702f4
Merge: 760848d203 890482052a
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jun 18 16:08:30 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 760848d203
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jun 18 16:07:55 2024 +0300

    Storage (resource): Mutate object in storage, not k8s (#89331)

commit 5e4fa5d735
Merge: 4cde5bd59f ea7f6ea32f
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jun 18 08:44:04 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 4cde5bd59f
Merge: 549ecfe053 5f83fdef2c
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jun 18 07:27:05 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 549ecfe053
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Sat Jun 15 00:49:06 2024 +0300

    lint fix

commit 1a5de75c34
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Sat Jun 15 00:42:19 2024 +0300

    lint fix

commit 31a05d5666
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Sat Jun 15 00:26:45 2024 +0300

    hack hack hack... but working from kubectl

commit 2f64556cf1
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 23:34:04 2024 +0300

    almost... but stuck on requester

commit c1b786c718
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 23:10:59 2024 +0300

    cleanup

commit d8abf8d851
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 22:53:10 2024 +0300

    entity bridge

commit d5f3038421
Merge: df9baddf53 8491e02caf
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 21:48:25 2024 +0300

    merge main

commit df9baddf53
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 21:44:33 2024 +0300

    move test files

commit 617dd1b40e
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 21:30:41 2024 +0300

    add basic list

commit 8108e90fe2
Merge: ef3a601109 15c81b2a8b
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 17:42:18 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit ef3a601109
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 17:42:15 2024 +0300

    update the event type messages

commit 55d1e8ad1d
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 17:41:16 2024 +0300

    update the event type messages

commit a01f8dd099
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 16:52:17 2024 +0300

    remove rv from key and update watch signature

commit e78a5122ce
Merge: 504d84b8b2 90c3d74955
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 16:19:53 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 504d84b8b2
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 15:21:28 2024 +0300

    with storage wrapper

commit 4fa60b6546
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 15:21:17 2024 +0300

    with storage wrapper

commit d97d59ab38
Merge: f66768c67d 2dd44e2f58
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 14:55:52 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit f66768c67d
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 14:24:36 2024 +0300

    now with a base server implementation

commit 4a41f7d0dd
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 14:24:26 2024 +0300

    now with a base server implementation

commit 68003738fd
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 11:28:15 2024 +0300

    use partial object metadata

commit fc82089987
Merge: 9478befbcd dd3c3b5857
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 10:57:16 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 9478befbcd
Merge: 19481990d1 2173429ce2
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 09:08:14 2024 +0300

    merge main

commit 19481990d1
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 09:06:44 2024 +0300

    merge main

commit 29714d87fe
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 02:12:35 2024 +0300

    use a path hash for the blob table

commit 382d5d4e01
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Fri Jun 14 02:04:21 2024 +0300

    add fs based store

commit 15b958b2d1
Merge: a03a978eb4 e2f65dda0c
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 22:56:34 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit a03a978eb4
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 22:37:29 2024 +0300

    maybe happier

commit 79aed54c2c
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 22:12:55 2024 +0300

    more body prep

commit 1540c98fe1
Merge: f54af3d371 9d3a4e236d
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 21:19:51 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit f54af3d371
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 20:12:53 2024 +0300

    sum cleanup

commit a0f682b315
Merge: 2197a0e5e8 eb535e163d
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 20:05:01 2024 +0300

    merge main

commit 2197a0e5e8
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 16:02:06 2024 +0300

    update workspace

commit b696b6a32a
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 15:53:06 2024 +0300

    update go.mod

commit 8f44e1a349
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 15:49:41 2024 +0300

    lint fixes

commit c1798320d2
Merge: b44333730f afcb5a855c
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 14:27:42 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit b44333730f
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 14:26:57 2024 +0300

    now with basic test

commit f481f11d3a
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 09:11:10 2024 +0300

    change tree structure

commit e7c15b0e96
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 08:42:00 2024 +0300

    merged main and moved folder structure

commit 09e8605f14
Merge: 40829d645c 99d8025829
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 07:14:54 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 40829d645c
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Thu Jun 13 07:08:54 2024 +0300

    include client wrapper

commit 1857690bd0
Merge: c9c18717f5 ed400f0bbf
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 22:02:53 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit c9c18717f5
Merge: ad79d44db8 3ae95a6eb1
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 15:26:12 2024 +0300

    packaging

commit ad79d44db8
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 14:44:21 2024 +0300

    adding package

commit f8a2a83d59
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 14:44:18 2024 +0300

    adding package

commit 7b6e4d5da4
Merge: 16471fa057 58f7032b39
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 14:21:41 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 16471fa057
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 13:02:06 2024 +0300

    now with event setup

commit d83aa7f865
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 02:44:49 2024 +0300

    is_current

commit df148ca9ea
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 02:21:05 2024 +0300

    use reflection

commit 0118c7666a
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 02:20:47 2024 +0300

    use reflection

commit 5c91e52922
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 02:15:05 2024 +0300

    get metadata with reflection

commit af86293d87
Merge: 4dc3d0ee7f 465efbf802
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 00:48:13 2024 +0300

    Merge remote-tracking branch 'origin/main' into resource-store

commit 4dc3d0ee7f
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 00:34:40 2024 +0300

    update

commit 835879aa7a
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Wed Jun 12 00:29:52 2024 +0300

    revert hash key issues

commit ac39953d0e
Author: Ryan McKinley <ryantxu@gmail.com>
Date:   Tue Jun 11 23:01:40 2024 +0300

    basic queries

* remove old file
This commit is contained in:
Georges Chaudy 2024-07-22 15:07:12 +02:00 committed by GitHub
parent 5b17cd93c5
commit b2766ece5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 164 additions and 37 deletions

View File

@ -355,6 +355,10 @@ func (b *backend) PrepareList(ctx context.Context, req *resource.ListRequest) (*
_, span := b.tracer.Start(ctx, trace_prefix+"List")
defer span.End()
if req.Options == nil || req.Options.Key.Group == "" || req.Options.Key.Resource == "" {
return nil, fmt.Errorf("missing group or resource")
}
// TODO: think about how to handler VersionMatch. We should be able to use latest for the first page (only).
if req.ResourceVersion > 0 || req.NextPageToken != "" {
@ -373,9 +377,7 @@ func (b *backend) listLatest(ctx context.Context, req *resource.ListRequest) (*r
err := b.sqlDB.WithTx(ctx, ReadCommitted, func(ctx context.Context, tx db.Tx) error {
var err error
// TODO: Here the lastest RV might be lower than the actual latest RV
// because delete events are not included in the resource table.
out.ResourceVersion, err = fetchLatestRV(ctx, tx)
out.ResourceVersion, err = fetchLatestRV(ctx, tx, b.sqlDialect, req.Options.Key.Group, req.Options.Key.Resource)
if err != nil {
return err
}
@ -500,10 +502,10 @@ func (b *backend) WatchWriteEvents(ctx context.Context) (<-chan *resource.Writte
if err := b.Init(); err != nil {
return nil, err
}
// Fetch the lastest RV
since, err := fetchLatestRV(ctx, b.sqlDB)
// Get the latest RV
since, err := b.listLatestRVs(ctx)
if err != nil {
return nil, err
return nil, fmt.Errorf("get the latest resource version: %w", err)
}
// Start the poller
stream := make(chan *resource.WrittenEvent)
@ -511,9 +513,7 @@ func (b *backend) WatchWriteEvents(ctx context.Context) (<-chan *resource.Writte
return stream, nil
}
func (b *backend) poller(ctx context.Context, since int64, stream chan<- *resource.WrittenEvent) {
var err error
func (b *backend) poller(ctx context.Context, since groupResourceRV, stream chan<- *resource.WrittenEvent) {
interval := 100 * time.Millisecond // TODO make this configurable
t := time.NewTicker(interval)
defer close(stream)
@ -524,63 +524,123 @@ func (b *backend) poller(ctx context.Context, since int64, stream chan<- *resour
case <-b.ctx.Done():
return
case <-t.C:
since, err = b.poll(ctx, since, stream)
// List the latest RVs
grv, err := b.listLatestRVs(ctx)
if err != nil {
b.log.Error("watch error", "err", err)
b.log.Error("get the latest resource version", "err", err)
t.Reset(interval)
continue
}
for group, items := range grv {
for resource := range items {
// If we haven't seen this resource before, we start from 0
if _, ok := since[group]; !ok {
since[group] = make(map[string]int64)
}
if _, ok := since[group][resource]; !ok {
since[group][resource] = 0
}
// Poll for new events
next, err := b.poll(ctx, group, resource, since[group][resource], stream)
if err != nil {
b.log.Error("polling for resource", "err", err)
t.Reset(interval)
continue
}
since[group][resource] = next
}
}
t.Reset(interval)
}
}
}
// fetchLatestRV returns the current maxium RV in the resource table
func fetchLatestRV(ctx context.Context, db db.ContextExecer) (int64, error) {
// Fetch the lastest RV
rows, err := db.QueryContext(ctx, `SELECT COALESCE(max("resource_version"), 0) FROM "resource";`)
// listLatestRVs returns the latest resource version for each (Group, Resource) pair.
func (b *backend) listLatestRVs(ctx context.Context) (groupResourceRV, error) {
since := groupResourceRV{}
reqRVs := sqlResourceVersionListRequest{
SQLTemplate: sqltemplate.New(b.sqlDialect),
groupResourceVersion: new(groupResourceVersion),
}
query, err := sqltemplate.Execute(sqlResourceVersionList, reqRVs)
if err != nil {
return 0, fmt.Errorf("fetch latest rv: %w", err)
return nil, fmt.Errorf("execute SQL template to get the latest resource version: %w", err)
}
rows, err := b.sqlDB.QueryContext(ctx, query, reqRVs.GetArgs()...)
if err != nil {
return nil, fmt.Errorf("fetching recent resource versions: %w", err)
}
defer func() { _ = rows.Close() }()
if rows.Next() {
rv := new(int64)
if err := rows.Scan(&rv); err != nil {
return 0, fmt.Errorf("scan since resource version: %w", err)
for rows.Next() {
if err := rows.Scan(reqRVs.GetScanDest()...); err != nil {
return nil, err
}
return *rv, nil
if _, ok := since[reqRVs.Group]; !ok {
since[reqRVs.Group] = map[string]int64{}
}
if _, ok := since[reqRVs.Group][reqRVs.Resource]; !ok {
since[reqRVs.Group] = map[string]int64{}
}
since[reqRVs.Group][reqRVs.Resource] = reqRVs.ResourceVersion
}
return 0, fmt.Errorf("no rows")
return since, nil
}
func (b *backend) poll(ctx context.Context, since int64, stream chan<- *resource.WrittenEvent) (int64, error) {
// fetchLatestRV returns the current maximum RV in the resource table
func fetchLatestRV(ctx context.Context, x db.ContextExecer, d sqltemplate.Dialect, group, resource string) (int64, error) {
res, err := queryRow(ctx, x, sqlResourceVersionGet, sqlResourceVersionRequest{
SQLTemplate: sqltemplate.New(d),
Group: group,
Resource: resource,
resourceVersion: new(resourceVersion),
})
if errors.Is(err, sql.ErrNoRows) {
return 0, fmt.Errorf("now row for the provided resource version")
} else if err != nil {
return 0, fmt.Errorf("get resource version: %w", err)
}
return res.ResourceVersion, nil
}
func (b *backend) poll(ctx context.Context, grp string, res string, since int64, stream chan<- *resource.WrittenEvent) (int64, error) {
ctx, span := b.tracer.Start(ctx, trace_prefix+"poll")
defer span.End()
pollReq := sqlResourceHistoryPollRequest{
SQLTemplate: sqltemplate.New(b.sqlDialect),
Resource: res,
Group: grp,
SinceResourceVersion: since,
Response: new(historyPollResponse),
Response: &historyPollResponse{},
}
query, err := sqltemplate.Execute(sqlResourceHistoryPoll, pollReq)
if err != nil {
return 0, fmt.Errorf("execute SQL template to poll for resource history: %w", err)
return since, fmt.Errorf("execute SQL template to poll for resource history: %w", err)
}
rows, err := b.sqlDB.QueryContext(ctx, query, pollReq.GetArgs()...)
if err != nil {
return 0, fmt.Errorf("poll for resource history: %w", err)
return since, fmt.Errorf("poll for resource history: %w", err)
}
defer func() { _ = rows.Close() }()
next := since
for i := 1; rows.Next(); i++ {
nextRV := since
for rows.Next() {
// check if the context is done
if ctx.Err() != nil {
return 0, ctx.Err()
return nextRV, ctx.Err()
}
if err := rows.Scan(pollReq.GetScanDest()...); err != nil {
return 0, fmt.Errorf("scan row #%d polling for resource history: %w", i, err)
return nextRV, fmt.Errorf("scan row polling for resource history: %w", err)
}
resp := pollReq.Response
next = resp.ResourceVersion
if resp.Key.Group == "" || resp.Key.Resource == "" || resp.Key.Name == "" {
return nextRV, fmt.Errorf("missing key in response")
}
nextRV = resp.ResourceVersion
stream <- &resource.WrittenEvent{
WriteEvent: resource.WriteEvent{
Value: resp.Value,
@ -596,7 +656,7 @@ func (b *backend) poll(ctx context.Context, since int64, stream chan<- *resource
// Timestamp: , // TODO: add timestamp
}
}
return next, nil
return nextRV, nil
}
// resourceVersionAtomicInc atomically increases the version of a kind within a

View File

@ -77,12 +77,20 @@ func TestBackendHappyPath(t *testing.T) {
})
t.Run("PrepareList latest", func(t *testing.T) {
resp, err := store.PrepareList(ctx, &resource.ListRequest{})
resp, err := store.PrepareList(ctx, &resource.ListRequest{
Options: &resource.ListOptions{
Key: &resource.ResourceKey{
Namespace: "namespace",
Group: "group",
Resource: "resource",
},
},
})
assert.NoError(t, err)
assert.Len(t, resp.Items, 2)
assert.Equal(t, "item2 MODIFIED", string(resp.Items[0].Value))
assert.Equal(t, "item3 ADDED", string(resp.Items[1].Value))
assert.Equal(t, int64(4), resp.ResourceVersion)
assert.Equal(t, int64(5), resp.ResourceVersion)
})
t.Run("Watch events", func(t *testing.T) {
@ -162,7 +170,14 @@ func TestBackendPrepareList(t *testing.T) {
_, _ = writeEvent(ctx, store, "item3", resource.WatchEvent_DELETED) // rv=7
_, _ = writeEvent(ctx, store, "item6", resource.WatchEvent_ADDED) // rv=8
t.Run("fetch all latest", func(t *testing.T) {
res, err := store.PrepareList(ctx, &resource.ListRequest{})
res, err := store.PrepareList(ctx, &resource.ListRequest{
Options: &resource.ListOptions{
Key: &resource.ResourceKey{
Group: "group",
Resource: "resource",
},
},
})
assert.NoError(t, err)
assert.Len(t, res.Items, 5)
assert.Empty(t, res.NextPageToken)
@ -171,6 +186,12 @@ func TestBackendPrepareList(t *testing.T) {
t.Run("list latest first page ", func(t *testing.T) {
res, err := store.PrepareList(ctx, &resource.ListRequest{
Limit: 3,
Options: &resource.ListOptions{
Key: &resource.ResourceKey{
Group: "group",
Resource: "resource",
},
},
})
assert.NoError(t, err)
assert.Len(t, res.Items, 3)
@ -183,6 +204,12 @@ func TestBackendPrepareList(t *testing.T) {
t.Run("list at revision", func(t *testing.T) {
res, err := store.PrepareList(ctx, &resource.ListRequest{
ResourceVersion: 4,
Options: &resource.ListOptions{
Key: &resource.ResourceKey{
Group: "group",
Resource: "resource",
},
},
})
assert.NoError(t, err)
assert.Len(t, res.Items, 4)
@ -197,6 +224,12 @@ func TestBackendPrepareList(t *testing.T) {
res, err := store.PrepareList(ctx, &resource.ListRequest{
Limit: 3,
ResourceVersion: 7,
Options: &resource.ListOptions{
Key: &resource.ResourceKey{
Group: "group",
Resource: "resource",
},
},
})
assert.NoError(t, err)
assert.Len(t, res.Items, 3)
@ -218,6 +251,12 @@ func TestBackendPrepareList(t *testing.T) {
res, err := store.PrepareList(ctx, &resource.ListRequest{
NextPageToken: continueToken.String(),
Limit: 2,
Options: &resource.ListOptions{
Key: &resource.ResourceKey{
Group: "group",
Resource: "resource",
},
},
})
assert.NoError(t, err)
assert.Len(t, res.Items, 2)

View File

@ -8,5 +8,9 @@ SELECT
{{ .Ident "action" | .Into .Response.Action }}
FROM {{ .Ident "resource_history" }}
WHERE {{ .Ident "resource_version" }} > {{ .Arg .SinceResourceVersion }}
WHERE 1 = 1
AND {{ .Ident "group" }} = {{ .Arg .Group }}
AND {{ .Ident "resource" }} = {{ .Arg .Resource }}
AND {{ .Ident "resource_version" }} > {{ .Arg .SinceResourceVersion }}
ORDER BY {{ .Ident "resource_version" }} ASC
;

View File

@ -0,0 +1,6 @@
SELECT
{{ .Ident "resource_version" | .Into .ResourceVersion }},
{{ .Ident "group" | .Into .Group }},
{{ .Ident "resource" | .Into .Resource }}
FROM {{ .Ident "resource_version" }}
;

View File

@ -43,6 +43,7 @@ var (
sqlResourceVersionGet = mustTemplate("resource_version_get.sql")
sqlResourceVersionInc = mustTemplate("resource_version_inc.sql")
sqlResourceVersionInsert = mustTemplate("resource_version_insert.sql")
sqlResourceVersionList = mustTemplate("resource_version_list.sql")
)
// TxOptions.
@ -104,8 +105,11 @@ func (r *historyPollResponse) Results() (*historyPollResponse, error) {
return r, nil
}
type groupResourceRV map[string]map[string]int64
type sqlResourceHistoryPollRequest struct {
*sqltemplate.SQLTemplate
Resource string
Group string
SinceResourceVersion int64
Response *historyPollResponse
}
@ -176,6 +180,11 @@ type resourceVersion struct {
ResourceVersion int64
}
type groupResourceVersion struct {
Group, Resource string
ResourceVersion int64
}
func (r *resourceVersion) Results() (*resourceVersion, error) {
return r, nil
}
@ -189,3 +198,12 @@ type sqlResourceVersionRequest struct {
func (r sqlResourceVersionRequest) Validate() error {
return nil // TODO
}
type sqlResourceVersionListRequest struct {
*sqltemplate.SQLTemplate
*groupResourceVersion
}
func (r sqlResourceVersionListRequest) Validate() error {
return nil // TODO
}