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

1395 Commits

Author SHA1 Message Date
Thomas Heartman
9ac3d7511a
chore: use query to get strategies instead of whether a segment is in use (#5375)
This change is just a refactor, removing code that's no longer used. Instead of
checking just whether a segment is in use, we now extract the list of
strategies that use this segment. This is slightly more costly,
perhaps, but it will be necessary for the upcoming implementation.
2023-11-22 06:54:28 +00:00
Thomas Heartman
8337885e47
feat: return CR uses of segments when flag is active (#5378)
This PR changes the payload of the strategiesBySegment endpoint when the
flag is active. In addition to returning just the strategies, the object
will also contain a new property, called `changeRequestStrategies`
containing the strategies that are used in change requests.

This PR does not update the schema. That can be done later when the
changes go into beta. This also allows us some time to iterate on the
payload without changing the public API.

## Discussion points:

Should `strategies` and `changeRequestStrategies` ever contain
duplicates? Take this scenario:
- Strategy S uses segment T.
- There is an open change request that updates the list of segments for
S to T and a new segment U.
- In this case, strategy S would show up both in `strategies` _and_ in
`changeRequestStrategies`.

We have two options: 
1. Filter the list of change request strategies, so that they don't
contain any duplicates (this is currently how it's implemented)
2. Ignore the duplicates and just send both lists as is.

We're doing option 2 for now.
2023-11-22 07:51:04 +01:00
Gastón Fournier
7ddcceed8a
fix: remove user from project (#5383)
Removing a user from a project was impossible if you only had 1 owner.
It worked fine when having more than an owner. This should fix it and
we'll add tests later
2023-11-21 15:44:12 +01:00
Jaanus Sellin
1429b54957
feat: sorting by last seen, environments now working properly (#5376)
Now calculates final ranks also, if there are some ranks missing from
duplicates.
2023-11-21 15:19:06 +02:00
Jaanus Sellin
62dbf8d12f
fix: last seen is now using last seen values from new table (#5380)
In short the issue is that after our last seen improvements, we did not
update where we are getting last_seen field. It was still using features
table, which is not the source of last seen anymore.
2023-11-21 14:44:41 +02:00
Fredrik Strand Oseberg
fe4bb4f227
feat: scheduled functions observability (#5377)
See linear issue:
https://linear.app/unleash/issue/1-1656/add-scheduler-observability

As per post mortem actions, we are adding observability to scheduled
functions.

This PR adds prometheus observability to our scheduled functions via a
summary. In addition to timing these functions with the more accurate
process.hrtime, we are getting a counter for free per scheduled job id.

Prometheus example: 

<img width="731" alt="Skjermbilde 2023-11-21 kl 13 36 33"
src="https://github.com/Unleash/unleash/assets/16081982/08a2064d-5152-4b4f-8a08-eb06e726757a">
2023-11-21 13:42:38 +01:00
Thomas Heartman
f8db9098fc
Revert "Fix: add the right change"
This reverts commit 9dc64659b7.

Wasn't intended to push to main.
2023-11-21 12:54:45 +01:00
Thomas Heartman
9dc64659b7
Fix: add the right change 2023-11-21 12:53:35 +01:00
Nuno Góis
ae375703d2
fix: scheduler job runtime control (#5363)
## PR Description


https://linear.app/unleash/issue/2-1645/address-post-mortem-action-point-all-flags-should-be-runtime

Refactor with the goal of ensuring that flags are runtime controllable,
mostly focused on the current scheduler logic.

This includes the following changes:
 - Moves scheduler into its own "scheduler" feature folder
- Reverts dependency: SchedulerService takes in the MaintenanceService,
not the other way around
- Scheduler now evaluates maintenance mode at runtime instead of relying
only on its mode state (active / paused)
- Favors flag checks to happen inside the scheduled methods, instead of
controlling whether the method is scheduled at all (favor runtime over
startup)
 - Moves "account last seen update" to scheduler
 - Updates tests accordingly
 - Boyscouting

Here's a manual test showing this behavior, where my local instance was
controlled by a remote instance. Whenever I toggle `maintenanceMode`
through a flag remotely, my scheduled functions stop running:


https://github.com/Unleash/unleash/assets/14320932/ae0a7fa9-5165-4c0b-9b0b-53b9fb20de72


Had a look through all of our current flags and it *seems to me* that
they are all used in a runtime controllable way, but would still feel
more comfortable if this was double checked, since it can be complex to
ensure this.

The only exception to this was `migrationLock`, which I believe is OK,
since the migration only happens at the start anyways.

## Discussion / Questions

~~Scheduler `mode` (active / paused) is currently not *really* being
used, along with its respective methods, except in tests. I think this
could be a potential footgun. Should we remove it in favor of only
controlling the scheduler state through maintenance mode?~~ Addressed in
7c52e3f638

~~The config property `disableScheduler` is still a startup
configuration, but perhaps that makes sense to leave as is?~~
[Answered](https://github.com/Unleash/unleash/pull/5363#issuecomment-1819005445)
by @FredrikOseberg, leaving as is.

Are there any other tests we should add?

Is there anything I missed?

Identified some `setInterval` and `setTimeout` that may make sense to
leave as is instead of moving over to the scheduler service:
- ~~`src/lib/metrics` - This is currently considered a `MetricsMonitor`.
Should this be refactored to a service instead and adapt these
setIntervals to use the scheduler instead? Is there anything special
with this we need to take into account? @chriswk @ivarconr~~
[Answered](https://github.com/Unleash/unleash/pull/5363#issuecomment-1820501511)
by @ivarconr, leaving as is.
- ~~`src/lib/proxy/proxy-repository.ts` - This seems to have a complex
and specific logic currently. Perhaps we should leave it alone for now?
@FredrikOseberg~~
[Answered](https://github.com/Unleash/unleash/pull/5363#issuecomment-1819005445)
by @FredrikOseberg, leaving as is.
- `src/lib/services/user-service.ts` - This one also seems to be a bit
more specific, where we generate new timeouts for each receiver id.
Might not belong in the scheduler service. @Tymek
2023-11-21 10:06:38 +00:00
Thomas Heartman
27252f7728
chore: find segment strategies in CRs (#5365)
This PR adds the ability to detect which strategies use a specific
segment in active change requests.

It does not wire this functionality up to anything just yet. Follow-up
PRs will integrate this with the segment service and eventually with the
front end.
2023-11-21 10:29:43 +01:00
Jaanus Sellin
e79e30de96
fix: total number should be correct now in search (#5355)
The issue was that we all features were created exactly in same time,
and our feature counter waas expecting time to be unique to feature,
which was not the case.
2023-11-21 09:08:20 +01:00
Fredrik Strand Oseberg
11533bf97a
refactor: remove feature flag for Dora (#5367) 2023-11-21 08:18:00 +01:00
Thomas Heartman
0ba99a6162
fix: handle check against non existing projects (#5368)
Instead of throwing an error when the project doesn't exist, we say that
the names are valid, because we have nothing to say that they're not.
Presumably there is already something in place to prevent you from
importing into a non-existent project.
2023-11-20 16:02:41 +00:00
Thomas Heartman
90d6c7c0ba
chore: remove usage of feature naming pattern flag (#5364)
In preparation for this feature going GA
2023-11-20 12:42:24 +01:00
Gastón Fournier
9ef78a5a18
fix: Banners ga (#5361)
It looks like auto-merge is merging before all checks are green.... Fixing the snapshot from https://github.com/Unleash/unleash/pull/5348
2023-11-17 15:09:18 +01:00
Gastón Fournier
4801b64824
feat(banners): enable customer banners (#5348)
## About the changes
This feature allows our Enterprise customers to configure banners to be
displayed on their Unleash instance for all their users to see and
interact with. Previously known as "internal message banners".
2023-11-17 13:56:09 +00:00
Fredrik Strand Oseberg
fd453f5af7
fix: hardcoded stickiness and mode fields (#5342)
This PR fixes an issue where project overview would return hardcoded
project mode and stickiness fields.
2023-11-17 12:32:13 +01:00
Gastón Fournier
02da9b1d34
fix: handle concurrent service account updates (#5349) 2023-11-16 11:03:27 +00:00
Jaanus Sellin
f3df3a31bf
feat: fix paging in sql by using common table expressions (#5343)
Optimizations:

1. Removed extra round trip to database  to count environments
2. Removed extra round trip to database to count features

Fixes:

Currently, we were using a very optimistic query to set correct limit
and offset. This breaks as soon we we join tags.

` query = query
            .select(selectColumns)
            .limit(limit * environmentCount)
            .offset(offset * environmentCount);` 

The solution was to use common table expressions, so we could count and
rank features.
2023-11-16 10:34:44 +02:00
Jaanus Sellin
4e1040c849
feat: connect sort table to backend (#5338)
Now FE sorting is done in backend.
2023-11-15 16:01:02 +02:00
andreas-unleash
7281e8b2d3
fix: new SCHEDULED_CHANGE_REQUEST_EXECUTED on scheduled cr execution (#5330)
Rename event to SCHEDULED_CHANGE_REQUEST_EXECUTED

This event will be triggered when the executor runs a scheduled change
request.
The ChangeRequestApplied event will remain as is (going out to project
members - but will have a scheduled = true property in the data if it
scheduled.
This new event will fire on execution of the schedule and have a result
= "failed" | "succeeded" property.
Because notifications are tied to events, this notification will go out
to the creator and the applier

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
2023-11-14 14:58:48 +02:00
Tymoteusz Czech
fd3a7f12cb
chore: remove featureSwitchRefactor flag (#5329)
Cleanup. This change has been rolled out to significant number of
customers already, and we have another parallel version behind a flag.
2023-11-14 13:03:23 +01:00
Thomas Heartman
a115f89183
feat: include segment usage in CRs when showing usage in projects and flags (#5327)
This PR updates the segment usage counting to also include segment usage
in pending change requests.

The changes include:
- Updating the schema to explicitly call out that change request usage
is included.
- Adding two tests to verify the new features
- Writing an alternate query to count this data

Specifically, it'll update the part of the UI that tells you how many
places a segment is used:


![image](https://github.com/Unleash/unleash/assets/17786332/a77cf932-d735-4a13-ae43-a2840f7106cb)

## Implementation

Implementing this was a little tricky. Previously, we'd just count
distinct instances of feature names and project names on the
feature_strategy table. However, to merge this with change request data,
we can't just count existing usage and change request usage separately,
because that could cause duplicates.

Instead of turning this into a complex DB query, I've broken it up into
a few separate queries and done the merging in JS. I think that's more
readable and it was easier to reason about.

Here's the breakdown:
1. Get the list of pending change requests. We need their IDs and their
project.
2. Get the list of updateStrategy and addStrategy events that have
segment data.
3. Take the result from step 2 and turn it into a dictionary of segment
id to usage data.
4. Query the feature_strategy_segment and feature_strategies table, to
get existing segment usage data
5. Fold that data into the change request data.
6. Perform the preexisting segment query (without counting logic) to get
other segment data
7. Enrich the results of the query from step 2 with usage data.

## Discussion points

I feel like this could be done in a nicer way, so any ideas on how to
achieve that (whether that's as a db query or just breaking up the code
differently) is very welcome.

Second, using multiple queries obviously yields more overhead than just
a single one. However, I do not think this is in the hot path, so I
don't consider performance to be critical here, but I'm open to hearing
opposing thoughts on this of course.
2023-11-14 08:49:32 +01:00
Jaanus Sellin
5d762dcb39
feat: sort favorites on the backend (#5326)
Now favorites will be always on first page, if pinned.
2023-11-14 09:22:35 +02:00
Mateusz Kwasniewski
ce7644e0af
chore: log unerlying DB error in set user root role (#5324) 2023-11-13 12:16:01 +01:00
Jaanus Sellin
5782efa6c0
chore: move sort order validation closer to store due to possible SQL injection (#5322) 2023-11-13 12:43:12 +02:00
Jaanus Sellin
00327c359d
chore: optimize sql query to not concatenate (#5321) 2023-11-13 08:42:19 +02:00
Nuno Góis
15f77f5b8b
fix: project settings flag limit not properly set (#5317)
https://linear.app/unleash/issue/SR-169/ticket-1107-project-feature-flag-limit-is-not-correctly-updated

Fixes #5315, an issue where it would not be possible to set an empty
flag limit.
This also fixes the UI behavior: Before, when the flag limit field was
emptied, it would disappear from the UI.

I'm a bit unsure of the original intent of the `(data.defaultStickiness
!== undefined || data.featureLimit !== undefined)` condition. We're in
an update method, triggered by a PUT endpoint - I think it's safe to
assume that we'll always want to set these values to whatever they come
as, we just need to convert them to `null` in case they are not present
(i.e. `undefined`).
2023-11-10 09:57:20 +00:00
andreas-unleash
180c0dceae
Fix/scheduled request UI (#5318)
Change timezone format
Fixes a bug where the Edit button on hover being elongated

Before:
<img width="755" alt="Screenshot 2023-11-09 at 21 36 01"
src="https://github.com/Unleash/unleash/assets/104830839/189f21d5-8a68-4d6b-b094-b518749a9b2f">

After:
<img width="812" alt="Screenshot 2023-11-09 at 22 09 26"
src="https://github.com/Unleash/unleash/assets/104830839/9056f995-bd2b-4353-8526-77160e49e990">

Adds the missed onClick to the edit button to show the dialog

Fixes a bug with ScheduleChangesDialog onClose

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
2023-11-10 11:22:03 +02:00
Nuno Góis
de638b5b8e
fix: segment project fetch when global (#5311)
This fixes an edge case not caught originally in
https://github.com/Unleash/unleash/pull/5304 - When creating a new
segment on the global level:
 - There is no `projectId`, either in the params or body
- The `UPDATE_PROJECT_SEGMENT` is still a part of the permissions
checked on the endpoint
 - There is no `id` on the params

This made it so that we would run `segmentStore.get(id)` with an
undefined `id`, causing issues.

The fix was simply checking for the presence of `params.id` before
proceeding.
2023-11-09 13:27:12 +00:00
Thomas Heartman
ece5a634bf
feat: API prevents you from deleting segments in crs (#5308)
This PR hooks up the changes introduced in #5301 to the API and puts
them behind a feature flag. A new test has been added and the test setup
has been slightly tweaked to allow this test.

When the flag is enabled, the API will now not let you delete a segment
that's used in any active CRs.
2023-11-09 12:09:39 +01:00
Nuno Góis
4d1f76e61b
fix: take into account project segments permission (#5304)
https://linear.app/unleash/issue/SR-164/ticket-1106-user-with-createedit-project-segment-is-not-able-to-edit-a

Fixes a bug where the `UPDATE_PROJECT_SEGMENT` permission is not
respected, both on the UI and on the API. The original intention was
stated
[here](https://github.com/Unleash/unleash/pull/3346#discussion_r1140434517).

This was easy to fix on the UI, since we were simply missing the extra
permission on the button permission checks.

Unfortunately the API can be tricky. Our auth middleware tries to grab
the `project` information from either the params or body object, but our
`DELETE` method does not contain this information. There is no body and
the endpoint looks like `/admin/segments/:id`, only including the
segment id.

This means that, in the rbac middleware when we check the permissions,
we need to figure out if we're in such a scenario and fetch the project
information from the DB, which feels a bit hacky, but it's something
we're seemingly already doing for features, so at least it's somewhat
consistent.

Ideally what we could do is leave this API alone and create a separate
one for project segments, with endpoints where we would have project as
a param, like so:
`http://localhost:4242/api/admin/projects/:projectId/segments/1`.

This PR opts to go with the quick and hacky solution for now since this
is an issue we want to fix quickly, but this is something that we should
be aware of. I'm also unsure if we want to create a new API for project
segments. If we decide that we want a different solution I don't mind
either adapting this PR or creating a follow up.
2023-11-09 09:37:47 +00:00
Jaanus Sellin
8c2a052a68
fix: project overview and search returning just single tag (#5305) 2023-11-09 10:58:34 +02:00
Thomas Heartman
2695e38ed5
fix: make test for last seen by env not rely on array order (#5303)
This test was flaky because it relied on the order of the array
returned. To make it less flaky, we now turn the array into an object
instead and compare that.
2023-11-08 15:23:24 +01:00
Thomas Heartman
ebf3102244
chore: add detect segment usage in CRs flag (#5302)
As the title says, this PR adds a flag to unleash for detecting segment
usage in CRs.
2023-11-08 15:06:01 +01:00
Jaanus Sellin
a5288ae0b1
feat: also allow searching partial tags (#5299) 2023-11-08 16:05:22 +02:00
Thomas Heartman
f45454fbfd
refactor: extract segment usage read model (#5301)
This PR adds a way to tell if a specific segment is being used in any
active change requests. It's the first step towards preventing segments
that are being used in change requests from being deleted.

It does that by checking the db for any unclosed CRs and using those CR
ids to look for "addStrategy" and "updateStrategy" events in the cr
events table.

## Upcoming PRs

This only puts in a way to detect it, but doesn't add that to anything.
That'll be in an upcoming iteration.
2023-11-08 14:50:12 +01:00
Jaanus Sellin
24f9fa3058
feat: connect search and filter with server api (#5297) 2023-11-08 14:19:40 +02:00
Fredrik Strand Oseberg
fa85e10eac
refactor: remove separate admin api feature flag (#5228)
This PR will remove the feature flag to separate the admin and client
api
2023-11-08 12:24:11 +01:00
Jaanus Sellin
4bacd3e055
feat: introduce offset based search instead of cursor (#5274) 2023-11-08 11:12:42 +02:00
Gastón Fournier
1dc7dd646d
chore: expose custom-handler-auth type (#5287)
This will help us get type checking on the auth handler function
2023-11-07 10:37:09 +01:00
Thomas Heartman
b3054c9277
Chore: remove "dataPath" from data OpenAPI data errors. (#5272)
The `dataPath` was present (but not in the type) in previous versions of
the
error library that we use. But with the recent major upgrade, it's
been removed and the `instancePath` property has finally come into use.

This PR removes all the handling for the previous property and
replaces it with `instancePath`. Because the `dataPath` used full
stops and the `instancePath` uses slashes, we need to change a little
bit of the handling too.
2023-11-07 09:26:14 +01:00
Nuno Góis
1539cb7553
fix: correctly query roles to be removed (#5275)
Fixes / refactors the way roles are being fetched in
`removeRolesOfTypeForUser` to be more consistent with the rest of our
code base.
2023-11-06 13:38:12 +00:00
Gastón Fournier
f16ad4e899
chore: import IUser instead of User for auth (#5269)
## About the changes
A very subtle change in the way we import IUser makes a huge difference
because previously, instead of importing IUser interface we were
importing User and naming it IUser here:

6f8f21fd48/src/lib/routes/unleash-types.ts (L2)
whereas the correct way of importing the interface is:

eec64b119e/src/lib/routes/unleash-types.ts (L2)
2023-11-06 10:46:59 +01:00
Thomas Heartman
78cf9d03aa
refactor: switch to upstream express-openapi (#5259)
Switch the express-openapi implementation from our internal fork to the
upstream version. We have upstreamed our changes and a new version has
been released, so this should be the last step before we can retire our
fork.

Because some of the dependencies have been updated since our internal
fork, we also need to update some of our error handling to reflect this.
2023-11-06 08:22:02 +01:00
Gastón Fournier
6f8f21fd48
chore: expose type and more fixes (#5268)
Expose new interface while also getting rid of unneeded compiler ignores

None of the changes should add new security risks, despite this report:
> Code scanning results / CodeQL Failing after 4s — 2 new alerts
including 2 high severity security vulnerabilities

Not sure what that means, maybe a removed ignore...
2023-11-03 17:36:50 +01:00
Fredrik Strand Oseberg
1d9a67189a
fix: last seen deadlocks (#5264)
Sort the items before inserting them into the database in order to
reduce the chance of deadlocks happening when multiple pods are
inserting at the same time.
2023-11-03 14:06:13 +01:00
Mateusz Kwasniewski
43298e16e2
feat: Server side sort by (#5250) 2023-11-03 13:15:12 +01:00
Gastón Fournier
9688955d4b
chore: expose types so we can use them properly (#5251)
Expose types to be used in enterprise and cloud addons
2023-11-03 12:00:24 +01:00
Nuno Góis
a2b0507459
feat: add banners OpenAPI tag (#5257)
https://linear.app/unleash/issue/2-1515/create-new-api-tag-banners-for-ga

Adds a new OpenAPI tag "Banners" in preparation for GA.
2023-11-03 09:05:19 +00:00