From 1880993f0b275ccdccefeae57e49d7b0687714c2 Mon Sep 17 00:00:00 2001 From: IM CHAECHEOL Date: Tue, 27 Aug 2024 00:11:47 +0900 Subject: [PATCH] Fix/grafana review (#118) * Change log level * Rollback timeSeries to time seires and add 0.2.3 migration test * Fix workflow --- .github/workflows/playwright.yml | 6 +- docker-compose.yaml | 1 + pkg/gav4/analytics.go | 8 +- pkg/gav4/client.go | 12 +- pkg/model/models.go | 2 +- provisioning/dashboards/default.json | 2 +- provisioning/dashboards/v0.2.3.json | 158 +++++++++++++++++++++++++++ src/QueryEditorGA4.tsx | 6 +- tests/query/queryEdiyor.spec.ts | 10 ++ 9 files changed, 187 insertions(+), 18 deletions(-) create mode 100644 provisioning/dashboards/v0.2.3.json diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index f2bcc03..2c5a872 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -43,7 +43,7 @@ jobs: uses: actions/setup-go@v4 with: go-version: 1.22 - + - name: Install Mage uses: magefile/mage-action@v3 with: @@ -63,8 +63,8 @@ jobs: - name: Start Grafana run: | - docker-compose pull - GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} docker-compose up -d + docker compose pull + GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} docker compose up -d - name: Wait for Grafana to start uses: nev7n/wait_for_response@v1 diff --git a/docker-compose.yaml b/docker-compose.yaml index bb8eae7..d30ca7a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -18,6 +18,7 @@ services: cap_add: - SYS_PTRACE volumes: + # - ~/.grafana:/var/lib/grafana - ./dist:/var/lib/grafana/plugins/blackcowmoo-googleanalytics-datasource - ./provisioning:/etc/grafana/provisioning - .:/root/blackcowmoo-googleanalytics-datasource diff --git a/pkg/gav4/analytics.go b/pkg/gav4/analytics.go index 19c0811..fb1949b 100644 --- a/pkg/gav4/analytics.go +++ b/pkg/gav4/analytics.go @@ -43,7 +43,7 @@ func (ga *GoogleAnalytics) Query(ctx context.Context, config *setting.Datasource return nil, fmt.Errorf("required dimensions or metrics") } - if queryModel.Mode == "time series" && len(queryModel.TimeDimension) == 0 { + if queryModel.Mode == model.TIME_SERIES && len(queryModel.TimeDimension) == 0 { log.DefaultLogger.Error("Query", "error", "TimeSeries query need TimeDimension") return nil, fmt.Errorf("time series query need time dimensions") } @@ -84,7 +84,7 @@ func (ga *GoogleAnalytics) getReport(ctx context.Context, client *GoogleClient, return nil, err } default: - return nil, fmt.Errorf("unknown query mode") + return nil, fmt.Errorf("unknown query mode [%s]", queryModel.Mode) } return report, nil } @@ -216,10 +216,10 @@ func (ga *GoogleAnalytics) CheckHealth(ctx context.Context, config *setting.Data client, err := NewGoogleClient(ctx, config.JWT) if err != nil { - log.DefaultLogger.Error("CheckHealth: Fail NewGoogleClient", "error", config.JWT) + log.DefaultLogger.Error("CheckHealth: Fail NewGoogleClient", "error", err) return &backend.CheckHealthResult{ Status: backend.HealthStatusError, - Message: "CheckHealth: Fail NewGoogleClient" + err.Error() + "json:" + config.JWT, + Message: "CheckHealth: Fail NewGoogleClient" + err.Error(), }, nil } diff --git a/pkg/gav4/client.go b/pkg/gav4/client.go index 6ca106d..1deaa7b 100644 --- a/pkg/gav4/client.go +++ b/pkg/gav4/client.go @@ -136,8 +136,8 @@ func (client *GoogleClient) getRealtimeReport(query model.QueryModel) (*analytic end := time.Since(query.To) start := time.Since(query.From) - log.DefaultLogger.Info("getRealtimeReport", "start", start.Minutes()) - log.DefaultLogger.Info("getRealtimeReport", "end", end.Minutes()) + log.DefaultLogger.Debug("getRealtimeReport", "start", start.Minutes()) + log.DefaultLogger.Debug("getRealtimeReport", "end", end.Minutes()) var ( min = GaRealTimeMinMinute @@ -156,11 +156,11 @@ func (client *GoogleClient) getRealtimeReport(query model.QueryModel) (*analytic start = max } - log.DefaultLogger.Info("getRealtimeReport", "after start", start.Minutes()) - log.DefaultLogger.Info("getRealtimeReport", "after end", end.Minutes()) + log.DefaultLogger.Debug("getRealtimeReport", "after start", start.Minutes()) + log.DefaultLogger.Debug("getRealtimeReport", "after end", end.Minutes()) - log.DefaultLogger.Info("getRealtimeReport", "real start", int64(start.Minutes())) - log.DefaultLogger.Info("getRealtimeReport", "real end", int64(end.Minutes())) + log.DefaultLogger.Debug("getRealtimeReport", "real start", int64(start.Minutes())) + log.DefaultLogger.Debug("getRealtimeReport", "real end", int64(end.Minutes())) req := analyticsdata.RunRealtimeReportRequest{ Metrics: Metrics, Dimensions: Dimensions, diff --git a/pkg/model/models.go b/pkg/model/models.go index f54903d..9244e28 100644 --- a/pkg/model/models.go +++ b/pkg/model/models.go @@ -111,7 +111,7 @@ type ProfileSummary struct { type QueryMode string const ( - TIME_SERIES QueryMode = "timeSeries" + TIME_SERIES QueryMode = "time series" TABLE QueryMode = "table" REALTIME QueryMode = "realtime" ) diff --git a/provisioning/dashboards/default.json b/provisioning/dashboards/default.json index 3414d0c..f4f9a07 100644 --- a/provisioning/dashboards/default.json +++ b/provisioning/dashboards/default.json @@ -115,7 +115,7 @@ "metrics": [ "activeUsers" ], - "mode": "timeSeries", + "mode": "time series", "refId": "A", "selectedDimensions": [ { diff --git a/provisioning/dashboards/v0.2.3.json b/provisioning/dashboards/v0.2.3.json new file mode 100644 index 0000000..e2d7bbb --- /dev/null +++ b/provisioning/dashboards/v0.2.3.json @@ -0,0 +1,158 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 38, + "links": [], + "panels": [ + { + "datasource": { + "type": "blackcowmoo-googleanalytics-datasource", + "uid": "lcc3108_test" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.3.0-74991", + "targets": [ + { + "accountId": "accounts/145710468", + "cacheDurationSeconds": 300, + "datasource": { + "type": "blackcowmoo-googleanalytics-datasource", + "uid": "e7bdc464-a204-4e54-b865-9d712e112c66" + }, + "dimensionFilter": {}, + "displayName": {}, + "metrics": [ + "activeUsers" + ], + "mode": "time series", + "refId": "A", + "selectedMetrics": [ + { + "description": "The number of distinct users who visited your site or app.", + "label": "Active users", + "value": "activeUsers" + } + ], + "selectedTimeDimensions": { + "description": "The date of the event, formatted as YYYYMMDD.", + "label": "Date", + "value": "date" + }, + "timeDimension": "date", + "timezone": "Asia/Seoul", + "version": "v4", + "webPropertyId": "properties/323466308" + } + ], + "title": "Panel Title", + "type": "timeseries" + } + ], + "preload": false, + "refresh": "", + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-30d", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "0.2.3", + "uid": "b8503369-1580-4f6d-972f-0718f0f14fa6", + "version": 5, + "weekStart": "" +} diff --git a/src/QueryEditorGA4.tsx b/src/QueryEditorGA4.tsx index 93f9d88..9456b87 100644 --- a/src/QueryEditorGA4.tsx +++ b/src/QueryEditorGA4.tsx @@ -25,7 +25,7 @@ const gaVersionBadge = { }, } as const; const queryMode = [ - { label: 'Time Series', value: 'timeSeries' }, + { label: 'Time Series', value: 'time series' }, { label: 'Table', value: 'table' }, { label: 'Realtime', value: 'realtime' }, ] as Array>; @@ -62,8 +62,8 @@ export class QueryEditorGA4 extends PureComponent { this.options = accountSummaries; this.props.onChange(this.props.query); }); - if (query.mode === undefined || query.mode === '' || query.mode === 'time series') { - query.mode = 'timeSeries'; + if (query.mode === undefined || query.mode === '') { + query.mode = 'time series'; } if (query.dimensionFilter === undefined) { query.dimensionFilter = {}; diff --git a/tests/query/queryEdiyor.spec.ts b/tests/query/queryEdiyor.spec.ts index 7b86aee..5933bb7 100644 --- a/tests/query/queryEdiyor.spec.ts +++ b/tests/query/queryEdiyor.spec.ts @@ -1,5 +1,15 @@ import { expect, test } from '@grafana/plugin-e2e'; + + +test('0_2_3 migration test', async ({ readProvisionedDataSource, readProvisionedDashboard, gotoDashboardPage }) => { + // default settings + const dashboard = await readProvisionedDashboard({fileName: 'v0.2.3.json'}) + const dashboardPage = await gotoDashboardPage({uid: dashboard.uid}); + await dashboardPage.refreshDashboard() + await expect(dashboardPage.waitForQueryDataResponse()).toBeOK() +}); + test('time series', async ({ readProvisionedDataSource, explorePage, page }) => { // default settings const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' });