Skip to content

Commit 5c2a1ba

Browse files
committed
Merge remote-tracking branch 'origin/main' into iwysiu/ds/329
2 parents a3ed029 + 129ec28 commit 5c2a1ba

File tree

13 files changed

+246
-161
lines changed

13 files changed

+246
-161
lines changed

.github/workflows/check-grafana-compatibility.yml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,49 @@ name: Detect breaking change with Grafana
55
on:
66
pull_request:
77
paths:
8-
- 'go.mod'
9-
- 'go.sum'
8+
- "go.mod"
9+
- "go.sum"
1010
branches:
11-
- 'main'
11+
- "main"
1212

1313
jobs:
1414
buildPR:
1515
name: Build PR
1616
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
1719
steps:
18-
- uses: actions/checkout@v4
19-
with:
20-
path: './grafana-plugin-sdk-go'
21-
- uses: actions/checkout@v4
22-
with:
23-
repository: 'grafana/grafana'
24-
path: './grafana'
25-
- uses: actions/setup-go@v5
26-
with:
27-
cache: false
28-
go-version: '~1.22'
29-
check-latest: true
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
with:
22+
persist-credentials: false
23+
path: "./grafana-plugin-sdk-go"
24+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25+
with:
26+
persist-credentials: false
27+
repository: "grafana/grafana"
28+
path: "./grafana"
29+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # 5.5.0
30+
with:
31+
cache: false
32+
go-version: "~1.22"
33+
check-latest: true
3034

31-
- name: Check if branch exists in Grafana
32-
working-directory: './grafana'
33-
run: |
34-
if git ls-remote --heads --quiet --exit-code origin ${{ github.head_ref }}
35-
then
36-
echo "Found branch ${{ github.head_ref }} in Grafana"
37-
git fetch origin ${{ github.head_ref }}
38-
git checkout ${{ github.head_ref }}
39-
else
40-
echo "Branch ${{ github.head_ref }} not found in Grafana"
41-
fi
35+
- name: Check if branch exists in Grafana
36+
working-directory: "./grafana"
37+
env:
38+
BRANCH: ${{ github.head_ref }}
39+
run: |
40+
if git ls-remote --heads --quiet --exit-code origin "$BRANCH"; then
41+
echo "Found branch $BRANCH in Grafana"
42+
git fetch origin "$BRANCH" && git checkout "$BRANCH"
43+
else
44+
echo "Branch $BRANCH not found in Grafana"
45+
fi
4246
43-
- name: Link sdk
44-
working-directory: './grafana'
45-
run: go mod edit -replace github.com/grafana/grafana-plugin-sdk-go=../grafana-plugin-sdk-go
47+
- name: Link sdk
48+
working-directory: "./grafana"
49+
run: go mod edit -replace github.com/grafana/grafana-plugin-sdk-go=../grafana-plugin-sdk-go
4650

47-
- name: Automatic updates
48-
working-directory: './grafana'
49-
run: go mod tidy
50-
51-
- name: Build Grafana
52-
working-directory: './grafana'
53-
run: make build-go
51+
- name: Build Grafana
52+
working-directory: "./grafana"
53+
run: make build-go

.github/workflows/check-incompatibility.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ on:
1414
jobs:
1515
main:
1616
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
1719
steps:
18-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1921
with:
22+
persist-credentials: false
2023
path: './grafana-plugin-sdk-go'
21-
- uses: actions/setup-go@v5
24+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # 5.5.0
2225
with:
2326
cache: false
2427
check-latest: true

.github/workflows/ci.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,32 @@ on:
99
permissions:
1010
contents: read
1111

12-
env:
13-
GOLANGCI_LINT_VERSION: v1.64.2
14-
1512
jobs:
1613
lint-build-test:
1714
name: Lint, Build, and Test
1815
runs-on: ubuntu-latest
1916
steps:
2017
- name: Checkout
21-
uses: actions/checkout@v4
18+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19+
with:
20+
persist-credentials: false
2221

