Conversation
7cb2fd7 to
274f205
Compare
2e6dc8b to
00ddefe
Compare
yolossn
left a comment
There was a problem hiding this comment.
Left few comments, overall the prometheus metrics endpoint looks good.
| 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.
Instead of doing raw SQL here, could we add a new function GetInstanceStatsLatest in pkg/api/instances.go and use that? This would also allow to add a test for this new function.
There was a problem hiding this comment.
I had this logic initially in pkg/api/instances.go but decided to follow the convention above, though I agree with this suggestion
|
I have left an update in my project doc for you guys to go through regarding my progress as my internship has concluded and I have started the fall semester at my university I'm unable to make changes with my current setup but happy to follow along with the work on Nebraska! |
00ddefe to
f467768
Compare
8ec2d7e to
3393366
Compare
|
Relates to #566 |
c675bb0 to
0451999
Compare
|
I wanted to add a test for |
0451999 to
d4ee581
Compare
Pull request #656 adds the necessary instance_stats database table as well as functions for querying instance counts (by channel, version, and architecture) from the groups, instance, and instance_application tables and storing the results in the new table. To make this data accessible outside Nebraska, we create the following: - Prometheus metrics endpoint: A new HTTP endpoint (instance-metrics/prometheus) that serves only the latest snapshot from the instance_stats table. As Prometheus is a time-series database, this serves instance counts with the latest timestamp only. - JSON metrics data endpoint: A new HTTP endpoint that emits all instance_stats data in JSON format. The difference here is that we query for all data, and we emit one JSON document per row.
d4ee581 to
35cba54
Compare
| type: string | ||
| "500": | ||
| description: Get latest instance stats error response | ||
| /instance-metrics/json: |
There was a problem hiding this comment.
I'm wondering if we need the json sub-path, especially if we also define the response content type as json
| /instance-metrics/json: | |
| /instance-metrics: |
There was a problem hiding this comment.
In this case, I would propose to keep /instance-metrics/json and use /instance-metrics for the Prometheus endpoint to get closer from the default /metrics endpoint.
| content: | ||
| application/x-ndjson: | ||
| schema: | ||
| $ref: "#/components/schemas/instanceStats" |
There was a problem hiding this comment.
should not this rather be referencing instanceStatsPage?
| $ref: "#/components/schemas/instanceStats" | |
| $ref: "#/components/schemas/instanceStatsPage" |
| } | ||
|
|
||
| // GetInstanceStatsCount returns the total number of InstanceStats. | ||
| func (api *API) GetInstanceStatsCount() (int, error) { |
There was a problem hiding this comment.
I noticed that the GetInstanceStats function accepts the perPage param as a uint64, but that is supposed to be a smaller number than the total count, and yet it reserves more memory, so there is a minor inconsistency in the usage of the types here, or am I wrong? Is go's default int type 32 bit?
There was a problem hiding this comment.
Good catch. Let's stick to int.
| From("instance_stats"). | ||
| Limit(limit). | ||
| Offset(offset). | ||
| Order(goqu.C("timestamp").Asc()). |
There was a problem hiding this comment.
I'm not sure if it matters or not, but is the ordering correct here? shouldn't we get the latest stats first?
| latestInstanceStatsSQL = ` | ||
| 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.
do we have a index on timestamp?
| 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"` |
There was a problem hiding this comment.
I guess it doesn't matter as we are just forwarding the value as text, but a go time type could also be used here if the driver supports the automatic conversion. Could be nice for later to change the presentation format of the timestamp.
| Count: len(metrics), | ||
| Metrics: m, | ||
| } | ||
| if err := json.NewEncoder(ctx.Response()).Encode(p); err != nil { |
There was a problem hiding this comment.
The usage of the application/x-ndjson type is unusual as x-ndljson used to be used in streaming scenarios when the payload is made of homogeneous items without a wrapper. A batch would look like
...
{"id":101,…}
{"id":102,…}
...
whereas here we have a wrapper for the batch
p := metricPage{
TotalCount: totalCount,
Count: len(metrics),
Metrics: m,
}I recommend using plain Content-Type: application/json
Pull request #656 adds the necessary
instance_statsdatabase table as well as functions for querying instance counts (by channel, version, and architecture) from thegroups,instance, andinstance_applicationtables and storing the results in the new table.To make this data accessible outside Nebraska, we create the following:
instance_statstable. As Prometheus is a time-series database, this serves instance counts with the latest timestamp only.instance_statsdata in JSON format. The difference here is that we query for all data, and we emit one JSON document per row.