648 Commits

Author SHA1 Message Date
43f56c5ca1 Apiserver: Refactor authenticator and authorizers (#101449)
* Clean up authenticator

* Cleanup authorizers and replace org_id and stack_id with namespace authorizer

* Remove dependency on org service

* Extract orgID from /apis/ urls and validate stack id
2025-03-06 16:01:12 +01:00
a1d5e5dad1 K8s/Swagger: Avoid */* media type (#101658)
* avoid */*

* use application/yaml

* fix lint
2025-03-06 10:13:31 +03:00
dc2defd84f K8s/Annotations: Use manager/source annotations rather than repo (#101313)
Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
2025-03-05 08:54:20 +02:00
c1b48cc488 Dashboards: Add apiVersion to dashboard table (#100845) 2025-03-04 07:47:45 +03:00
c7c68322b1 Alerting: Allow specifying a folder for Prometheus rule import (#101406)
What is this feature?

Allows the creation of alert rules with mimirtool in a specified folder.

Why do we need this feature?

Currently, the APIs for mimirtool create namespaces and rule groups in the root folder without the ability to set a custom folder. For example, it could be a special "Imported" folder, etc.

This PR makes it possible with a special header: mimirtool ... --extra-headers="X-Grafana-Alerting-Folder-UID=123". If it's not present, the root folder is used, otherwise, the specified one is used.

mimirtool does not support nested folder structures, while Grafana allows folder nesting. To keep compatibility, we return only direct child folders of the working folder (as namespaces) with rule groups and rules that are directly in these child folders as if there are no nested folders.

For example, given this folder structure in Grafana:

```
	grafana/
	├── production/
	│   ├── service1/
	│   │   └── alerts/
	│   └── service2/
	└── testing/
	    └── service3/
```

If the working folder is "grafana":

    Only namespaces "production" and "testing" are returned
    Only rule groups directly within these folders are included

If the working folder is "production":
   -  Only namespaces "service1" and "service2" are returned
    Only rule groups directly within these folders are included
2025-03-03 17:59:01 +01:00
f5e5824bab fix (unified-storage): stop registering unified storage metrics in global state (#101322)
* move prometheus.register for unified storage metrics into metrics.go and do most of the plumbing to get it to work

* convert StorageApiMetrics to pointer and check for nil before using it

* rename type and variables to something more sensible

---------

Co-authored-by: Jean-Philippe Quéméner <jeanphilippe.quemener@grafana.com>
2025-02-28 07:39:39 -05:00
ae2074ef55 Alerting: Fix updating Prometheus definition in the metadata (#101440)
Initially, Metadata had only the EditorSettings, and HasMetadata was used to understand if the incoming update request had metadata in the body because it could be omitted if it was empty. For example, when the rule is updated via the provisioning API or has only false values. If it was in the request, we used that; if not, we used the metadata from the existing rule from the database. If the rule was updated via the AlertRuleService, we didn't change Metadata at all if the rule already existed.

But now, Metadata also has the Prometheus rule definition, and we always need to update it with the new version of the AlertRuleService when the rule exists in the DB and has the same UID. HasMetadata is renamed to HasEditorSettings to keep the old behaviour only for EditorSettings.

Now, the provisioning API and the conversion API will overwrite everything except EditorSettings with the new data.
2025-02-28 13:11:49 +02:00
ef86582dfc Alerting: API paths for cortextool to import Loki rules (#101409)
Alerting: Legacy rules paths for cortextool
2025-02-27 17:20:49 +01:00
d947433d19 Alerting: API to delete rule groups using mimirtool (#100687)
* Alerting: API to delete rule groups using mimirtool
2025-02-27 13:04:47 +01:00
6eb335a8ce Alerting: API to read rule groups using mimirtool (#100674) 2025-02-25 15:49:08 +01:00
b641fd64f9 Alerting: API to create rule groups using mimirtool (#100558)
What is this feature?

Adds an API endpoint to create alert rules with mimirtool:

- POST /convert/prometheus/config/v1/rules/{NamespaceTitle} - Accepts a single rule group in a Prometheus YAML format and creates or updates a Grafana rule group from it.

The endpoint uses the conversion package from #100224.

Key parts

The API works similarly to the provisioning API. If the rule does not exist, it will be created, otherwise updated. Any rules not present in the new group will be deleted, ensuring the group is fully synchronized with the provided configuration.

Since the API works with namespace titles (folders), the handler automatically creates a folder in the root based on the provided title if it does not exist. It also requires a special header, X-Grafana-Alerting-Datasource-UID. This header specifies which datasource to use for the new rules.

If the rule group's evaluation interval is not specified, it uses the DefaultRuleEvaluationInterval from settings.
2025-02-25 11:26:36 +01:00
279b641469 Provisioning: Define large parts of our infrastructure (#101029)
* Provisioning: Define secrets service

* Provisioning: Create and store secrets service

* Provisioning: Define safepath

* Provisioning: Define the repository

* Identity: Support a provisioning service

* Provisioning: Define a job queue

* Chore: Regen code

* Provisioning: Show progress more often

Co-Authored-By: Ryan McKinley <ryantxu@gmail.com>

* Provisioning: Rename hash field to lastRef

Co-Authored-By: =?UTF-8?q?Roberto=20Jim=C3=A9nez=20S=C3=A1nchez?= <roberto.jimenez@grafana.com>

* Provisioning: Workflows as write access

Co-Authored-By: Ryan McKinley <ryantxu@gmail.com>

* Provisioning: Regen OpenAPI snapshot

* Provisioning: Update tests to match new fields

---------

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
Co-authored-by: =?UTF-8?q?Roberto=20Jim=C3=A9nez=20S=C3=A1nchez?= <roberto.jimenez@grafana.com>
2025-02-24 09:08:58 +01:00
d1dfa0576b Alerting: Support Jira Integration (#100480) 2025-02-21 12:51:38 -05:00
79c0e5e3ec scopes: moves scopes to enterprise (#100746)
Signed-off-by: bergquist <carl.bergquist@gmail.com>
2025-02-21 08:51:34 +01:00
b1b5b4766c Alerting: Sanitize Slack image upload comment labels (#101084)
* Alerting: Sanitize Slack image upload comment labels

upgrades grafana/alerting to d43046
2025-02-20 12:22:04 -05:00
5a40c84568 DualWriter: Support managed DualWriter (#100881) 2025-02-19 17:50:39 +03:00
3e6f40c873 K8s: Move to one feature toggle for folders and dashboards (#100911) 2025-02-19 01:11:26 +02:00
ff7ba54cbc Investigations: Add experimental app platform backend (#100584)
* add investigations group?

* Investigations: Add experimental app platform backend

* change `grafana-app-sdk/logging` version

* investigations: add feature flag to test

---------

Co-authored-by: Sven Grossmann <svennergr@gmail.com>
2025-02-17 19:19:22 +01:00
f535a7804f Provisioning: Update types (#100722)
* Provisioning: Remove S3

* Provisioning: Use URL for GitHub

Co-Authored-By: Ryan McKinley <ryantxu@gmail.com>
Co-Authored-By: Alex Khomenko <Clarity-89@users.noreply.github.com>

* Provisioning: Use workflow list

Co-Authored-By: =?UTF-8?q?Roberto=20Jim=C3=A9nez=20S=C3=A1nchez?= <roberto.jimenez@grafana.com>

* Provisioning: Model secrets

* Provisioning: Define a total in the job summary

* Provisioning: Generate code

* Provisioning: Update testdata

---------

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
Co-authored-by: =?UTF-8?q?Roberto=20Jim=C3=A9nez=20S=C3=A1nchez?= <roberto.jimenez@grafana.com>
2025-02-17 12:45:23 +01:00
6eeb28e312 Authn: use authenticator for grpc (#99573)
* Remove usage of grpc-authenticator

* Cleanup client construction code
2025-02-17 10:58:59 +01:00
e343cb5ac9 Alerting: Stop running AM integration tests on CI (#100702) 2025-02-14 16:55:20 +01:00
d092998927 Query Library: Move backend to enterprise (#100371)
* Move files to enterprise

* Remove last parts of QL api

* Fix CODEOWNERS
2025-02-14 11:05:03 +00:00
19777ba3e9 Skip flaky test that's breaking the CI pipelines (#100640) 2025-02-13 17:49:21 +01:00
ae9837b793 Alerting: Add alertmanager integration tests (#100106) 2025-02-13 11:36:45 +01:00
d1dee968c3 Schema V2: Adjust quick_ranges in time settings and remove time_options (#100135)
* adjut quickRanges type in v2

* clean up unused time_options property

* remove deprecated time_options property on time picker

* add schema migration for time_options

* adjust test
2025-02-12 19:23:09 +00:00
7dee4d1808 Alerting: Allow specifying uid for new rules added to groups (#99858)
When modifying rule groups the `uid` can be specified but only if the rule already existed in the DB. If the rule is new the update would be rejected.

This updates the RuleGroup provisioning apis to allow specifying the `uid` when creating/updating rule groups. 

Additionally, the RuleGroupIdx was not being updated when rules were reordered in the group.

Context: https://github.com/grafana/terraform-provider-grafana/pull/1971#issuecomment-2599223897
Relates to: https://github.com/grafana/terraform-provider-grafana/issues/1928

Fixes: #98283
2025-02-10 10:28:34 -05:00
45775dd6ad Skip flakey test (#100251) 2025-02-10 07:40:32 +00:00
7ae8058c8b Alerting: Return 404 when /api/ruler/grafana/api/v1/rules/{Namespace}/{Groupname} does not exist (#100264)
* Return a 404 when rule group doesn't exist

* Update tests

* Update swagger doc and tests
2025-02-07 16:24:28 +00:00
dfaa12b800 Provisioning: Sync API with current feature branch (#100252)
* Provisioning: Jobs: Define repository name field

* Provisioning: Jobs: Separate options per job type

* Provisioning: Define a sanitised settings resource

* Provisioning: Jobs: Define a job summary

* Provisioning: Remove linting

* Provisioning: Update docs for a few fields

* Provisioning: Remove HelloWorld

* Provisioning: Replace Repository with Message in job info

* Provisioning: Remove YAML support

* Provisioning: Remove custom folder specification

* Provisioning: Support read-only repositories

* Provisioning: Remove edit options

* Provisioning: Add sync options for repositories

* Provisioning: Add resource statistics

* Provisioning: Make slices atomic lists

* Provisioning: Message list needs to exist even if empty

If we don't do this, we can't clear the messages field, leading to buggy UX.

* Provisioning: Support incremental syncing

* Provisioning: Remove the 'items' subresource workaround

* Provisioning: Add resource list

* Provisioning: Reformat

* Provisioning: Declare new types

* OpenAPI: Generate openapi JSON spec from generated code

* Codegen: Generate OpenAPI spec

* Provisioning: Support generating frontend API

* Codegen: Generate Go code

* Provisioning: Define the base API

* Codegen: Generate frontend endpoints for provisioning

* Refactor: yarn prettier:write

* Provisioning: Tiger team takes ownership

* Chore: Remove dir we haven't added yet

* Provisioning: Remove frontend

* Test: Update example repositories
2025-02-07 15:35:55 +01:00
e815a2850e Provisioning: Integration test that Repository resources work (#100197)
* Provisioning: Set up server in practice

* Provisioning: Integration test that Repository resources work
2025-02-07 12:04:58 +01:00
f7d476e408 Alerting: Remove id and org_id from grafana alert rule API model (#100139) 2025-02-05 23:13:22 +02:00
69e4d8468b Dashboard: Add v1alpha1 test coverage (#100149) 2025-02-05 23:01:51 +02:00
ac41c19350 Alerting: Rule version history API (#99041)
* implement store method to read rule versions

* implement request handler

* declare a new endpoint

* fix fake to return correct response

* add tests

* add integration tests

* rename history to versions

* apply diff from swagger CI step

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>

---------

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
2025-02-03 13:26:18 -05:00
e0151528a4 API client generation: Update iam client (#99963)
* update generated iam client

* update API

* with meta api

* regenerate client

* with identify ref

---------

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2025-02-03 13:40:36 +00:00
b636b81b16 K8s/IAM: Use raw handler for display (not rest.Connector) (#99898) 2025-02-03 14:24:35 +03:00
9693212475 API client generation: Create new IAM api client and use in query library (#99888)
* create new generated iam api client and use in query library

* update betterer

* use new createBaseQuery method

* update CODEOWNERS

* fix unit tests

* use shared type

* update comment

* fix test
2025-01-31 17:12:55 +00:00
9d5af95565 K8s/OpenAPI: Remove /watch/ from the openapi spec (#99793) 2025-01-30 12:51:55 +03:00
3c0383f0d5 K8s/Test: Allow setting license path in test helper (#99786) 2025-01-30 08:59:00 +02:00
b820fd6bef Alerting: Fix Alertmanager configuration updates (#99610)
* Alerting: Fix Alertmanager configuration updates

Alertmanager configuration updates would behave inconsistently when performing no-op updates with `mysql` as the store.

In particular this bug manifested as a failure to reload the provisioned alertmanager configuration components with no changes to the configuration itself. This would result in a 500 error with mysql store only.

The core issue is that we were relying on the number of rows affected by the update query to determine if the configuration was found in the db or not.
While this behavior works for certain sql dialects, mysql does not return the number of rows matched by the update query but rather the number of rows actually updated.

Also discovered and fixed the mismatched `xorm` tag for the `CreatedAt` field to match the actual column name in the db.

References: https://dev.mysql.com/doc/refman/8.4/en/update.html
2025-01-29 23:00:45 +02:00
9f4e8ee206 Query Library: Update API client (#99382)
* Add process script

* Working version

* Use new types

* Use new types

* Update client

* Tweaks

* Process multiple specs

* Remove 'any' types

* Use BASE_URL

* Update CODEOWNERS

* Fix filename

* add openapi

* update CODEOWNDER

* use JSONeq

* Use existing specs

* Filter ForAllNamespaces

* Add instructions

* Switch to tsx

* Use openapi-types

* Update src path

* Expand docs

* Update docs

* Rename script

* codeowners

* More docs

* Move openapi-types to dev deps

* Update error message

* Update doc

* Fix typo

---------

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2025-01-29 18:05:40 +02:00
8415059290 K8s/OpenAPI: Move openapi snapshots out of the root (#99728) 2025-01-29 09:26:17 +02:00
4e703576b0 K8s/OpenAPI: Render openapi into a static file (#99561) 2025-01-28 10:30:53 +03:00
82f457495a Alerting: Correctly escape provisioning API exports (#99039)
When exporting contact-points, mute-timings, and notification policies in the provisioning API, we need to escape the `$` character which is used in interpolation by file provisioning.

Follow up to #97985
2025-01-27 14:59:50 -05:00
d71904cb27 Alerting: Expose updated_by in rules GET APIs (#99525)
---------

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
2025-01-27 14:31:40 -05:00
af663dadc7 Alerting: Refactor integration tests (#99519)
---------

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
2025-01-24 14:49:05 -05:00
a037c6f344 K8s/Folders: Remove kubernetesFolders flag and full path metadata (#99256)
* remove full path

* remove more

* remove KubernetesFolders tests

* remove feature toggles

* remove feature toggles

* skip permissions test

* skip permissions test

---------

Co-authored-by: Jack Baldry <jack.baldry@grafana.com>
2025-01-23 17:25:03 +03:00
20d25c6ad9 Alerting: Use rule uid in silenceURL template instead of alertname and folder (#99221)
* Update grafana/alerting to a5e8136407d4

Includes:
- Alerting: Use rule uid in silenceURL template instead of alertname and folder (#266)

* Fix tests
2025-01-21 18:11:22 -05:00
d8b6ded101 K8s: use deprecatedInternalID label rather than SQL annotation (#99263) 2025-01-21 12:38:14 +03:00
b2d0359e72 K8s/Folders: Remove slow/redundant folder integration tests (#99291) 2025-01-21 11:14:31 +03:00
7329d2c34b Authz: Account for fixed roles when running oss and using authz service (#99244)
* Extract "PermissionStore" from general store interface

* Add static and union permission stores

* Add GetStaticRoles

* Use accesscontrol.Service for inproc to provide static permissions
2025-01-20 16:00:36 +01:00