Skip to content

Commit

Permalink
feat(sse/tracking): Add project and org name to the influx event (#3337)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi authored Jan 29, 2024
1 parent 84d912d commit 351232f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
40 changes: 20 additions & 20 deletions api/sse/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,30 @@ def update_sse_usage():
) as write_api:
environments = Environment.objects.filter(
api_key__in=agg_request_count.keys()
).values("api_key", "id", "project_id", "project__organisation_id")
).values(
"api_key",
"id",
"project_id",
"project__name",
"project__organisation_id",
"project__organisation__name",
)

for environment in environments:
record = _get_influx_point(
environment["id"],
environment["project_id"],
environment["project__organisation_id"],
agg_request_count[environment["api_key"]],
agg_last_event_generated_at[environment["api_key"]],
time = agg_last_event_generated_at[environment["api_key"]]
count = agg_request_count[environment["api_key"]]
record = (
Point("sse_call")
.field("request_count", count)
.tag("environment_id", environment["id"])
.tag("project_id", environment["project_id"])
.tag("project", environment["project__name"])
.tag("organisation_id", environment["project__organisation_id"])
.tag("organisation", environment["project__organisation__name"])
.time(time)
)
write_api.write(bucket=settings.INFLUXDB_BUCKET, record=record)


def _get_influx_point(
environment_id: int, project_id: int, organisation_id: int, count: int, time: str
) -> Point:
return (
Point("sse_call")
.field("request_count", count)
.tag("organisation_id", organisation_id)
.tag("project_id", project_id)
.tag("environment_id", environment_id)
.time(time)
)
write_api.write(bucket=settings.INFLUXDB_BUCKET, record=record)


def get_auth_header():
Expand Down
30 changes: 25 additions & 5 deletions api/tests/unit/sse/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,30 @@ def test_track_sse_usage(
[
call("sse_call"),
call().field("request_count", 2),
call().field().tag("organisation_id", environment.project.organisation_id),
call().field().tag().tag("project_id", environment.project_id),
call().field().tag().tag().tag("environment_id", environment.id),
call().field().tag().tag().tag().time(second_access_log.generated_at),
call().field().tag("environment_id", environment.id),
call().field().tag().tag("project_id", environment.project.id),
call().field().tag().tag().tag("project", environment.project.name),
call()
.field()
.tag()
.tag()
.tag()
.tag("organisation_id", environment.project.organisation.id),
call()
.field()
.tag()
.tag()
.tag()
.tag()
.tag("organisation", environment.project.organisation.name),
call()
.field()
.tag()
.tag()
.tag()
.tag()
.tag()
.time(second_access_log.generated_at),
]
)

Expand All @@ -136,5 +156,5 @@ def test_track_sse_usage(
assert write_method.call_count == 1
write_method.assert_called_once_with(
bucket=influxdb_bucket,
record=mocked_influx_point().field().tag().tag().tag().time(),
record=mocked_influx_point().field().tag().tag().tag().tag().tag().time(),
)

3 comments on commit 351232f

@vercel
Copy link

@vercel vercel bot commented on 351232f Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 351232f Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 351232f Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-flagsmith.vercel.app
docs.bullet-train.io
docs-git-main-flagsmith.vercel.app
docs.flagsmith.com

Please sign in to comment.