2322
- name: Setup go
24-
uses: actions/setup-go@v5
23+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # 5.5.0
2524
with:
2625
go-version-file: ./go.mod
2726

2827
- name: Run golangci-lint
29-
uses: golangci/golangci-lint-action@v6
28+
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
3029
with:
31-
version: ${{env.GOLANGCI_LINT_VERSION}}
30+
version: v1.64.2
3231
args: |
3332
"./..." --timeout=7m
3433
skip-cache: true
3534
install-mode: binary
3635

3736
- name: Setup Mage
38-
uses: magefile/mage-action@v3
37+
uses: magefile/mage-action@6f50bbb8ea47d56e62dee92392788acbc8192d0b # v3
3938
with:
4039
install-only: true
4140

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
stale:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/stale@v9
12+
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9
1313
with:
1414
# Number of days of inactivity before a stale Issue or Pull Request is closed.
1515
# Set to -1 to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.

.github/workflows/validate-protos.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ on:
1212
jobs:
1313
main:
1414
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
1517
steps:
1618
# Run `git checkout`
17-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
with:
21+
persist-credentials: false
1822
# Install the `buf` CLI
19-
- uses: bufbuild/buf-setup-action@v1
23+
- uses: bufbuild/buf-setup-action@a47c93e0b1648d5651a065437926377d060baa99 # v1.50.0
2024
# Perform breaking change detection against the `proto` directory in the `main` branch
21-
- uses: bufbuild/buf-breaking-action@v1
25+
- uses: bufbuild/buf-breaking-action@c57b3d842a5c3f3b454756ef65305a50a587c5ba # v1.1.4
2226
with:
2327
input: 'proto'
2428
against: 'https://github.com/grafana/grafana-plugin-sdk-go.git#branch=main,subdir=proto'

backend/httpclient/datasource_metrics_middleware.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ var (
5252
}, []string{"datasource_type", "secure_socks_ds_proxy_enabled", "endpoint"},
5353
)
5454

