1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
Commit Graph

920 Commits

Author SHA1 Message Date
Jaanus Sellin
59bdfcd84b
feat: first revision of delta api (#8967)
This is not changing existing logic.
We are creating a new endpoint, which is guarded behind a flag.

---------

Co-authored-by: Simon Hornby <liquidwicked64@gmail.com>
Co-authored-by: FredrikOseberg <fredrik.no@gmail.com>
2024-12-12 14:18:11 +02:00
Gastón Fournier
04eaf8d5bd
feat: add variant etag (#8922)
## About the changes
This adds a variant that allows us to control client refreshes in case
of need.
2024-12-05 15:13:11 +01:00
Jaanus Sellin
3c01813826
Revert "task: enabled in OSS." (#8892)
Reverts Unleash/unleash#8856
2024-11-29 13:42:10 +02:00
Christopher Kolstad
663b169c46
task: enabled in OSS. (#8856)
Hardcode project and environment names to filter by when OSS
2024-11-29 09:43:43 +01:00
Jaanus Sellin
4234020b8d
feat: backfill licensed users (#8791)
**This migration introduces a query that calculates the licensed user
counts and inserts them into the licensed_users table.**

**The logic ensures that:**

1. All users created up to a specific date are included as active users
until they are explicitly deleted.
2. Deleted users are excluded after their deletion date, except when
their deletion date falls within the last 30 days or before their
creation date.
3. The migration avoids duplicating data by ensuring records are only
inserted if they don’t already exist in the licensed_users table.


**Logic Breakdown:**

**Identify User Events (user_events):** Extracts email addresses from
user-related events (user-created and user-deleted) and tracks the type
and timestamp of the event. This step ensures the ability to
differentiate between user creation and deletion activities.
**Generate a Date Range (dates):** Creates a continuous range of dates
spanning from the earliest recorded event up to the current date. This
ensures we analyze every date, even those without events.
**Determine Active Users (active_emails):** Links dates with user events
to calculate the status of each email address (active or deleted) on a
given day. This step handles:

- The user's creation date.
- The user's deletion date (if applicable).

**Calculate Daily Active User Counts (result):** 
For each date, counts the distinct email addresses that are active based
on the conditions:

- The user has no deletion date.
- The user's deletion date is within the last 30 days relative to the
current date.
- The user's creation date is before the deletion date.
2024-11-20 09:10:07 +02:00
Tymoteusz Czech
7820ca62ad
feat: show max count of sessions that users have to an admin (#8781)
Add info about large number of parallel sessions per user.
2024-11-18 15:15:56 +00:00
Thomas Heartman
a55a956772
1-3120: remove project connected environments (#8775)
Remove everything related to the connected environment count for project
status. We decided that because we don't have anywhere to link it to at
the moment, we don't want to show it yet.
2024-11-18 12:01:25 +01:00
Mateusz Kwasniewski
4fabf49706
feat: show deleted user sessions (#8749) 2024-11-14 10:30:31 +01:00
Tymoteusz Czech
60fb647489
Count active browser sessions per user (#8736)
Show info on how many devices a user is logged in to an admin.
2024-11-13 15:49:25 +00:00
Mateusz Kwasniewski
bcbbd5c3e6
refactor: sessions for user without error (#8742) 2024-11-13 16:37:05 +01:00
Mateusz Kwasniewski
c6519cd95d
feat: delete stale user sessions (#8738) 2024-11-13 15:41:07 +01:00
Jaanus Sellin
c8bc40146a
feat: email will be stored hashed now for all users (#8720)
Adding email_hash column to users table.
We will update all existing users to have hashed email. 
All new users will also get the hash.

We are fine to use md5, because we just need uniqueness. We have emails
in events table stored anyways, so it is not sensitive.
2024-11-12 13:28:19 +02:00
Mateusz Kwasniewski
e039cdc85c
feat: count recently deleted users (#8688) 2024-11-07 11:57:47 +01:00
Thomas Heartman
c70c023143
refactor: introduce countProjectTokens method on ApiTokenStore (#8674)
This change introduces a new method `countProjectTokens` on the
`IApiTokenStore` interface. It also swaps out the manual filtering for
api tokens belonging to a project in the project status service.
2024-11-06 13:13:44 +00:00
Thomas Heartman
8a5771dd50
chore (1-3076): add remaining "project resources" to status payload (#8660)
This PR adds member, api token, and segment counts to the project status
payload. It updates the schemas and adds the necessary stores to get
this information. It also adds a new query to the segments store for
getting project segments.

I'll add tests in a follow-up.
2024-11-06 11:46:04 +00:00
Jaanus Sellin
d6e722b7b3
feat: activity chart polish (#8665)
![image](https://github.com/user-attachments/assets/a97f5745-1300-473e-80af-54f0cfc985e1)
2024-11-06 12:00:42 +02:00
Thomas Heartman
1897f8a19d
chore: add connected environments to project status payload (#8645)
This PR adds connected environments to the project status payload.

It's done by:
- adding a new `getConnectedEnvironmentCountForProject` method to the
project store (I opted for this approach instead of creating a new view
model because it already has a `getEnvironmentsForProject` method)
- adding the project store to the project status service
- updating the schema

For the schema, I opted for adding a `resources` property, under which I
put `connectedEnvironments`. My thinking was that if we want to add the
rest of the project resources (that go in the resources widget), it'd
make sense to group those together inside an object. However, I'd also
be happy to place the property on the top level. If you have opinions
one way or the other, let me know.

As for the count, we're currently only counting environments that have
metrics and that are active for the current project.
2024-11-05 11:12:08 +01:00
Tymoteusz Czech
2bd2d74f83
feat: User subscriptions store and service (#8648)
Co-authored-by: kwasniew <kwasniewski.mateusz@gmail.com>
2024-11-05 10:14:47 +01:00
Jaanus Sellin
0ce49c789e
feat: now backend returns event counts for activity chart (#8638) 2024-11-04 14:29:10 +02:00
Thomas Heartman
b276d5a89c
fix: correctly filter for to dates (#8567)
This change fixes a bug in the event filter's `to` query parameter.

The problem was that in an attempt to make it inclusive, we also
stripped it of the `IS:` prefix, which meant it had no effect. This
change fixes that by first splitting the value, fixing only the
date (because we want it to include the entire day), and then joining
it back together.
2024-10-29 09:42:15 +01:00
gitar-bot[bot]
0ff0b2dbd0
[Gitar] Cleaning up stale flag: onboardingMetrics with value true (#8550) 2024-10-28 11:47:58 +01:00
Gastón Fournier
15f55c7662
chore: Prometheus metrics refactor (#8484)
Migrate some prometheus metrics to use the new and sequential metric
updater
2024-10-22 15:11:57 +02:00
Gastón Fournier
a9f9be1efa
chore: add a class to handle aggreggation queries (#8446)
## About the changes
We have many aggregation queries that run on a schedule:
f63496d47f/src/lib/metrics.ts (L714-L719)

These staticCounters are usually doing db query aggregations that
traverse tables and we run all of them in parallel:
f63496d47f/src/lib/metrics.ts (L410-L412)

This can add strain to the db. This PR suggests a way of handling these
queries in a more structured way, allowing us to run them sequentially
(therefore spreading the load):
f02fe87835/src/lib/metrics-gauge.ts (L38-L40)

As an additional benefit, we get both the gauge definition and the
queries in a single place:
f02fe87835/src/lib/metrics.ts (L131-L141)

This PR only tackles 1 metric, and it only focuses on gauges to gather
initial feedback. The plan is to migrate these metrics and eventually
incorporate more types (e.g. counters)

---------

Co-authored-by: Nuno Góis <github@nunogois.com>
2024-10-18 11:11:22 +02:00
Thomas Heartman
96d8dc353a
feat: return project roles (#8314)
This PR updates the personal dashboard project endpoint to return owners
and roles. It also adds the impl for getting roles (via the access
store).

I'm filtering the roles for a project to only include project roles for
now, but we might wanna change this later.

Tests and UI update will follow.
2024-10-01 09:13:59 +00:00
Thomas Heartman
a4ea46dab6
feat: add Unleash admins to API payload (#8299)
Adds Unleash admins to the personal dashboard payload.

Uses the access store (and a new method) to fetch admins and maps it to
a new `MinimalUser` type. We already have a `User` class, but it
contains a lot of information we don't care about here, such as `isAPI`,
SCIM data etc.

In the UI, admins will be shown to users who are not part of any
projects. This is the default state for new viewer users, and can also
happen for editors if you archive the default project, for instance.

Tests in a follow-up PR
2024-09-30 11:01:30 +00:00
Mateusz Kwasniewski
823f6330b7
refactor: move getProjectsByUser to read model (#8262) 2024-09-26 09:45:02 +02:00
gitar-bot[bot]
338b5ce853
[Gitar] Cleaning up stale flag: useProjectReadModel with value true (#8211)
Co-authored-by: Gitar <noreply@gitar.co>
Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com>
2024-09-23 13:20:42 +02:00
Jaanus Sellin
037651c35f
feat: start returning onboarding status with project overview (#8058)
To show/hide onboarding flow, we need to get extra info about onboarding
status. This PR adds it to project overview.
2024-09-03 14:41:47 +03:00
Mateusz Kwasniewski
f27e07ab88
feat: onboarding store (#8027) 2024-09-02 08:53:23 +02:00
Mateusz Kwasniewski
2a35976081
feat: user loging event emitting with login order (#8021) 2024-08-30 11:28:19 +02:00
Jaanus Sellin
e61f016c8c
feat: start collecting prometheus metrics for onboarding events (#8012)
We start collecting prometheus metrics for onboarding events.

Co-authored-by: @kwasniew
2024-08-29 12:46:23 +03:00
Thomas Heartman
b0541a0af2
feat: add remaining resource usage to instance stats (#7958)
Updates the instance stats endpoint with 
- maxEnvironmentStrategies
- maxConstraints
- maxConstraintValues

It adds the following rows to the front end table:
- segments (already in the payload, just not used for the table before)
- API tokens (separate rows for type, + one for total) (also existed
before, but wasn't listed)
- Highest number of strategies used for a single flag in a single
environment
- Highest number of constraints used on a single strategy
- Highest number of values used for a single constraint


![image](https://github.com/user-attachments/assets/57798f8e-c466-4590-820b-15afd3729243)
2024-08-22 13:09:26 +02:00
Thomas Heartman
e5cca661d9
fix: serialize API token data correctly in instance stats (#7953)
Turns out we've been trying to return API token data in instance stats
for a while, but that the serialization has failed. Serializing a JS map
just yields an empty object.

This PR fixes that serialization and also adds API tokens to the
instance stats schema (it wasn't before, but we did return it). Adding
it to the schema is also part of making resource usage visible as part
of the soft limits project.
2024-08-22 10:29:05 +02:00
Jaanus Sellin
ead195923c
fix: fixing flaky test, because order for distinct may be random (#7954) 2024-08-21 15:42:23 +03:00
Jaanus Sellin
df73c65073
feat: filter projectless events for normal users (#7914)
Now events that do not have project ( for example user creation, segment
creation etc), will not be displayed to non root admins.
2024-08-21 13:59:24 +03:00
Thomas Heartman
79c3f8e975
refactor: switch projectStore.getProjects with projectReadModel.getProjectsForAdminUi in project service (#7904)
Hooks up the new project read model and updates the existing project
service to use it instead when the flag is on.

In doing:
- creates a composition root for the read model
- includes it in IUnleashStores
- updates some existing methods to accept either the old or the new
model
- updates the OpenAPI schema to deprecate the old properties
2024-08-19 08:46:50 +02:00
Thomas Heartman
0847a395dc
chore: Extract project read model (#7887)
Creates a new project read model exposing data to be used for the UI and
for the insights module.

The model contains two public methods, both based on the project store's
`getProjectsWithCounts`:
- `getProjectsForAdminUi`
- `getProjectsForInsights`

This mirrors the two places where the base query is actually in use
today and adapts the query to those two explicit cases.

The new `getProjectsForAdminUi` method also contains data for last flag
update and last flag metric reported, as required for the new projects
list screen.

Additionally the read model contains a private `getMembersCount` method,
which is also lifted from the project store. This method was only used
in the old `getProjectsWithCounts` method, so I have also removed the
method from the public interface.

This PR does *not* hook up the new read model to anything or delete any
existing uses of the old method.

## Why?

As mentioned in the background, this query is used in two places, both
to get data for the UI (directly or indirectly). This is consistent with
the principles laid out in our [ADR on read vs write
models](https://docs.getunleash.io/contributing/ADRs/back-end/write-model-vs-read-models).

There is an argument to be made, however, that the insights module uses
this as an **internal** read model, but the description of an internal
model ("Internal read models are typically narrowly focused on answering
one question and usually require simple queries compared to external
read models") does not apply here. It's closer to the description of
external read models: "View model will typically join data across a few
DB tables" for display in the UI.

## Discussion points

### What about properties on the schema that are now gone?

The `project-schema`, which is delivered to the UI through the
`getProjects` endpoint (and nowhere else, it seems), describes
properties that will no longer be sent to the front end, including
`defaultStickiness`, `avgTimeToProduction`, and more. Can we just stop
sending them or is that a breaking change?

The schema does not define them as required properties, so in theory,
not sending them isn't breaking any contracts. We can deprecate the
properties and just not populate them anymore.

At least that's my thought on it. I'm open to hearing other views.

### Can we add the properties in fewer lines of code? 

Yes! The [first commit in this PR
(b7534bfa)](b7534bfa07)
adds the two new properties in 8 lines of code.

However, this comes at the cost of diluting the `getProjectsWithCounts`
method further by adding more properties that are not used by the
insights module. That said, that might be a worthwhile tradeoff.

## Background

_(More [details in internal slack
thread](https://unleash-internal.slack.com/archives/C046LV6HH6W/p1723716675436829))_

I noticed that the project store's `getProjectWithCounts` is used in
exactly two places:

1. In the project service method which maps directly to the project
controller (in both OSS and enterprise).
2.  In the insights service in enterprise.

In the case of the controller, that’s the termination point. I’d guess
that when written, the store only served the purpose of showing data to
the UI.

In the event of the insights service, the data is mapped in
getProjectStats.
But I was a little surprised that they were sharing the same query, so I
decided to dig a little deeper to see what we’re actually using and what
we’re not (including the potential new columns). Here’s what I found.

Of the 14 already existing properties, insights use only 7 and the
project list UI uses only 10 (though the schema mentions all 14 (as far
as I could tell from scouring the code base)). Additionally, there’s two
properties that I couldn’t find any evidence of being used by either:
-   default stickiness
-   updatedAt (this is when the project was last updated; not its flags)
2024-08-16 10:52:57 +02:00
Jaanus Sellin
627768b96c
feat: start using event service composition root (#7871)
During adding privateProjectsChecker, I saw that events composition root
is not used almost at all.
Refactored code so we do not call new EventService anymore.
2024-08-15 08:33:46 +03:00
Simon Hornby
f276728688
feat: allow editing root role/description on SCIM group (#7874) 2024-08-14 15:11:56 +02:00
Nuno Góis
585eb30730
chore: initial admin email (#7795)
https://linear.app/unleash/issue/2-2518/figure-out-how-to-create-the-initial-admin-user-in-unleash

The logic around `initAdminUser` that was introduced in
https://github.com/Unleash/unleash/pull/4927 confused me a bit. I wrote
new tests with what I assume are our expectations for this feature and
refactored the code accordingly, but would like someone to confirm that
it makes sense to them as well.

The logic was split into 2 different methods: one to get the initial
invite link, and another to send a welcome email. Now these two methods
are more granular than the previous alternative and can be used
independently of creating a new user.

---------

Co-authored-by: Gastón Fournier <gaston@getunleash.io>
2024-08-14 10:05:11 +02:00
Mateusz Kwasniewski
4738d4a61f
feat: query archived projects (#7862) 2024-08-13 15:33:31 +02:00
gitar-bot[bot]
caac8f3fcb
[Gitar] Cleaning up stale flag: parseProjectFromSession with value true (#7854)
[![Gitar](https://raw.githubusercontent.com/gitarcode/.github/main/assets/gitar-banner.svg)](https://gitar.co)
  
  ---
This automated PR was generated by [Gitar](https://gitar.co). View
[docs](https://gitar.co/docs).

Co-authored-by: Gitar <noreply@gitar.co>
2024-08-13 14:15:59 +03:00
Mateusz Kwasniewski
bb30032f2e
feat: revive project (#7847) 2024-08-13 10:25:42 +02:00
Mateusz Kwasniewski
fcf1329816
feat: exclude archived projects from insights and project stats (#7843) 2024-08-13 10:00:04 +02:00
Thomas Heartman
0934c6ccd8
fix: search events by user ID, not by user name (#7846)
Changes the event search handling, so that searching by user uses the
user's ID, not the "createdBy" name in the event. This aligns better
with what the OpenAPI schema describes it.
2024-08-13 09:32:51 +02:00
Jaanus Sellin
3fbb64511a
fix: event creators, distinct on two users with same id (#7824)
Previously distinct was not working properly, because we were joining
users table.
You needed to do distinctOn. Now fixed.
2024-08-09 14:32:55 +03:00
Jaanus Sellin
2f92dac14e
feat: event creators (#7809)
Adds an endpoint to return all event creators.

An interesting point is that it does not return the user object, but
just created_by as a string. This is because we do not store user IDs
for events, as they are not strictly bound to a user object, but rather
a historical user with the name X.
2024-08-09 10:32:31 +03:00
Mateusz Kwasniewski
bde81b940c
feat: prevent adding flags to archived project (#7811) 2024-08-09 09:00:19 +02:00
Mateusz Kwasniewski
fffed5d8dc
feat: filter out archived projects from the main project list (#7803) 2024-08-08 13:22:44 +02:00
Mateusz Kwasniewski
0450bfe6f9
feat: archive project service (#7794) 2024-08-07 12:09:00 +02:00