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

1051 Commits

Author SHA1 Message Date
Thomas Heartman
34aeca2418
#4205: add openapi definition for the new endpoint (#4256)
This PR adds an operation and accompanying openapi docs for the new
"update feature type lifetime" API operation.

It also fixes an oversight where the other endpoint on the same
controller didn't use `respondWithValidation`.

Note: the API here is a suggestion. I'd like to hear whether you agree
with this implementation or not.
2023-07-18 09:00:51 +00:00
Nuno Góis
3b20978eb2
test: add some basic tests to the new slack app (#4259)
https://linear.app/unleash/issue/2-1244/write-some-tests-for-the-new-slack-app-addon

Pretty self-explanatory. These are based on the tests we have for the
other addons.

If you're reading this and have any suggestions of tests we could add at
this stage, please let me know.
Thanks!
2023-07-18 08:12:15 +01:00
Mateusz Kwasniewski
593f83d5d3
feat: advancedPlayground flag used only for runtime control (#4262) 2023-07-18 08:49:04 +02:00
andreas-unleash
1f21770977
Feat/feature environment strategy execution reorder (#4248)
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
When reordering strategies for a feature environment:
- Adds stop when CR are enabled
- Emits an event 

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
2023-07-17 17:12:59 +03:00
Thomas Heartman
02635a32ef
feat(#4205): modify feature type store to allow lifetime updates (#4252)
This PR updates the feature type store to allow for lifetime updates,
laying the foundation required to make it user-configurable (#4205).
2023-07-17 14:36:43 +02:00
Thomas Heartman
209cf01477
Chore: add configurable feature type lifetimes flag (#4253)
Relates to #4205
2023-07-17 14:34:10 +02:00
Thomas Heartman
11f77a21de
#4205: activate event emission (#4240)
This PR activates the event emission that was prepared for in
https://github.com/Unleash/unleash/pull/4239.

It emits events (behind a flag) when something is marked as potentially
stale or the opposite.
It takes the features returned from the store and creates events out of
them.

The events only contain data, no preData. This is because the preData
can easily be inferred and because it gives a nicer event in the event
log.

Here is an image of the difference. The top event uses only data, so it
shows the name of the feature and the new potentiallyStale status. The
bottom event uses both preData and data, so it only shows the new
potentiallyStale status and not the feature name (unless you show the
raw event):


![image](https://github.com/Unleash/unleash/assets/17786332/5ec0fbef-f4cf-4dc6-9af6-9203fca30e5d)


Should not be merged before #4239. Merge that and then rebase this off
main or cherry the commit.

## Discussion 


### `preData`

Should we also use preData or is it enough to use only data? It seems
unnecessary in this event, but I'm open to hearing your thoughts.

### event author: `createdBy`

I've set `unleash-system` as the `createdBy` property on these events
because they are generated by the system. I found the same string used
some other places. However, it may be that there we want to use a
different author.
2023-07-17 08:10:15 +00:00
Thomas Heartman
333c0c0db1
#4205: update to prepare for emitting potentially stale events (#4239)
This PR adds updates the potentially stale status change events whenever
the potentially stale update function is run.

No events are emitted yet. While the emission is only a few lines of
code, I'd like to do that in a separate PR so that we can give it the
attention it deserves in the form of tests, etc.

This PR also moves the potentially stale update functionality from the
`update` method to only being done in the
`updatePotentiallyStaleFeatures` method. This keeps all functionality
related to marking `potentiallyStale` in one place.

The emission implementation was removed in
4fb7cbde03

## The update queries

While it would be possible to do the state updates in a single query
instead of three separate ones, wrangling this into knex proved to be
troublesome (and would also probably be harder to understand and reason
about). The current solution uses three smaller queries (one select, two
updates), as Jaanus suggested in a private slack thread.
2023-07-17 09:53:32 +02:00
Tymoteusz Czech
f91c8a338a
fix: feature OpenAPI endpoints - project related (#4212)
Update OpenAPI for `/api/admin/projects/{projectId}/features/` and
related endpoints

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-07-14 16:48:35 +02:00
Mateusz Kwasniewski
e8ea79c967
feat: client api with proper client segments and strategy variants (#4244) 2023-07-14 13:25:31 +02:00
Jaanus Sellin
4cd4153412
chore: remove split button strategy flag (#4245) 2023-07-14 14:23:23 +03:00
Jaanus Sellin
8de7dfc488
chore: remove context/segment usage flag (#4242) 2023-07-14 13:30:15 +03:00
andreas-unleash
5e45ec25e9
Revert "Feat/add strategy update event on strategy ordering (#4234)" (#4243)
This reverts commit 16e3799b9a.


<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
2023-07-14 09:11:32 +00:00
Nuno Góis
383e522127
feat: Slack App addon (#4238)
https://linear.app/unleash/issue/2-1232/implement-first-iteration-of-the-new-slack-app-addon

This PR implements the first iteration of the new Slack App addon.
Unlike the old Slack addon, this one uses a Slack App (bot) that is
installed to Slack workspaces in order to post messages. This uses
`@slack/web-api`, which internally uses the latest Slack API endpoints
like `postMessage`.

This is currently behind a flag: `slackAppAddon`.

The current flow is that the Unleash Slack App is installed from
whatever source:
 - Unleash addons page;
 - Direct link;
 - https://unleash-slack-app.vercel.app/ (temporary URL);
 - Slack App Directory (in the future);
 - Etc;

After installed, we resolve the authorization to an `access_token` that
the user can paste into the Unleash Slack App addon configuration form.


https://github.com/Unleash/unleash/assets/14320932/6a6621b9-5b8a-4921-a279-30668be6d46c

Co-authored by: @daveleek

---------

Co-authored-by: David Leek <david@getunleash.io>
2023-07-14 09:49:34 +01:00
andreas-unleash
16e3799b9a
Feat/add strategy update event on strategy ordering (#4234)
Adds a `feature-strategy-update-event` when the strategy sort-order is
changed.

Makes all fields in the eventDataSchema nullable

Closes #
[1-11120](https://linear.app/unleash/issue/1-1112/we-should-have-event-for-re-ordering-strategies)

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
2023-07-14 04:46:13 +03:00
Mateusz Kwasniewski
87b46ea734
feat: Persist strategy variants (#4236) 2023-07-13 16:04:55 +02:00
Thomas Heartman
00ca1d7186
#4205: add flag for emitting potentially stale events (#4237) 2023-07-13 12:57:34 +00:00
Thomas Heartman
85bd7845b0
#4205: mark potentially stale features (#4217)
This PR lays most of the groundwork required for emitting events when
features are marked as potentially stale by Unleash. It does **not**
emit any events just yet. The summary is:
- periodically look for features that are potentially stale and mark
them (set to run every 10 seconds for now; can be changed)
- when features are updated, if the update data contains changes to the
feature's type or createdAt date, also update the potentially stale
status.

It is currently about 220 lines of tests and about 100 lines of
application code (primarily db migration and two new methods on the
IFeatureToggleStore interface).

The reason I wanted to put this into a single PR (instead of just the db
migration, then just the potentially stale marking, then the update
logic) is:
If users get the db migration first, but not the rest of the update
logic until the events are fired, then they could get a bunch of new
events for features that should have been marked as potentially stale
several days/weeks/months ago. That seemed undesirable to me, so I
decided to bunch those changes together. Of course, I'd be happy to
break it into smaller parts.

## Rules

A toggle will be marked as potentially stale iff:
- it is not already stale
- its createdAt date is older than its feature type's expected lifetime
would dictate

## Migration

The migration adds a new `potentially_stale` column to the features
table and sets this to true for any toggles that have exceeded their
expected lifetime and that have not already been marked as `stale`.

## Discussion

### The `currentTime` parameter of `markPotentiallyStaleFeatures`

The `markPotentiallyStaleFetaures` method takes an optional
`currentTime` parameter. This was added to make it easier to test (so
you can test "into the future"), but it's not used in the application.
We can rewrite the tests to instead update feature toggles manually, but
that wouldn't test the actual marking method. Happy to discuss.
2023-07-13 12:02:33 +00:00
Mateusz Kwasniewski
ce87806a80
feat: strategy variant schema openapi (#4232) 2023-07-13 13:50:03 +02:00
Thomas Heartman
8f5bda6b8a
openapi: document operations for admin ui feedback (#4226)
This PR updates the endpoint documentation and schemas related to Admin
UI feedback.
2023-07-13 13:27:52 +02:00
Jaanus Sellin
3da1cbba47
feat: feature creation limit crud together with frontend (#4221) 2023-07-13 14:02:35 +03:00
Nuno Góis
c387a19831
feat: add slackAppAddon feature flag (#4235)
https://linear.app/unleash/issue/2-1231/add-new-slack-app-addon-feature-flag

Adds a new feature flag for the new slack app addon.
2023-07-13 12:26:22 +02:00
Thomas Heartman
a785465943
openapi: update the splash endpoints and schemas for splash (#4227)
This change updates the splash endpoints and related schemas for the
admin ui tag.
2023-07-13 08:29:54 +00:00
Tymoteusz Czech
fb9db12002
Fix: variants-batch (#4222)
## About the changes
Fix un-awaited promise on batch variant update - reduce function allowed
TS to skip Promise type.

---------

Co-authored-by: Gastón Fournier <gaston@getunleash.io>
2023-07-12 17:14:55 +02:00
Thomas Heartman
b927615ebe
openapi: update misc 'features'-tagged endpoints (#4192)
This PR updates a slew of miscellaneous endpoints tagged `Features`
2023-07-11 14:17:10 +02:00
Mateusz Kwasniewski
2e9bf76717
feat: sort feature strategies (#4218) 2023-07-11 13:58:14 +02:00
Mateusz Kwasniewski
81c005013e
fix: min items was breaking import (#4219) 2023-07-11 12:42:33 +02:00
Christopher Kolstad
902cc2f2e7
fix: reduce severity of api token middleware errors (#4216)
This isn't something our on-calls can do something about when it fails,
so downgrading to WARN seems like the right level.
2023-07-11 13:33:02 +03:00
andreas-unleash
6601ef19c2
fix: return 400 on incorrect client metrics input (#4193)
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
Wraps the whole `registerClientMetrics` function with try/catch to
return 400 on error
## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #
[1-1037](https://linear.app/unleash/issue/1-1037/return-4xx-error-for-incorrect-metrics-input)

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
![Screenshot 2023-07-10 at 14 23
13](https://github.com/Unleash/unleash/assets/104830839/5417fb39-ce24-4b70-b3d3-c63374a29a12)

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
2023-07-11 12:06:28 +03:00
Mateusz Kwasniewski
92d43ed4f6
fix: missing flags (#4214) 2023-07-11 08:27:42 +00:00
Gastón Fournier
58151d8d80
docs: add descriptions and examples to tag schemas (#4194)
## About the changes
- Adding descriptions and examples to tag and tag types schemas
- Adding standard errors, summaries, and descriptions to tag and tag
types endpoints
- Some improvements on compilation errors

---------

Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-07-11 10:02:00 +02:00
Mateusz Kwasniewski
5c4f15ea5d
feat: strategy variant test UI (#4199) 2023-07-11 09:21:01 +02:00
Thomas Heartman
f83350cb2a
refactor: move status codes into classes (#4200)
Make each error class have to define its own status code. This makes
it easier for developers to see which code an error corresponds to and
means less jumping back and forth between files. In other words:
improved locality.

Unfortunately, the long switch needs to stay in case we get errors
thrown that aren't of the Unleash Error type, but we can move it to
the `fromLegacyError` file instead.

Tradeoff analysis by @kwasniew: 
+ I like the locality of error to code reasoning
- now HTTP leaks to the non-HTTP code that throws those errors e.g. application services

If we had other delivery mechanisms other than HTTP then it wouldn't make sense to couple error codes to one protocol (HTTP). But since we're mostly doing web it may not be a problem.

@thomasheartman's response:

This is a good point and something I hadn't considered. The same data was always available on those errors (by using the same property), I've just made the declaration local to each error instead of something that the parent class handles. The idea was to make it easier to create new error classes with their corresponding error codes. Because the errors are intended to be API errors (or at least, I've always considered them to be that), I think that makes sense.

Taking your comment into consideration, I still think it's the right thing to do, but I'm not bullish about it. We could always walk it back later if we find that it's not appropriate. The old code is still available and we could easily enough roll back this change if we find that we want to decouple it later.
2023-07-11 09:20:11 +02:00
Jaanus Sellin
a2b06e4222
feat: project UI rework, move edit and delete buttons deeper (#4195) 2023-07-11 09:47:38 +03:00
Gastón Fournier
b37851acea
chore: Datadog addon, ability to include source type name (#4196)
## About the changes
Include a new configuration parameter to be able to specify
source_type_name. This is an opt-in feature which provides backward
compatibility to our existing users.


![image](https://github.com/Unleash/unleash/assets/455064/0e65584f-f601-4f17-b7a5-e73dae55772e)


Closes #4109 

## Discussion points
Maybe this should be hardcoded to `Unleash` but this gives additional
flexibility
2023-07-10 15:38:53 +02:00
andreas-unleash
d5ef1dda0a
chore: openapai favorite endpoints (#4189)
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->
Adds description and summary to `favorite` endpoints
## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #
[1-1098](https://linear.app/unleash/issue/1-1098/openapi-features-favorites)

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
2023-07-10 14:13:00 +03:00
Thomas Heartman
5b95eed163
refactor: split NoAccessError into ForbiddenError + PermissionError (#4190)
In some of the places we used `NoAccessError` for permissions, other
places we used it for a more generic 403 error with a different
message. This refactoring splits the error type into two distinct
types instead to make the error messages more consistent.
2023-07-10 12:48:13 +02:00
Christopher Kolstad
4ce78ccecd
docs: add description to requests per seconds schemas (#4182)
### What
Adds a quick and dirty description to requestPerSeconds and
segmentedRequestPerSecondsSchema so the enterprise /rps endpoint has
better API docs.

---------

Co-authored-by: Simon Hornby <liquidwicked64@gmail.com>
2023-07-10 08:18:08 +00:00
Thomas Heartman
d60e505a40
1-1049 Emit events after db transaction is complete (#4174)
This PR fixes an issue where events generated during a db transaction
would get published before the transaction was complete. This caused
errors in some of our services that expected the data to be stored
before the transaction had been commited. Refer to [linear issue
1-1049](https://linear.app/unleash/issue/1-1049/event-emitter-should-emit-events-after-db-transaction-is-commited-not)
for more info.

Fixes 1-1049.

## Changes

The most important change here is that the `eventStore` no longer emits
events when they happen (because that can be in the middle of a
transaction). Instead, events are stored with a new `announced` column.
The new event announcer service runs on a schedule (every second) and
publishes any new events that have not been published.

Parts of the code have largely been lifted from the
`client-application-store`, which uses a similar logic.

I have kept the emitting of the event within the event store because a
lot of other services listen to events from this store, so removing that
would require a large rewrite. It's something we could look into down
the line, but it seems like too much of a change to do right now.

## Discussion

### Terminology:

Published vs announced? We should settle on one or the other. Announced
is consistent with the client-application store, but published sounds
more fitting for events.

### Publishing and marking events as published

The current implementation fetches all events that haven't been marked
as announced, sets them as announced, and then emits them. It's possible
that Unleash would crash in the interim or something else might happen,
causing the events not to get published. Maybe it would make sense to
just fetch the events and only mark them as published after the
announcement? On the other hand, that might get us into other problems.
Any thoughts on this would be much appreciated.
2023-07-10 08:43:22 +02:00
Tymoteusz Czech
ace499d7c6
Update OpenAPI feature strategies (#4175)
## About the changes
Updates for endpoint
`/api/admin/projects/{projectId}/features/{featureName}/environments/{environment}/strategies`
and similar
2023-07-07 15:45:04 +00:00
Tymoteusz Czech
6f15eb9f4c
fix: correct escaping of ui flags for plausible (#3907)
## About the changes
Stringified JSON still needs to be escaped before being placed in an
HTML attribute.
2023-07-07 17:40:37 +02:00
Tymoteusz Czech
1b99b700d6
OpenAPI - feature environment endpoints (#4166)
## About the changes
Fix OpenAPI definitions for endpoint

`/api/admin/projects/{projectId}/features/{featureName}/environments/{environment}`
and similar.
2023-07-07 14:31:03 +02:00
Thomas Heartman
a51b47e956
openapi: update tag description (#4178)
Tiny PR to update the admin UI tag description, including a disclaimer
that it may change at any time.
2023-07-07 11:14:19 +00:00
Mateusz Kwasniewski
23981407ef
fix: validate min constraint values in openapi (#4179) 2023-07-07 12:41:48 +02:00
Jaanus Sellin
3c52550474
fix: bulk tags will work now with project permissions (#4177) 2023-07-07 11:55:13 +03:00
Simon Hornby
79dd508485
fix: project tokens can now be created with the correct permissions (#4165) 2023-07-06 15:47:03 +02:00
Mateusz Kwasniewski
d7b7d93533
feat: user openapi spec (#4162) 2023-07-06 15:27:43 +02:00
Thomas Heartman
46b4030d47
bug: mark descriptions on strategies as nullable (#4156)
This was omitted by mistake.

Fixes 1-1086
2023-07-06 13:39:23 +02:00
Christopher Kolstad
e22662e140
fix: add change-edited event 2023-07-06 13:11:09 +02:00
Christopher Kolstad
7130270058
fix: added service-account events (#4164)
We're using this in enterprise as well, so we need to add events that
could happen there as well.
2023-07-06 10:51:32 +00:00