Skip to content

Commit

Permalink
fix: usage and analytics data duplicates the current day (#4529)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell authored Aug 21, 2024
1 parent 32be7c0 commit 910b3ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions api/app_analytics/influxdb_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def get_event_list_for_organisation(
results = InfluxDBWrapper.influx_query_manager(
filters=f'|> filter(fn:(r) => r._measurement == "api_call") \
|> filter(fn: (r) => r["organisation_id"] == "{organisation_id}")',
extra="|> aggregateWindow(every: 24h, fn: sum)",
extra='|> aggregateWindow(every: 24h, fn: sum, timeSrc: "_start")',
date_start=date_start,
date_stop=date_stop,
)
Expand Down Expand Up @@ -241,7 +241,7 @@ def get_multiple_event_list_for_organisation(
date_start=date_start,
date_stop=date_stop,
filters=build_filter_string(filters),
extra="|> aggregateWindow(every: 24h, fn: sum)",
extra='|> aggregateWindow(every: 24h, fn: sum, timeSrc: "_start")',
)
if not results:
return results
Expand Down Expand Up @@ -319,7 +319,7 @@ def get_multiple_event_list_for_feature(
|> filter(fn: (r) => r["_field"] == "request_count") \
|> filter(fn: (r) => r["environment_id"] == "{environment_id}") \
|> filter(fn: (r) => r["feature_id"] == "{feature_name}")',
extra=f'|> aggregateWindow(every: {aggregate_every}, fn: sum, createEmpty: false) \
extra=f'|> aggregateWindow(every: {aggregate_every}, fn: sum, createEmpty: false, timeSrc: "_start") \
|> yield(name: "sum")',
)
if not results:
Expand Down
4 changes: 2 additions & 2 deletions api/organisations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def remove_users(self, request, pk):

@swagger_auto_schema(
deprecated=True,
operation_description="Please use ​​/api/v1/organisations/{organisation_pk}/usage-data/total-count/",
operation_description="Please use /api/v1/organisations/{organisation_pk}/usage-data/total-count/",
)
@action(
detail=True,
Expand Down Expand Up @@ -221,7 +221,7 @@ def get_hosted_page_url_for_subscription_upgrade(self, request, pk):

@swagger_auto_schema(
deprecated=True,
operation_description="Please use ​​/api/v1/organisations/{organisation_pk}/usage-data/",
operation_description="Please use /api/v1/organisations/{organisation_pk}/usage-data/",
query_serializer=InfluxDataQuerySerializer(),
)
@action(detail=True, methods=["GET"], url_path="influx-data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_influx_db_query_when_get_events_list_then_query_api_called(monkeypatch)
f'|> filter(fn: (r) => r["organisation_id"] == "{org_id}") '
f'|> drop(columns: ["organisation", "organisation_id", "type", "project", '
f'"project_id", "environment", "environment_id", "host"])'
f"|> aggregateWindow(every: 24h, fn: sum)"
f'|> aggregateWindow(every: 24h, fn: sum, timeSrc: "_start")'
)
mock_influxdb_client = mock.MagicMock()
monkeypatch.setattr(
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_influx_db_query_when_get_multiple_events_for_organisation_then_query_ap
f"{build_filter_string(expected_filters)}"
'|> drop(columns: ["organisation", "organisation_id", "type", "project", '
'"project_id", "environment", "environment_id", "host"]) '
"|> aggregateWindow(every: 24h, fn: sum)"
'|> aggregateWindow(every: 24h, fn: sum, timeSrc: "_start")'
)
.replace(" ", "")
.replace("\n", "")
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_influx_db_query_when_get_multiple_events_for_feature_then_query_api_cal
f'|> filter(fn: (r) => r["feature_id"] == "{feature_name}") '
'|> drop(columns: ["organisation", "organisation_id", "type", "project", '
'"project_id", "environment", "environment_id", "host"])'
"|> aggregateWindow(every: 24h, fn: sum, createEmpty: false) "
'|> aggregateWindow(every: 24h, fn: sum, createEmpty: false, timeSrc: "_start") '
'|> yield(name: "sum")'
)

Expand Down

0 comments on commit 910b3ed

Please sign in to comment.