Skip to content

Commit

Permalink
Fix/grafana review (#118)
Browse files Browse the repository at this point in the history
* Change log level

* Rollback timeSeries to time seires and add 0.2.3 migration test

* Fix workflow
  • Loading branch information
lcc3108 authored Aug 26, 2024
1 parent 4597963 commit 1880993
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
uses: actions/setup-go@v4
with:
go-version: 1.22

- name: Install Mage
uses: magefile/mage-action@v3
with:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/gav4/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/gav4/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion provisioning/dashboards/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"metrics": [
"activeUsers"
],
"mode": "timeSeries",
"mode": "time series",
"refId": "A",
"selectedDimensions": [
{
Expand Down
158 changes: 158 additions & 0 deletions provisioning/dashboards/v0.2.3.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
6 changes: 3 additions & 3 deletions src/QueryEditorGA4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SelectableValue<string>>;
Expand Down Expand Up @@ -62,8 +62,8 @@ export class QueryEditorGA4 extends PureComponent<Props> {
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 = {};
Expand Down
10 changes: 10 additions & 0 deletions tests/query/queryEdiyor.spec.ts
Original file line number Diff line number Diff line change
@@ -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' });
Expand Down

0 comments on commit 1880993

Please sign in to comment.