55+
datasourceResponseGauge = promauto.NewGaugeVec(
56+
prometheus.GaugeOpts{
57+
Namespace: "plugins",
58+
Name: "datasource_response_size",
59+
Help: "gauge of data source response sizes returned to Grafana in bytes",
60+
}, []string{"datasource_type", "secure_socks_ds_proxy_enabled", "endpoint"},
61+
)
62+
5563
datasourceRequestsInFlight = promauto.NewGaugeVec(
5664
prometheus.GaugeOpts{
5765
Namespace: "plugins",
@@ -128,6 +136,7 @@ func executeMiddleware(next http.RoundTripper, datasourceType string, secureSock
128136
requestHistogram := datasourceRequestHistogram.MustCurryWith(labels)
129137
requestInFlight := datasourceRequestsInFlight.With(labels)
130138
responseSizeHistogram := datasourceResponseHistogram.With(labels)
139+
responseSizeGauge := datasourceResponseGauge.With(labels)
131140

132141
res, err := promhttp.InstrumentRoundTripperDuration(requestHistogram,
133142
promhttp.InstrumentRoundTripperCounter(requestCounter,
@@ -140,6 +149,7 @@ func executeMiddleware(next http.RoundTripper, datasourceType string, secureSock
140149
if res != nil && res.StatusCode != http.StatusSwitchingProtocols {
141150
res.Body = CountBytesReader(res.Body, func(bytesRead int64) {
142151
responseSizeHistogram.Observe(float64(bytesRead))
152+
responseSizeGauge.Set(float64(bytesRead))
143153
})
144154
}
145155

backend/httpclient/http_client.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ import (
1414
)
1515

1616
// New creates a new http.Client.
17-
// If opts is nil the http.DefaultClient will be returned.
1817
// If no middlewares are provided the DefaultMiddlewares will be used. If you
1918
// provide middlewares you have to manually add the DefaultMiddlewares for it to be
2019
// enabled.
2120
// Note: Middlewares will be executed in the same order as provided.
2221
// Note: If more than one Options is provided a panic is raised.
2322
func New(opts ...Options) (*http.Client, error) {
24-
if opts == nil {
25-
return http.DefaultClient, nil
26-
}
27-
2823
clientOpts := createOptions(opts...)
2924
transport, err := GetTransport(clientOpts)
3025
if err != nil {

backend/httpclient/http_client_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@ import (
1010
)
1111

1212
func TestNewClient(t *testing.T) {
13-
t.Run("New() without any opts should return http.DefaultClient", func(t *testing.T) {
13+
t.Run("New() without any opts should return expected http client and middlewares", func(t *testing.T) {
1414
client, err := New()
1515
require.NoError(t, err)
16-
require.Same(t, http.DefaultClient, client)
16+
require.NotNil(t, client)
17+
require.NotSame(t, http.DefaultClient, client)
18+
19+
require.Equal(t, 30*time.Second, client.Timeout)
20+
require.NotSame(t, &http.DefaultTransport, &client.Transport)
21+
})
22+
23+
t.Run("New() with opts and no middlewares specified should return expected http client and middlewares", func(t *testing.T) {
24+
client, err := New(Options{})
25+
require.NoError(t, err)
26+
require.NotNil(t, client)
27+
require.NotSame(t, http.DefaultClient, client)
28+
29+
require.Equal(t, 30*time.Second, client.Timeout)
30+
require.NotSame(t, &http.DefaultTransport, &client.Transport)
1731
})
1832

19-
t.Run("New() with opts and no middleware should return expected http client and transport", func(t *testing.T) {
33+
t.Run("New() with opts and empty middlewares should return expected http client and transport", func(t *testing.T) {
2034
client, err := New(Options{
2135
Timeouts: &TimeoutOptions{
2236
Timeout: time.Second,
@@ -35,6 +49,7 @@ func TestNewClient(t *testing.T) {
3549
require.NotNil(t, client)
3650
require.Equal(t, time.Second, client.Timeout)
3751

52+
// this only works when there are no middlewares, otherwise the transport is wrapped
3853
transport, ok := client.Transport.(*http.Transport)
3954
require.True(t, ok)
4055
require.NotNil(t, transport)

data/sqlutil/scanrow.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ import (
88
"github.com/grafana/grafana-plugin-sdk-go/backend"
99
)
1010

11+
// ErrColumnTypeNotSupported is returned when an SQL column has a type that cannot be processed.
12+
// This typically occurs when a database driver doesn't provide a valid scan type for a column
13+
// or when encountering custom/exotic data types that don't have appropriate conversion handlers.
14+
type ErrColumnTypeNotSupported struct {
15+
Type string
16+
Column string
17+
}
18+
19+
func (e ErrColumnTypeNotSupported) Error() string {
20+
return fmt.Sprintf("type %q is not supported (column %q)", e.Type, e.Column)
21+
}
22+
1123
// A ScanRow is a container for SQL metadata for a single row.
1224
// The row metadata is used to generate dataframe fields and a slice that can be used with sql.Scan
1325
type ScanRow struct {
@@ -87,7 +99,7 @@ func MakeScanRow(colTypes []*sql.ColumnType, colNames []string, converters ...Co
8799
if !rc.hasConverter(i) {
88100
scanTypeValue := colType.ScanType()
89101
if scanTypeValue == nil {
90-
return nil, fmt.Errorf(`type %s is not supported for column %s`, colType.DatabaseTypeName(), colName)
102+
return nil, ErrColumnTypeNotSupported{Type: colType.DatabaseTypeName(), Column: colName}
91103
}
92104
v := NewDefaultConverter(colName, nullable, scanTypeValue)
93105
rc.append(colName, scanType(v, colType.ScanType()), v)

0 commit comments

Comments
 (0)