Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/stats service #2211

Merged
merged 11 commits into from Oct 25, 2022
Merged

Feat/stats service #2211

merged 11 commits into from Oct 25, 2022

Conversation

ivarconr
Copy link
Member

@ivarconr ivarconr commented Oct 19, 2022

About the changes

This feature introduces instance stats to Unleash.

image

This makes it easier for admins to get an overview of the Unleash installation and also offer a download CSV file function, to make it shareable (e.g. with support)

All metrics are also exposed as Prometheus metrics for convenience.

@vercel
Copy link

vercel bot commented Oct 19, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Oct 24, 2022 at 6:02PM (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Oct 24, 2022 at 6:02PM (UTC)

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question about the signatures but I think this this looks great!

src/lib/services/instance-stats-service.ts Show resolved Hide resolved
src/lib/db/role-store.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Some minor details and clarifications, otherwise looks super clean!

</TableHead>
<TableBody>
{rows.map(row => (
<TableRow >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a key, technically since you can't mutate the state and the order is guaranteed it doesn't matter. But it would be good to promote best practices.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍🏼

Maybe prettier could warn about this?


export const InstanceAdmin = () => {
return (
<div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should InstanceStats be available for everyone in the system? Currently we don't gate the stats for Admins only.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the intention, all users with access should be able to access it for now, as there is not secrets here. All stats will be implicitly available for read only users anyway (number of projects, feature toggles etc).

Comment on lines 17 to 38
if(stats?.versionEnterprise) {
versionTitle = 'Unleash Enterprise version';
version = stats.versionEnterprise;
} else {
versionTitle = 'Unleash OSS version';
version = stats?.versionOSS;
}



const rows = [
{title: 'Instance Id', value: stats?.instanceId},
{title: versionTitle, value: version},
{title: 'Users', value: stats?.users},
{title: 'Feature toggles', value: stats?.featureToggles},
{title: 'Projects', value: stats?.projects},
{title: 'Environments', value: stats?.environments},
{title: 'Roles', value: stats?.roles},
{title: 'Groups', value: stats?.groups},
{title: 'Context fields', value: stats?.contextFields},
{title: 'Strategies', value: stats?.strategies},
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Prettier seems to not be working correctly here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not gotten my IDE to work correctly with prettier after the merge. This is how it looks after auto-format of this file.

.count('*')
.where('type', 'custom')
.orWhere('type', 'project')
.then((res) => Number(res[0].count));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about this. I guess since it's count it always returns a row? But not every knex method does this, as far as I know. Sometimes this causes problems because people try to copy what they have seen elsewhere, and expect it to work the same. Not sure if we should do something about it, but I'm raising the point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In knex a count() will return a result of type: Record<string, number | string>. So we know it will be a single row with a "key" named "count" and the value to be a number or a stringed number (42 vs "42").

method: 'get',
path: '/statistics',
handler: this.getStatistics,
permission: NONE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is intentional.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@ivarconr
Copy link
Member Author

I have addressed all feedback @FredrikOseberg

Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ivarconr ivarconr merged commit cf4fc23 into main Oct 25, 2022
@ivarconr ivarconr deleted the feat/stats-service branch October 25, 2022 11:10
sighphyre pushed a commit that referenced this pull request Oct 27, 2022
Introduces an instance stats service exposing usage metrics of the Unleash installation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants