-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add metrics endpoints #665
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ const ( | |
|
||
const ( | ||
validityInterval postgresDuration = "1 days" | ||
defaultInterval time.Duration = time.Hour | ||
defaultInterval time.Duration = 2 * time.Hour | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change intentional here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup! This was just an issue with rebasing, see #666 |
||
) | ||
|
||
// Instance represents an instance running one or more applications for which | ||
|
@@ -651,7 +651,7 @@ func (api *API) GetDefaultInterval() time.Duration { | |
// that have been checked in during a given duration from a given time. | ||
func (api *API) instanceStatsQuery(t *time.Time, duration *time.Duration) *goqu.SelectDataset { | ||
if t == nil { | ||
now := time.Now() | ||
now := time.Now().UTC() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is done in #664, please rebase with main to avoid redoing this part. |
||
t = &now | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,12 @@ WHERE a.id = e.application_id AND e.event_type_id = et.id AND et.result = 0 AND | |
GROUP BY app_name | ||
ORDER BY app_name | ||
`, ignoreFakeInstanceCondition("e.instance_id")) | ||
|
||
latestInstanceStatsSQL string = ` | ||
SELECT channel_name, version, arch, timestamp, instances AS instances_count | ||
FROM instance_stats | ||
WHERE timestamp = (SELECT MAX(timestamp) FROM instance_stats) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing raw SQL here, could we add a new function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had this logic initially in |
||
` | ||
) | ||
|
||
type AppInstancesPerChannelMetric struct { | ||
|
@@ -77,6 +83,35 @@ func (api *API) GetFailedUpdatesMetrics() ([]FailedUpdatesMetric, error) { | |
return metrics, nil | ||
} | ||
|
||
type LatestInstanceStatsMetric struct { | ||
ChannelName string `db:"channel_name" json:"channel_name"` | ||
Version string `db:"version" json:"version"` | ||
Arch string `db:"arch" json:"arch"` | ||
Timestamp string `db:"timestamp" json:"timestamp"` | ||
InstancesCount int `db:"instances_count" json:"instances_count"` | ||
} | ||
|
||
func (api *API) GetLatestInstanceStatsMetrics() ([]LatestInstanceStatsMetric, error) { | ||
var metrics []LatestInstanceStatsMetric | ||
rows, err := api.db.Queryx(latestInstanceStatsSQL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer rows.Close() | ||
for rows.Next() { | ||
var metric LatestInstanceStatsMetric | ||
err := rows.StructScan(&metric) | ||
if err != nil { | ||
return nil, err | ||
} | ||
metrics = append(metrics, metric) | ||
} | ||
if err := rows.Err(); err != nil { | ||
return nil, err | ||
} | ||
return metrics, nil | ||
} | ||
|
||
func (api *API) DbStats() sql.DBStats { | ||
return api.db.Stats() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a response stream? And do we want to return (via stream) all the instance stats in this endpoint? I would suggest to use some form pagination instead of stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the goal is to output all instance stats here, and I agree with the pagination suggestion