Graphite: Backend tag values autocomplete endpoint (#110773)

* Add lint rules

* Backend decoupling

- Add standalone files
- Add graphite query type
- Add logger to Service
- Create logger in the ProvideService method
- Use a pointer for the HTTP client provider
- Update logger usage everywhere
- Update tracer type
- Replace simplejson with json
- Add dummy CallResource and CheckHealth methods
- Update tests

* Update ConfigEditor imports

* Update types imports

* Update datasource

- Switch to using semver package
- Update imports

* Update store imports

* Update helper imports and notification creation

* Update context import

* Update version numbers and logic

* Copy array_move from core

* Test updates

* Add required files and update plugin.json

* Update core references and packages

* Remove commented code

* Update wire

* Lint

* Fix import

* Copy null type

* More lint

* Update snapshot

* Refactor backend

- Split query logic into separate file
- Move utils to separate file

* Add health-check logic

- Support backend healthcheck if the FF is enabled

* Remove query import support as unneeded

* Add test

* Add util function for decoding responses

* Add events types

* Add resource handler

* Add events handler and generic resource req handler

* Tests

* Update frontend

- Add types
- Update events function to support backend requests

* Lint and typing

* Lint

* Add metrics find endpoint

- Add types
- Add generic response parser
- Add endpoint
- Tests

* Update FE functoin to use backend endpoint

* Lint

* Simplify request

* Update test

* Metrics expand type

* Extract shared logic and add metric expand endpoint

* Update tests

* Call metric expand from backend

* Rename type for clarity

* Add get resource req handler

* Refactor doGraphiteRequest, parseResponse

Update tests

* Migrate functions endpoint to backend

* Support tags autocomplete in backend

- Add tests
- Add types
- Remove unneeded comments

* Support tag values autocomplete

- Remove unused frontend endpoints
- Add types
- Update tests

* Add tests

* Review

* Review

* Fix packages

* Format

* Fix merge issues

* Review

* Fix undefined values

* Extract request creation

- Add method for create requests generically with tests
- Replace usage in query method
- Update usages in resource handlers
- Update tests
- Update types

* Lint
This commit is contained in:
Andreas Christou
2025-09-15 11:35:29 +01:00
committed by GitHub
parent f392bb6f94
commit df2bb6be0a
7 changed files with 243 additions and 109 deletions
+40 -22
View File
@@ -26,7 +26,7 @@ func Test_CreateRequest(t *testing.T) {
expectedMethod string
expectedError string
checkHeaders map[string]string
checkQuery map[string]string
checkQuery map[string][]string
}{
{
name: "basic request with default GET method",
@@ -57,16 +57,16 @@ func Test_CreateRequest(t *testing.T) {
name: "request with query parameters",
dsInfo: dsInfo,
params: URLParams{
QueryParams: map[string]string{
"query": "stats.counters.*",
"format": "json",
QueryParams: map[string][]string{
"query": {"stats.counters.*"},
"format": {"json"},
},
},
expectedURL: "http://graphite.example.com",
expectedMethod: "GET",
checkQuery: map[string]string{
"query": "stats.counters.*",
"format": "json",
checkQuery: map[string][]string{
"query": {"stats.counters.*"},
"format": {"json"},
},
},
{
@@ -99,9 +99,9 @@ func Test_CreateRequest(t *testing.T) {
params: URLParams{
SubPath: "/metrics/expand",
Method: "POST",
QueryParams: map[string]string{
"groupByExpr": "true",
"leavesOnly": "false",
QueryParams: map[string][]string{
"groupByExpr": {"true"},
"leavesOnly": {"false"},
},
Headers: map[string]string{
"X-Custom-Header": "test-value",
@@ -110,9 +110,9 @@ func Test_CreateRequest(t *testing.T) {
},
expectedURL: "http://graphite.example.com/metrics/expand",
expectedMethod: "POST",
checkQuery: map[string]string{
"groupByExpr": "true",
"leavesOnly": "false",
checkQuery: map[string][]string{
"groupByExpr": {"true"},
"leavesOnly": {"false"},
},
checkHeaders: map[string]string{
"X-Custom-Header": "test-value",
@@ -130,16 +130,30 @@ func Test_CreateRequest(t *testing.T) {
name: "empty query parameter values",
dsInfo: dsInfo,
params: URLParams{
QueryParams: map[string]string{
"empty": "",
"valid": "value",
QueryParams: map[string][]string{
"empty": {""},
"valid": {"value"},
},
},
expectedURL: "http://graphite.example.com",
expectedMethod: "GET",
checkQuery: map[string]string{
"empty": "",
"valid": "value",
checkQuery: map[string][]string{
"empty": {""},
"valid": {"value"},
},
},
{
name: "multi-valued query parameter",
dsInfo: dsInfo,
params: URLParams{
QueryParams: map[string][]string{
"valid": {"value1", "value2"},
},
},
expectedURL: "http://graphite.example.com",
expectedMethod: "GET",
checkQuery: map[string][]string{
"valid": {"value1", "value2"},
},
},
}
@@ -163,9 +177,13 @@ func Test_CreateRequest(t *testing.T) {
assert.Equal(t, tt.expectedMethod, req.Method)
if tt.checkQuery != nil {
for key, expectedValue := range tt.checkQuery {
actualValue := req.URL.Query().Get(key)
assert.Equal(t, expectedValue, actualValue, "Query parameter %s", key)
for key, expectedValues := range tt.checkQuery {
actualValue := req.URL.Query()[key]
assert.NotZero(t, len(actualValue))
for _, expectedValue := range expectedValues {
assert.Contains(t, actualValue, expectedValue, "Query parameter %s", key)
}
}
}