Skip to content

Commit

Permalink
Fix metris endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Mar 29, 2022
1 parent 799dea8 commit b9d5ded
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions web/org/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,18 @@ func init() {
}

const groupCountsSQL = `
SELECT
g.id AS id,
g.name AS name,
g.uuid AS uuid,
g.group_type AS group_type,
COALESCE(SUM(c.count), 0) AS count
FROM
contacts_contactgroup g
LEFT OUTER JOIN
contacts_contactgroupcount c
ON
c.group_id = g.id
WHERE
g.org_id = $1 AND
g.is_active = TRUE
GROUP BY
g.id;
`
SELECT g.id, g.name, g.uuid, g.is_system, COALESCE(SUM(c.count), 0) AS count
FROM contacts_contactgroup g
LEFT OUTER JOIN contacts_contactgroupcount c ON c.group_id = g.id
WHERE g.org_id = $1 AND g.is_active = TRUE
GROUP BY g.id;`

type groupCountRow struct {
ID models.GroupID `db:"id"`
Name string `db:"name"`
UUID assets.GroupUUID `db:"uuid"`
Type string `db:"group_type"`
Count int64 `db:"count"`
ID models.GroupID `db:"id"`
Name string `db:"name"`
UUID assets.GroupUUID `db:"uuid"`
IsSystem bool `db:"is_system"`
Count int64 `db:"count"`
}

func calculateGroupCounts(ctx context.Context, rt *runtime.Runtime, org *models.OrgReference) (*dto.MetricFamily, error) {
Expand All @@ -70,26 +57,26 @@ func calculateGroupCounts(ctx context.Context, rt *runtime.Runtime, org *models.
}

groupType := "user"
if row.Type != "U" {
if row.IsSystem {
groupType = "system"
}

family.Metric = append(family.Metric,
&dto.Metric{
Label: []*dto.LabelPair{
&dto.LabelPair{
{
Name: proto.String("group_name"),
Value: proto.String(row.Name),
},
&dto.LabelPair{
{
Name: proto.String("group_uuid"),
Value: proto.String(string(row.UUID)),
},
&dto.LabelPair{
{
Name: proto.String("group_type"),
Value: proto.String(groupType),
},
&dto.LabelPair{
{
Name: proto.String("org"),
Value: proto.String(org.Name),
},
Expand Down

0 comments on commit b9d5ded

Please sign in to comment.