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

2411 Commits

Author SHA1 Message Date
Mateusz Kwasniewski
1f3cc3917e
fix: split features schema into archived and project features (#7973) 2024-08-23 12:59:39 +02:00
Thomas Heartman
4693f7c598
fix: normalize casing for API token types before insert (#7972)
Fixes a bug where if you had API keys using different casing for the
same type, they'd come out as different types in the API token count
map. To get around it, we normalize the keys to lowercase before
inserting them into the map, taking into account any previous values
that might have existed for that type.

Should fix issues like this:

![image](https://github.com/user-attachments/assets/1fe218ed-7729-4a06-9a10-f4c8c7831bf8)
2024-08-23 12:53:53 +02:00
gitar-bot[bot]
4615ff40ce
[Gitar] Cleaning up stale flag: resourceLimits with value true (#7964)
[![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>
Co-authored-by: Thomas Heartman <thomas@getunleash.io>
2024-08-22 13:20:53 +02: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
David Leek
00700918c8
chore: remove unused feature flag for webhooks name logging (#7968) 2024-08-22 12:39:52 +02:00
David Leek
e13f7eea63
feat: log domain every time a webhook is invoked (#7962) 2024-08-22 11:26:53 +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
99e4a564d0
fix: fix events with no-project projects (#7951)
Fixes issue where `segment-created `events had fake project name
**no-project** attached.

In total for previous 4 months, all segments created that were global
segments, have this issue.


https://github.com/Unleash/unleash/pull/6872/files#diff-68dcd43b31d35a8a80c73bca1f2a9626b0234dd0b76920a6881b81fa04708268R135
2024-08-21 15:32:37 +03:00
gitar-bot[bot]
3a15fa7689
[Gitar] Cleaning up stale flag: integrationEvents with value true (#7940) 2024-08-21 14:25:24 +02:00
Mateusz Kwasniewski
48423fa980
fix: enable disabled strategies keeps settings (#7950) 2024-08-21 13:17:33 +02:00
Gastón Fournier
45de8ceae0
chore: type our path parameters when they are numbers (#4471)
Path types in our openapi are inferred as string (which is a sensible
default). But we can be more specific and provide the right type for
each parameter. This is one example of how we can do that
2024-08-21 13:01:00 +02: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
Tymoteusz Czech
6c5ce52470
Refactor: Remove react-timeago (#7943)
Remove dependency 🫡
2024-08-21 12:03:03 +02:00
gitar-bot[bot]
43100f9561
Cleaning up stale flag: insightsV2 with value true (#7896)
Co-authored-by: Gitar <noreply@gitar.co>
Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com>
2024-08-21 12:01:35 +02:00
Mateusz Kwasniewski
ee1d8ee8cd
fix: misc fixes for project archive (#7948) 2024-08-21 10:34:13 +02:00
Thomas Heartman
3cd312f9a9
chore: allow you to use the options object to override *all* the new resource limits (#7938)
This allows us to use different limits for enterprise self-hosted and
hosted
2024-08-21 08:59:19 +02:00
David Leek
74133395cc
chore: change integration events api tag to addons (#7932) 2024-08-20 14:00:58 +02:00
Mateusz Kwasniewski
02c8250905
fix: delete project action (#7934) 2024-08-20 11:46:12 +02:00
Thomas Heartman
7c774b22e8
fix: don't count flags multiple times (bonus: don't count non-project events) (#7931)
This PR fixes an issue where the number of flags belonging to a project
was wrong in the new getProjectsForAdminUi.

The cause was that we now join with the events table to get the most
"lastUpdatedAt" data. This meant that we got multiple rows for each
flag, so we counted the same flag multiple times. The fix was to use a
"distinct".

Additionally, I used this as an excuse to write some more tests that I'd
been thinking about. And in doing so also uncovered another bug that
would only ever surface in verrry rare conditions: if a flag had been
created in project A, but moved to project B AND the
feature-project-change event hadn't fired correctly, project B's last
updated could show data from that feature in project A.

I've also taken the liberty of doing a little bit of cleanup.
2024-08-20 09:31:45 +00:00
Mateusz Kwasniewski
4e11e57f7f
feat: project actions count metric (#7929) 2024-08-20 09:46:39 +02:00
David Leek
e714a7fe2b
feat:metrics for outgoing integrations (#7921) 2024-08-20 09:00:28 +02:00
Gastón Fournier
106e1d1376
fix: last seen metrics exceeding table limits (#7923)
## About the changes
When storing last seen metrics we no longer validate at insert time that
the feature exists. Instead, there's a job cleaning up on a regular
interval.

Metrics for features with more than 255 characters, makes the whole
batch to fail, resulting in metrics being lost.

This PR helps mitigate the issue while also logs long name feature names
2024-08-19 20:17:52 +00:00
gitar-bot[bot]
662c7ab4dc
[Gitar] Cleaning up stale flag: changeRequestPlayground with value true (#7920) 2024-08-19 15:33:55 +02:00
David Leek
205aeb5265
feat: feature flags for metrics and service name logging (#7916) 2024-08-19 14:16:31 +02:00
Thomas Heartman
7008070fc1
chore: impl empty results for fake project read model (#7912)
Implements empty responses for the fake project read model. Instead of
throwing a not implemented error, we'll return empty results.

This makes some of the tests in enterprise pass.
2024-08-19 10:53:05 +02:00
Thomas Heartman
f965246b83
chore: minor cleanup in new project read model (#7911)
This PR touches up a few small things in the project read model.

Fixes:
Use the right method name in the query/method timer for
`getProjectsForAdminUi`. I'd forgotten to change the timer name from the
original method name.

Spells the method name correctly for the `getMembersCount` timer (it
used to be `getMemberCount`, but the method is callled `getMembersCount`
with a plural s).

Changes:
Call the `getMembersCount` timer from within the `getMembersCount`
method itself. Instead of setting that timer up from two different
places, we can call it in the method we're timing. This wasn't a problem
previously, because the method was only called from a single place.
Assuming we always wanna time that query, it makes more sense to put the
timing in the actual method.
2024-08-19 10:13:30 +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
abd077aaf7
chore: add flags projectListImprovements and useProjectReadModel (#7905)
These are both related to the work on the project list improvements
project.

The `projectListImprovements` flag will be used to enable disable the
new project list improvements.

The `useProjectReadModel` flag will be used to enable/disable the use
of the new project read model and is mostly a safety feature.
2024-08-16 11:54:11 +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
gitar-bot[bot]
977f969b80
[Gitar] Cleaning up stale flag: improveCreateFlagFlow with value true (#7895)
[![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>
Co-authored-by: sjaanus <sellinjaanus@gmail.com>
2024-08-15 15:53:36 +03:00
Mateusz Kwasniewski
30cbde573b
feat: return archived at in project overview (#7888) 2024-08-15 14:15:06 +02:00
gitar-bot[bot]
413df42555
[Gitar] Cleaning up stale flag: commandBarUI with value true (#7894)
[![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>
Co-authored-by: sjaanus <sellinjaanus@gmail.com>
2024-08-15 14:29:07 +03:00
Mateusz Kwasniewski
c2e6f74bfa
fix: exclude archived features in segments count (#7897) 2024-08-15 13:27:18 +02:00
David Leek
cf83043d8a
feat: resolve useragent source and add as source label to metrics (#7883) 2024-08-15 13:25:42 +02:00
Jaanus Sellin
183a9fc737
feat: support private projects for event search (#7884)
Adds private projects support for event search. Unit test should cover
the usecases.
2024-08-15 12:51:04 +03:00
Mateusz Kwasniewski
a89f05181d
fix: exclude archived features in segments count (#7886) 2024-08-15 11:32:46 +02:00
Tymoteusz Czech
3baeb4c541
feat: dialogs for project revive and delete (#7863)
Dialog needed to confirm revive/delete actions
2024-08-15 07:25:49 +00: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
Mateusz Kwasniewski
94605646f6
fix: always provide empty segments list in feature env strategies (#7880)
<!-- 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

When reading feature env strategies and there's no segments it returns
empty list of segments now. Previously it was undefined leading to
overly verbose change request diffs.

<img width="669" alt="Screenshot 2024-08-14 at 16 06 14"
src="https://github.com/user-attachments/assets/1ac6121b-1d6c-48c6-b4ce-3f26c53c6694">


### 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? -->
2024-08-14 19:13:06 +02:00
Simon Hornby
f276728688
feat: allow editing root role/description on SCIM group (#7874) 2024-08-14 15:11:56 +02:00
Mateusz Kwasniewski
94a05eecc0
fix: change request enabled check should ignore disabled envs (#7869) 2024-08-14 13:13:31 +02:00
Gastón Fournier
cac621c450
fix: messed up on merge-conflicts (#7873)
When fixing conflicts accidentally I've undone my changes
2024-08-14 12:00:57 +02:00
Mateusz Kwasniewski
cb6ba743ac
fix: make archivedAt nullable (#7872) 2024-08-14 11:36:48 +02:00
Mateusz Kwasniewski
b042afb7dd
feat: archived projects query improved (#7866) 2024-08-14 11:01:17 +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
Jaanus Sellin
bbdb5e635b
feat: update feature completed payload to have boolean instead of string (#7855)
For easy gitar integration, we need to have boolean in the event
payload.
We might rethink it when we add variants, but currently enabled with
variants is not used.
2024-08-13 12:43:49 +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
Mateusz Kwasniewski
9b781b781a
feat: prevent move feature to archived project (#7839) 2024-08-12 13:29:38 +02:00
Mateusz Kwasniewski
67fa28f05a
feat: prevent revive flag/flags in archived project (#7826) 2024-08-12 13:29:24 +02:00
Jaanus Sellin
624c6ce9c3
feat: events table type column index (#7838)
Adding index on even table type column, since we are running queries on
top of it.
2024-08-12 13:46:27 +03:00
Tymoteusz Czech
e77bb1b2e7
Fix: time to production (#7835)
- filter out time to production data points of `0 days to production`
- allow for gathering data for quickly enabled feature flags
2024-08-12 09:47:06 +00:00
Jaanus Sellin
ea057d1777
feat: add index on events created at (#7836)
After adding an index, the time for the new event search on 100k events
decreased from 5000ms to 4ms. This improvement is due to the query using
an index scan instead of a sequence scan.
2024-08-12 12:46:50 +03:00
Gastón Fournier
f9d077209f
fix: after encryption some emails end up being too long (#7828)
Encountered this case after encrypting an already long email address.
This should mitigate the issue in demo instance. I don't think it's a
big issue to ignore the length when validating an email address cause
this is already limited at the DB layer by the column length
2024-08-09 19:18:19 +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
Thomas Heartman
1db222a5b9
feat: add collaborators to feature schema (#7821)
Update the feature schema to include collaborator information
2024-08-09 11:18:37 +02:00
gitar-bot[bot]
5aaa4920dd
chore: [Gitar] Cleaning up stale flag: featureCollaborators with value true (#7820)
[![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>
Co-authored-by: Thomas Heartman <thomas@getunleash.io>
2024-08-09 11:12:26 +02: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
Tymoteusz Czech
413da2aa27
fix: don't show link stubs in slack notifications (#7810)
Slack is trying to add not useful link previews
2024-08-08 15:29:42 +02:00
Mateusz Kwasniewski
b65e593c23
chore: remove featureLifecycle and featureLifecycleMetrics flags (#7808) 2024-08-08 13:45:23 +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
3fe385e127
chore: remove flagCreator flag (#7807) 2024-08-08 12:19:32 +02:00
Mateusz Kwasniewski
8caa1e242c
feat: transactional project service support (#7799) 2024-08-07 16:34:55 +02:00
Mateusz Kwasniewski
0450bfe6f9
feat: archive project service (#7794) 2024-08-07 12:09:00 +02:00
Mateusz Kwasniewski
74de3ea72e
feat: archived at column in projects (#7782) 2024-08-07 10:00:37 +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
Mateusz Kwasniewski
f9665233cc
chore: archive projects flag (#7772) 2024-08-06 14:59:49 +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
Mateusz Kwasniewski
afa34867c1
fix: playground parent disabled with strategy (#7744) 2024-08-05 10:39:21 +02: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
Mateusz Kwasniewski
bbefff5d5a
refactor: rename rollback to more explicit rollbackTransaction (#7723) 2024-08-01 13:49:49 +02:00
Tymoteusz Czech
d1e70eefbe
feat: Remove orphaned tokens flags (#7714)
Cleanup of `allowOrphanedWildcardTokens` and `cleanApiTokenWhenOrphaned`
2024-08-01 13:31:52 +02:00
Thomas Heartman
0c53f7d21b
feat: create gauges for all resource limits (#7718)
This PR adds Grafana gauges for all the existing resource limits. The
primary purpose is to be able to use this in alerting. Secondarily, we
can also use it to get better insights into how many customers have
increased their limits, as well as how many people are approaching their
limit, regdardless of whether it's been increased or not.

## Discussion points

### Implementation

The first approach I took (in
87528b4c67),
was to add a new gauge for each resource limit. However, there's a lot
of boilerplate for it.

I thought doing it like this (the current implementation) would make it
easier. We should still be able to use the labelName to collate this in
Grafana, as far as I understand? As a bonus, we'd automatically get new
resource limits when we add them to the schema.

``` tsx
        const resourceLimit = createGauge({
            name: 'resource_limit',
            help: 'The maximum number of resources allowed.',
            labelNames: ['resource'],
        });

        // ...

        for (const [resource, limit] of Object.entries(config.resourceLimits)) {
            resourceLimit.labels({ resource }).set(limit);
        }
```

That way, when checking the stats, we should be able to do something
like this:

``` promql
resource_limit{resource="constraintValues"}
```

### Do we need to reset gauges?

I noticed that we reset gauges before setting values in them all over
the place. I don't know if that's necessary. I'd like to get that double
clarified before merging this.
2024-08-01 09:59:25 +02:00
Mateusz Kwasniewski
a4c49e7d7f
fix: rollback should await a result (#7712) 2024-07-31 16:46:15 +02:00
Nuno Góis
49fecb2005
chore: request origin prom metrics (#7709)
https://linear.app/unleash/issue/2-2501/adapt-origin-middleware-to-stop-logging-ui-requests-and-start

This adapts the new origin middleware to stop logging UI requests (too
noisy) and adds new Prometheus metrics.

<img width="745" alt="image"
src="https://github.com/user-attachments/assets/d0c7f51d-feb6-4ff5-b856-77661be3b5a9">

This should allow us to better analyze this data. If we see a lot of API
requests, we can dive into the logs for that instance and check the
logged data, like the user agent.

This PR adds some helper methods to make listening and emitting metric
events more strict in terms of types. I think it's a positive change
aligned with our scouting principle, but if you think it's complex and
does not belong here I'm happy with dropping it.
2024-07-31 13:52:39 +01:00
Mateusz Kwasniewski
987ba5ea0a
chore: composition root playground service (#7710) 2024-07-31 14:44:57 +02:00
Mateusz Kwasniewski
126dff2344
chore: change request playground flag (#7707) 2024-07-31 11:38:55 +02:00
Mateusz Kwasniewski
6170d10e62
feat: rollback transaction wrapper (#7706) 2024-07-31 10:22:05 +02:00
Nuno Góis
9fff29a080
chore: change log level to info in origin middleware (#7705)
https://linear.app/unleash/issue/2-2492/change-origin-middleware-log-level-to-info

Changes origin middleware log level to `info` instead of `debug`.
2024-07-31 09:01:48 +01:00
Jaanus Sellin
24e2c4030b
feat: new event search flag (#7699)
Add `newEventSearch` flag
2024-07-31 08:59:42 +02:00
Mateusz Kwasniewski
c828d01135
refactor: encapsulate playground limit in service (#7700) 2024-07-30 12:40:27 +02:00
Nuno Góis
50167d4f9e
chore: origin middleware (#7695)
https://linear.app/unleash/issue/2-2489/create-a-first-iteration-of-an-origin-middleware-that-logs-ui-and-api

Small spike around what the first iteration of an "origin middleware"
would look like.

No strong feelings all around, so feel free to tell me this is all wrong
and we should go a different route. However diving a little bit into it
personally helps me wrap my head around it, so it may help you too.
2024-07-30 10:42:50 +01:00
Tymoteusz Czech
1f2d47bd91
fix: on project delete with tokens put token deleted in audit log (#7675)
Use service with audit tracking instead of store directly.
2024-07-26 14:06:15 +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
Tymoteusz Czech
369518cd7d
Feat: webhook markdown (#7658)
Add ability to format format event as Markdown in generic webhooks,
similar to Datadog integration.
Closes https://github.com/Unleash/unleash/issues/7646

Co-authored-by: Nuno Góis <github@nunogois.com>
2024-07-25 09:45:20 +00:00
Thomas Heartman
245c3e119d
chore: add flag configuration for the new flag creation flow (#7662)
Add a new flag and default it to true for local development.
2024-07-25 11:12:58 +02:00
Jaanus Sellin
0148481623
feat: update openapi schema for feature creation for tags (#7657)
Added tags support for schema.
2024-07-25 10:36:04 +03:00
Nuno Góis
8a20ae999f
chore: keep latest integration events for each integration configuration (#7652)
https://linear.app/unleash/issue/2-2469/keep-the-latest-event-for-each-integration-configuration

This makes it so we keep the latest event for each integration
configuration, along with the previous logic of keeping the latest 100
events of the last 2 hours.

This should be a cheap nice-to-have, since now we can always know what
the latest integration event looked like for each integration
configuration. This will tie-in nicely with the next task of making the
latest integration event state visible in the integration card.

Also improved the clarity of the auto-deletion explanation in the modal.
2024-07-24 13:52:57 +01:00
Thomas Heartman
e2b90ae91d
fix: add workaround for tooltip (#7649)
This PR adds the UI part of feature flag collaborators. Collaborators are hidden on windows smaller than size XL because we're not sure how to deal with them in those cases yet.
2024-07-24 09:33:29 +00:00
Nuno Góis
1d6dc9b195
chore: integration events API (#7639)
https://linear.app/unleash/issue/2-2439/create-new-integration-events-endpoint

https://linear.app/unleash/issue/2-2436/create-new-integration-event-openapi-schemas

This adds a new `/events` endpoint to the Addons API, allowing us to
fetch integration events for a specific integration configuration id.


![image](https://github.com/user-attachments/assets/e95b669e-e498-40c0-9d66-55be30a24c13)

Also includes:
- `IntegrationEventsSchema`: New schema to represent the response object
of the list of integration events;
- `yarn schema:update`: New `package.json` script to update the OpenAPI
spec file;
- `BasePaginationParameters`: This is copied from Enterprise. After
merging this we should be able to refactor Enterprise to use this one
instead of the one it has, so we don't repeat ourselves;

We're also now correctly representing the BIGSERIAL as BigInt (string +
pattern) in our OpenAPI schema. Otherwise our validation would complain,
since we're saying it's a number in the schema but in fact returning a
string.
2024-07-23 10:09:19 +01:00
Nuno Góis
9ff393b3d7
chore: register integration events in New Relic integration (#7636)
https://linear.app/unleash/issue/2-2462/register-integration-events-new-relic

Registers integration events in the **New Relic** integration.

Similar to:
- #7635
- #7634
- #7631
- #7626
- #7621
2024-07-23 10:07:31 +01:00
Nuno Góis
47ff73afb2
chore: register integration events in Datadog integration (#7635)
https://linear.app/unleash/issue/2-2461/register-integration-events-datadog

Registers integration events in the **Datadog** integration.

Similar to:
 - #7634 
 - #7631
 - #7626
 - #7621
2024-07-22 12:14:32 +01:00
Nuno Góis
e07ded9455
chore: register integration events in Teams integration (#7634)
https://linear.app/unleash/issue/2-2460/register-integration-events-teams

Registers integration events in the **Teams** integration.

Also includes slight improvements to the **Webhooks** integration.

Similar to:
 - #7631
 - #7626
 - #7621
2024-07-22 12:13:10 +01:00
Nuno Góis
1033276e97
chore: register integration events in Slack App integration (#7631)
https://linear.app/unleash/issue/2-2459/register-integration-events-slack-app

Registers integration events in the **Slack App** integration.

Similar to:
 - #7626
 - #7621
2024-07-22 11:54:19 +01:00
Thomas Heartman
a5223af702
fix: change "features flags" -> "feature flags" (#7632)
This typo has been around since the tag was introduced. About time we
fixed it.
2024-07-22 10:48:54 +02:00
Christopher Kolstad
71b2035dfb
chore: extend uiConfig schema with new SSO variables (#7628)
As the title says. Adds two new nullable variables to uiConfig. Used in
frontend to decide if SSO config is editable through the GUI
2024-07-19 12:39:34 +00:00
Mateusz Kwasniewski
71b3a2ae0a
feat: feature collaborators added to API behind a flag (#7627) 2024-07-19 14:34:22 +02:00
Nuno Góis
203b700e27
chore: register integration events in Slack integration (#7626)
https://linear.app/unleash/issue/2-2458/register-integration-events-slack

Registers integration events in the **Slack** integration.

Similar to: https://github.com/Unleash/unleash/pull/7621

Also slightly improves the previous work on webhooks.
2024-07-19 12:56:55 +01:00
Thomas Heartman
87fa5a2414
chore: allow you to lower constraint values even when they're above limit (#7624)
This PR allows you to gradually lower constraint values, even if they're
above the limits.

It does, however, come with a few caveats because of how Unleash deals
with constraints:
Constraints are just json blobs. They have no IDs or other
distinguishing features. Because of this, we can't compare the current
and previous state of a specific constraint.

What we can do instead, is to allow you to lower the amount of
constraint values if and only if the number of constraints hasn't
changed. In this case, we assume that you also haven't reordered the
constraints (not possible from the UI today). That way, we can compare
constraint values between updated and existing constraints based on
their index in the constraint list.

It's not foolproof, but it's a workaround that you can use. There's a
few edge cases that pop up, but that I don't think it's worth trying to
cover:

Case: If you **both** have too many constraints **and** too many
constraint values
Result: You won't be allowed to lower the amount of constraints as long
as the amount of strategy values is still above the limit.
Workaround: First, lower the amount of constraint values until you're
under the limit and then lower constraints. OR, set the constraint you
want to delete to a constraint that is trivially true (e.g. `currentTime
> yesterday` ). That will essentially take that constraint out of the
equation, achieving the same end result.

Case: You re-order constraints and at least one of them has too many
values
Result: You won't be allowed to (except for in the edge case where the
one with too many values doesn't move or switches places with another
one with the exact same amount of values).
Workaround: We don't need one. The order of constraints has no effect on
the evaluation.
2024-07-19 10:14:42 +00: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
Thomas Heartman
3db1159304
feat: allow you to gradually scale back constraint usage (#7622)
This PR updates the limit validation for constraint numbers on a single
strategy. In cases where you're already above the limit, it allows you
to still update the strategy as long as you don't add any **new**
constraints (that is: the number of constraints doesn't increase).

A discussion point: I've only tested this with unit tests of the method
directly. I haven't tested that the right parameters are passed in from
calling functions. The main reason being that that would involve
updating the fake strategy and feature stores to sync their flag lists
(or just checking that the thrown error isn't a limit exceeded error),
because right now the fake strategy store throws an error when it
doesn't find the flag I want to update.
2024-07-19 08:40:45 +00:00
Mateusz Kwasniewski
a0ba44d9f4
chore: feature collaborators flag (#7623) 2024-07-19 10:11:39 +02:00
Nuno Góis
5a2b48687e
chore: integration events service (#7614)
https://linear.app/unleash/issue/2-2438/create-new-integration-event-service

https://linear.app/unleash/issue/2-2442/automatically-clean-up-old-integration-events

Adds a new `IntegrationEventsService`.
2024-07-18 16:54:31 +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
Nuno Góis
0d3dee0e96
fix: validate patched data with schema (#7616)
https://linear.app/unleash/issue/2-2453/validate-patched-data-against-schema

This adds schema validation to patched data, fixing potential issues of
patching data to an invalid state.

This can be easily reproduced by patching a strategy constraints to be
an object (invalid), instead of an array (valid):

```sh
curl -X 'PATCH' \
  'http://localhost:4242/api/admin/projects/default/features/test/environments/development/strategies/8cb3fec6-c40a-45f7-8be0-138c5aaa5263' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "path": "/constraints",
    "op": "replace",
    "from": "/constraints",
    "value": {}
  }
]'
```

Unleash will accept this because there's no validation that the patched
data actually looks like a proper strategy, and we'll start seeing
Unleash errors due to the invalid state.

This PR adapts some of our existing logic in the way we handle
validation errors to support any dynamic object. This way we can perform
schema validation with any object and still get the benefits of our
existing validation error handling.

This PR also takes the liberty to expose the full instancePath as
propertyName, instead of only the path's last section. We believe this
has more upsides than downsides, especially now that we support the
validation of any type of object.


![image](https://github.com/user-attachments/assets/f6503261-f6b5-4e1d-9ec3-66547d0d061f)
2024-07-18 13:26:50 +01:00
Thomas Heartman
f15bcdc2a6
chore: send prometheus metrics when someone tries to exceed resource limits (#7617)
This PR adds prometheus metrics for when users attempt to exceed the
limits for a given resource.

The implementation sets up a second function exported from the
ExceedsLimitError file that records metrics and then throws the error.
This could also be a static method on the class, but I'm not sure that'd
be better.
2024-07-18 13:35:45 +02:00
Thomas Heartman
949a5f0109
fix: Update OpenAPI error converter to handle query param errors too (#7609)
This PR updates the OpenAPI error converter to also work for errors with
query parameters.
We previously only sent the body of the request along with the error,
which meant that query parameter errors would show up incorrectly.

For instance given a query param with the date format and the invalid
value `01-2020-01`, you'd previously get the message:
> The `from` value must match format "date". You sent undefined

With this change, you'll get this instead:
> The `from` value must match format "date". You sent "01-2020-01". 

The important changes here are two things:
- passing both request body and query params
- the 3 lines in `fromOpenApiValidationError` that check where we should
get the value you sent from.

The rest of it is primarily updating tests to send the right arguments
and some slight rewording to more accurately reflect that this can be
either request body or query params.
2024-07-17 12:47:32 +02:00
Nuno Góis
13d02685d8
chore: db migration for integration events (#7604)
https://linear.app/unleash/issue/2-2435/create-migration-for-a-new-integration-events-table

Adds a DB migration that creates the `integration_events` table:
 - `id`: Auto-incrementing primary key;
- `integration_id`: The id of the respective integration (i.e.
integration configuration);
 - `created_at`: Date of insertion;
- `state`: Integration event state, as text. Can be anything we'd like,
but I'm thinking this will be something like:
   - Success 
   - Failed 
   - SuccessWithErrors ⚠️
- `state_details`: Expands on the previous column with more details, as
text. Examples:
   - OK. Status code: 200
   - Status code: 429 - Rate limit reached
   - No access token provided
 - `event`: The whole event object, stored as a JSON blob;
- `details`: JSON blob with details about the integration execution.
Will depend on the integration itself, but for example:
   - Webhook: Request body
- Slack App: Message text and an array with all the channels we're
posting to

I think this gives us enough flexibility to cover all present and
(possibly) future integrations, but I'd like to hear your thoughts.

I'm also really torn on what to call this table:
- `integration_events`: Consistent with the feature name. Addons are now
called integrations, so this would be consistent with the new thing;
 - `addon_events`: Consistent with the existing `addons` table.
2024-07-17 10:02:04 +01:00
Nuno Góis
4fb5469cb5
chore: add integrationEvents feature flag (#7602)
https://linear.app/unleash/issue/2-2434/add-a-new-integrationevents-feature-flag

Adds a new `integrationEvents` feature flag.
2024-07-17 08:25:47 +01:00
Tymoteusz Czech
7b2532ea4f
New insights layout - feature flag (#7598)
Preparing insights component for refactoring and enhancements.
2024-07-16 12:24:30 +00: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
8bee33fa48
task: added flag to remove unsafe inline style src header (#7566)
Our CSP reports that unsafe-inline is not recommended for styleSrc. This
PR adds a flag for making it possible to remove this element of our CSP
headers. It should allow us to see what (if anything) breaks hard.
2024-07-10 14:36:28 +02:00
Mateusz Kwasniewski
3fe110f155
feat: exclude archived features in max reporting (#7559) 2024-07-10 09:11:22 +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
Thomas Heartman
e2c6d468e4
Chore: use createApiTokenService instead of newing it up (#7560)
PR #7519 introduced the pattern of using `createApiTokenService` instead
of newing it up. This usage was introduced in a concurrent PR (#7503),
so we're just cleaning up and making the usage consistent.
2024-07-09 14:11:56 +02:00
David Leek
2e5d81cb89
chore: delete project api tokens when last mapped project is removed (#7503)
Deletes API tokens bound to specific projects when the last project they're mapped to is deleted.

---------

Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com>
Co-authored-by: Thomas Heartman <thomas@getunleash.io>
2024-07-09 13:49:26 +02:00
Mateusz Kwasniewski
7ca2ace0bc
feat: constraints limit in a strategy (#7554) 2024-07-08 11:02:22 +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
Alexandru Savin
9fae7801ed
feat: New Relic integration (#7492)
## About the changes
Add New Relic integration based on issue #878.


![image](https://github.com/Unleash/unleash/assets/1612455/05523b73-398b-413d-b760-26bf2feec2db)


![image](https://github.com/Unleash/unleash/assets/1612455/1ec01f52-0c1a-46a7-aa5b-5ca80004dcf8)


<!-- 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 #878
2024-07-05 15:16:00 +02:00
Simon Hornby
2e205fc14e
chore: make sdk metrics snake case (#7547) 2024-07-05 12:29:00 +02:00
Thomas Heartman
59d6014853
Chore: add limits to feature flags (#7536)
This PR adds a feature flag limit to Unleash. It's set up to be
overridden in Enterprise, where we turn the limit up.

I've also fixed a couple bugs in the fake feature flag store.
2024-07-04 11:00:11 +02:00
Simon Hornby
30073d527a
feat: extended SDK metrics (#7527)
This adds an extended metrics format to the metrics ingested by Unleash
and sent by running SDKs in the wild. Notably, we don't store this
information anywhere new in this PR, this is just streamed out to
Victoria metrics - the point of this project is insight, not analysis.

Two things to look out for in this PR:

- I've chosen to take extend the registration event and also send that
when we receive metrics. This means that the new data is received on
startup and on heartbeat. This takes us in the direction of collapsing
these two calls into one at a later point
- I've wrapped the existing metrics events in some "type safety", it
ain't much because we have 0 type safety on the event emitter so this
also has some if checks that look funny in TS that actually check if the
data shape is correct. Existing tests that check this are more or less
preserved
2024-07-04 08:51:27 +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
e9b643761c
feat: Project limit UI (#7518) 2024-07-02 15:29:58 +02:00
Thomas Heartman
b2522f9199
feat: add resource limits for API tokens (#7510)
This PR adds the back end for API token resource limits. 

It adds the limit to the schema and checks the limit in the service.

## Discussion points

The PAT service uses a different service and different store entirely,
so I have not included testing any edge cases where PATs are included.
However, that could be seen as "knowing too much". We could add tests
that check both of the stores in tandem, but I think it's overkill for
now.
2024-07-02 12:41:31 +00:00
Mateusz Kwasniewski
8a9535d352
feat: projects limit (#7514) 2024-07-02 12:03:00 +02:00
Thomas Heartman
be518af228
feat: use new environment limit in Unleash UI (#7500)
This PR updates the Unleash UI to use the new environment limit.

As it turns out, we already had an environment limit in the UI, but it
was hardcoded (luckily, its value is the same as the new default value
🥳).

In addition to the existing places this limit was used, it also disables
the "new environment" button if you've reached the limit. Because this
limit already exists, I don't think we need a flag for it. The only
change is that you can't click a button (that should be a link!) that
takes you to a page you can't do anything on.
2024-07-02 06:14:15 +00:00
Mateusz Kwasniewski
054b44a8dd
feat: allow enterprise override for constraint values limit (#7502) 2024-07-01 15:45:13 +02:00
Mateusz Kwasniewski
57b253c050
feat: constraint values limit UI (#7501) 2024-07-01 15:05:44 +02:00
Mateusz Kwasniewski
2cfd71f34e
feat: constraint values limit (#7498) 2024-07-01 13:28:30 +02:00
Thomas Heartman
441c399f58
feat: add environments to resource limit schema (#7495)
This PR adds limits for environments to the resource limit schema. The
actual limiting will have to be done in Enterprise, however, so this is
just laying the groundwork.
2024-07-01 11:20:22 +02:00
Mateusz Kwasniewski
3525928fea
feat: configurable strategies limit (#7488) 2024-07-01 10:03:26 +02:00
Mateusz Kwasniewski
eaf68af2da
test: remove last seen at assertion (#7487) 2024-06-28 15:18:16 +02:00
Mateusz Kwasniewski
5bd32f264d
feat: strategy limit to 30 (#7473) 2024-06-28 11:18:44 +02:00
Christopher Kolstad
fbda7cdc48
chore: sync dependencies with enterprise (#7482)
As the title says. We had some mismatch in our dependencies where
enterprise was ahead of oss, and some places where oss was ahead of
enterprise. Hence
https://github.com/ivarconr/unleash-enterprise/pull/1419 and this PR
2024-06-28 10:54:37 +02:00
Thomas Heartman
95359ecff8
fix: cap project ids to 90 characters (without suffix) (#7481)
This fixes the issue where project names that are 100 characters long
or longer would cause the project creation to fail. This is because
the resulting ID would be longer than the 100 character limit imposed
by the back end.

We solve this by capping the project ID to 90 characters, which leaves
us with 10 characters for the suffix, meaning you can have 1 billion
projects (999,999,999 + 1) that start with the same 90
characters (after slugification) before anything breaks.

It's a little shorter than what it strictly has to be (we could
probably get around with 95 characters), but at this point, you're
reaching into edge case territory anyway, and I'd rather have a little
too much wiggle room here.
2024-06-28 09:25:27 +02:00
Mateusz Kwasniewski
b67c73a578
chore: resource limits flag (#7471) 2024-06-27 14:25:07 +02:00