1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
Commit Graph

888 Commits

Author SHA1 Message Date
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
Simon Hornby
a507ca91a5
chore: remove scim api flag (#7780) 2024-08-07 09:19:42 +02:00
Thomas Heartman
440d6b48db
feat: make to date inclusive (#7775)
Changes the handling of the `to` query parameter in
the API to be inclusive.
2024-08-06 13:40:07 +00:00
Thomas Heartman
76bc7bf250
refactor: rename createdAtFrom/To to from/to (#7773)
Update the query parameter of the new event search API to match the
query parameters of the insights API
2024-08-06 15:02:44 +02:00
Jaanus Sellin
0118f88964
fix: feature type is now validated (#7769)
Previously people were able to send random data to feature type. Now it
is validated.

Fixes https://github.com/Unleash/unleash/issues/7751

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.io>
2024-08-06 12:27:20 +03:00
Jaanus Sellin
1a97515adf
feat: event search e2e tests (#7755)
This covers the e2e cases for event search.
2024-08-05 15:02:35 +03:00
Jaanus Sellin
57a8b9da79
feat: event search on new endpoint, first test (#7739)
Changed the url of event search to search/events to align with
search/features. With that created a search controller to keep all
searches under there.
Added first test.
2024-08-02 15:07:21 +03:00
Jaanus Sellin
bcb7a803d0
feat: new event search (#7708)
This introduces the new event search API, with paging.
2024-08-02 10:56:42 +03:00
Tymoteusz Czech
d1e70eefbe
feat: Remove orphaned tokens flags (#7714)
Cleanup of `allowOrphanedWildcardTokens` and `cleanApiTokenWhenOrphaned`
2024-08-01 13:31:52 +02:00
Mateusz Kwasniewski
987ba5ea0a
chore: composition root playground service (#7710) 2024-07-31 14:44:57 +02:00
Jaanus Sellin
1e3c690185
feat: tag feature on creation (#7664)
Now it is possible to tag feature on creation.
2024-07-25 13:36:28 +03:00
Mateusz Kwasniewski
c3a00c07e1
feat: feature collaborators read model (#7625) 2024-07-19 12:10:21 +02:00
Nuno Góis
0869e39603
chore: register integration events in webhooks (#7621)
https://linear.app/unleash/issue/2-2450/register-integration-events-webhook

Registers integration events in the **Webhook** integration.

Even though this touches a lot of files, most of it is preparation for
the next steps. The only actual implementation of registering
integration events is in the **Webhook** integration. The rest will
follow on separate PRs.

Here's an example of how this looks like in the database table:

```json
{
  "id": 7,
  "integration_id": 2,
  "created_at": "2024-07-18T18:11:11.376348+01:00",
  "state": "failed",
  "state_details": "Webhook request failed with status code: ECONNREFUSED",
  "event": {
    "id": 130,
    "data": null,
    "tags": [],
    "type": "feature-environment-enabled",
    "preData": null,
    "project": "default",
    "createdAt": "2024-07-18T17:11:10.821Z",
    "createdBy": "admin",
    "environment": "development",
    "featureName": "test",
    "createdByUserId": 1
  },
  "details": {
    "url": "http://localhost:1337",
    "body": "{ \"id\": 130, \"type\": \"feature-environment-enabled\", \"createdBy\": \"admin\", \"createdAt\": \"2024-07-18T17: 11: 10.821Z\", \"createdByUserId\": 1, \"data\": null, \"preData\": null, \"tags\": [], \"featureName\": \"test\", \"project\": \"default\", \"environment\": \"development\" }"
  }
}
```
2024-07-19 10:07:52 +01:00
Nuno Góis
0ae6af13e9
chore: integration events store (#7613)
https://linear.app/unleash/issue/2-2437/create-new-integration-event-store

Adds a new `IntegrationEventsStore`.
2024-07-18 15:20:35 +01:00
Tymoteusz Czech
b9c3d101ba
feat: statistics for orphaned tokens (#7568)
Added metrics for orphaned tokens and modified `createTokenRowReducer` to exclude tokens in v1 format.
2024-07-11 11:39:38 +02:00
Christopher Kolstad
f65afff6c1
feat: Disallow repeating last 5 passwords. (#7552)
We'll store hashes for the last 5 passwords, fetch them all for the user
wanting to change their password, and make sure the password does not
verify against any of the 5 stored hashes.

Includes some password-related UI/UX improvements and refactors. Also
some fixes related to reset password rate limiting (instead of an
unhandled exception), and token expiration on error.

---------

Co-authored-by: Nuno Góis <github@nunogois.com>
2024-07-09 16:18:35 +02:00
Tymoteusz Czech
225d8a91f1
API tokens scoped to deleted projects shouldn't give wildcard access (#7499)
If you have SDK tokens scoped to projects that are deleted, you should
not get access to any flags with those.

---------

Co-authored-by: David Leek <david@getunleash.io>
2024-07-08 09:52:10 +02:00
Christopher Kolstad
d8bb9f18de
fix: update addon counter to include new relic addon 2024-07-05 15:17:45 +02:00
Jaanus Sellin
08533d7224
chore: remove unused clone code (#7529)
Removing this code, because variants per env are GA and I did not find
any usage of it.
2024-07-03 15:08:19 +03:00
Thomas Heartman
6d913809ca
chore: extract api token service composition root; place it in /features (#7519)
This is a refactoring task, creating an ApiTokenService composition root
in /features.
2024-07-03 11:49:11 +02:00
Mateusz Kwasniewski
72615cc6d5
feat: segments limit (#7524) 2024-07-03 10:41:56 +02:00
Mateusz Kwasniewski
72de574012
feat: largest projects and features metric (#7459) 2024-06-26 16:09:08 +02:00
Mateusz Kwasniewski
6a9a2c687d
feat: stage count by project metric (#7441) 2024-06-25 09:54:26 +02:00
Mateusz Kwasniewski
0c79b36b74
feat: Max strategies metrics (#7392) 2024-06-14 09:20:43 +02:00
Mateusz Kwasniewski
3cc0dfe35a
fix: playground parent deps check (#7384) 2024-06-13 10:36:44 +02:00
Jaanus Sellin
3acb3ad2c2
feat: upgrade from react v17 to v18 (#7265)
**Upgrade to React v18 for Unleash v6. Here's why I think it's a good
time to do it:**
- Command Bar project: We've begun work on the command bar project, and
there's a fantastic library we want to use. However, it requires React
v18 support.
- Straightforward Upgrade: I took a look at the upgrade guide
https://react.dev/blog/2022/03/08/react-18-upgrade-guide and it seems
fairly straightforward. In fact, I was able to get React v18 running
with minimal changes in just 10 minutes!
- Dropping IE Support: React v18 no longer supports Internet Explorer
(IE), which is no longer supported by Microsoft as of June 15, 2022.
Upgrading to v18 in v6 would be a good way to align with this change.

TS updates:
* FC children has to be explicit:
https://stackoverflow.com/questions/71788254/react-18-typescript-children-fc
* forcing version 18 types in resolutions:
https://sentry.io/answers/type-is-not-assignable-to-type-reactnode/

Test updates:
* fixing SWR issue that we have always had but it manifests more in new
React (https://github.com/vercel/swr/issues/2373)

---------

Co-authored-by: kwasniew <kwasniewski.mateusz@gmail.com>
2024-06-11 13:59:52 +03:00
Thomas Heartman
eb39a212ce
chore: test that the tags API still returns tags that you can't create anymore (#7304)
This change adds a test to the tags API to ensure that even if you
can't create tags that are pure whitespace anymore, you'll still
receive pre-existing tags from the API that fit this description.

The test is here to ensure that we don't break this in future versions
of Unleash.
2024-06-06 14:16:45 +02:00
Mateusz Kwasniewski
3c3e888ff0
feat: project flag creators api (#7302) 2024-06-06 11:10:28 +02:00
Gastón Fournier
07ef4a114f
chore: sync user groups is a system action (#7214)
## About the changes
After an internal conversation, we concluded that syncExternalGroups is
an action that Unleash performs as a system, not something triggered by
the user. We keep the method and just write the event log that the
action was performed by the system user.
2024-05-30 11:47:30 +02:00
Jaanus Sellin
6c8b1d8904
fix: when finding median time to production, ignore 0s (#7200)
We have an issue that if you open up Insights, the Time to Production
chart was showing nothing because it was taking the median across all
projects. You might have many new or empty projects where the median was
0 (no data).

For example, the median from [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.7, 50.3, 140] was 0.

Now, we will remove the 0 values to have a more reasonable median.
2024-05-29 14:17:31 +03:00
Jaanus Sellin
ef9f09b58c
feat: insights out of beta and expose 2 widgets to pro (#7177)
1. Remove beta badge
2. Remove exposure from oss
3. Expose 2 widgets to pro and rest to enterprise
2024-05-29 11:55:01 +03:00
David Leek
61a8908694
chore: remove state service (#7184)
## About the changes

Removes the deprecated state endpoint, state-service (despite the
service itself not having been marked as deprecated), and the file
import in server-impl. Leaves a TODO in place of where file import was
as traces for a replacement file import based on the new import/export
functionality
2024-05-28 14:47:31 +02:00
Gastón Fournier
e5aa1a81cb
feat: add remote ip to all events (2) (#7149)
## About the changes
This aligns us with the requirement of having ip in all events. After
tackling the enterprise part we will be able to make the ip field
mandatory here:
2c66a4ace4/src/lib/types/events.ts (L362)
2024-05-27 11:58:32 +02:00