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

[Stack Monitoring] Converts logstash api routes to typescript #131946

Merged

Conversation

crespocarlos
Copy link
Contributor

@crespocarlos crespocarlos commented May 10, 2022

Summary

This converts the logstash api routes to TypeScript.

closes #117763

Additional nodes

Logstash api folder has a sub directory called pipelines. I'm not sure if we should keep it like thas, but I didn't change the folder structure. I've decided not to create a subdirectory in the new http_api directory structure to add the new type definitions.

@crespocarlos crespocarlos requested a review from a team as a code owner May 10, 2022 15:43
@@ -142,6 +142,14 @@ export interface ElasticsearchIndexStats {
};
}

export interface ElasticsearchLogstashStatePipeline {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've created this type to improve the return type readability on getPipeline function

return getLogstashForClusters(req, clusters).then((clusterStatus) =>
get(clusterStatus, '[0].stats')
return getLogstashForClusters(req, clusters).then(
(clusterStatus) => clusterStatus && clusterStatus[0]?.stats
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've seen lodash being removed somewhere else. I thinks this way is safe

Copy link
Contributor

Choose a reason for hiding this comment

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

There was no defaultValue passed to get so this LGTM.


try {
const [pipeline, vertex] = await Promise.all(promises);
const [pipeline, vertex] = await Promise.all([
Copy link
Contributor Author

@crespocarlos crespocarlos May 10, 2022

Choose a reason for hiding this comment

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

This is like this so that ts can be able to infer the correct type of pipeline and vertex

} from '../../../../../../common/http_api/logstash';

const throughputMetric = 'logstash_cluster_pipeline_throughput';
const nodesCountMetric = 'logstash_cluster_pipeline_node_count';
Copy link
Contributor Author

@crespocarlos crespocarlos May 10, 2022

Choose a reason for hiding this comment

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

Previously, this was logstash_cluster_pipeline_nodes_count. However this is not a valid type (see: here). So we need to either include logstash_cluster_pipeline_nodes_count to the union or use a valid option here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually had to add logstash_cluster_pipeline_nodes_count to PipelineNodeCountMetricKey. The endpoint was returning 500 when logstash_cluster_pipeline_node_count was passed

} from '../../../../../../common/http_api/logstash';

const throughputMetric = 'logstash_node_pipeline_throughput';
const nodesCountMetric = 'logstash_node_pipeline_node_count';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, this was logstash_node_pipeline_nodes_count. However this is not a valid type (see: here). So we need to either include logstash_node_pipeline_nodes_count to the union or use a valid option here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually had to add logstash_node_pipeline_nodes_count to PipelineNodeCountMetricKey. The endpoint was returning 500 when logstash_node_pipeline_nodes_count was passed

@crespocarlos crespocarlos added the backport:skip This commit does not require backporting label May 10, 2022
@crespocarlos crespocarlos changed the title converts logstash api routes to typescript [Stack Monitoring] Converts logstash api routes to typescript May 10, 2022
@crespocarlos crespocarlos added Feature:Stack Monitoring release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services labels May 10, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/infra-monitoring-ui (Team:Infra Monitoring UI)

rt.partial({
ccs: ccsRT,
sort: sortingRT,
queryText: rt.string,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original type had a default value of '' when queryText was not sent. Should we have this validation here?

Copy link
Contributor

Choose a reason for hiding this comment

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

As queryText can sometimes not be sent, having it as optional here on the io-ts request payload type seems accurate to me. Imo, it should fall to other functions to then check for that and hand what is needed to other call sites.

@crespocarlos
Copy link
Contributor Author

@elasticmachine merge upstream

@Kerry350 Kerry350 self-requested a review May 18, 2022 16:07
@crespocarlos crespocarlos force-pushed the 117763-covert-logstash-routes-ts branch from a4b3621 to 411fc59 Compare May 18, 2022 16:33
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

  • 💚 Build #44188 succeeded a4b36212f8d29a76f05d5d50b7c73b610d13c2b2
  • 💚 Build #44113 succeeded 6f16993416a9c2c978d25255dde76d50f2c2db0f
  • 💔 Build #44015 failed 8860b61a99db3d3c55c83e50de0ceb39b864e64b
  • 💔 Build #43944 failed b9552f66c15794ccf5ea1ad8ca8a0fb5fe25602f
  • 💔 Build #43760 failed 87f5c58b66d9a7cdc97809b9e27a014e64162bfd

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@Kerry350 Kerry350 left a comment

Choose a reason for hiding this comment

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

Great work, LGTM 🙌

Thanks for the additional improvements (removing Lodash and so on).

rt.partial({
ccs: ccsRT,
sort: sortingRT,
queryText: rt.string,
Copy link
Contributor

Choose a reason for hiding this comment

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

As queryText can sometimes not be sent, having it as optional here on the io-ts request payload type seems accurate to me. Imo, it should fall to other functions to then check for that and hand what is needed to other call sites.

return getLogstashForClusters(req, clusters).then((clusterStatus) =>
get(clusterStatus, '[0].stats')
return getLogstashForClusters(req, clusters).then(
(clusterStatus) => clusterStatus && clusterStatus[0]?.stats
Copy link
Contributor

Choose a reason for hiding this comment

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

There was no defaultValue passed to get so this LGTM.

@crespocarlos crespocarlos merged commit fa607d1 into elastic:main May 19, 2022
@crespocarlos crespocarlos deleted the 117763-covert-logstash-routes-ts branch May 19, 2022 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Stack Monitoring release_note:skip Skip the PR/issue when compiling release notes Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Stack Monitoring] Convert files in server/routes/logstash to typescript
4 participants