Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Add a way to customize the completion result #82

Merged
merged 5 commits into from Dec 4, 2020

Conversation

Nexucis
Copy link
Member

@Nexucis Nexucis commented Nov 16, 2020

This PR provides a way to inject a custom completion. It won't override the current completion but will enrich it instead.
It will be possible to trigger the custom completion for a certain kind of completion (like only when the system will autocomplete the aggregation)

related to prometheus/prometheus#8174

@Nexucis Nexucis requested a review from juliusv November 16, 2020 06:52
@Nexucis Nexucis force-pushed the feature/enrich-completion branch 2 times, most recently from cbbbb51 to c67931d Compare November 24, 2020 14:22
README.md Outdated
@@ -66,6 +66,47 @@ In case you would like to deactivate the linter and/or the autocompletion it's s
const promQL = new PromQLExtension().activateLinter(false).activateCompletion(false) // here the linter and the autocomplete are deactivated
```

### maxMetricsMetadata

maxMetricsMetadata is the maximum limit of the number of metrics in Prometheus. Under this limit, it allows the completion to get the metadata of the metrics.
Copy link
Member

Choose a reason for hiding this comment

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

People may confuse this with autocompletion limits for metric names themselves, how about:

Suggested change
maxMetricsMetadata is the maximum limit of the number of metrics in Prometheus. Under this limit, it allows the completion to get the metadata of the metrics.
`maxMetricsMetadata` is the maximum number of metrics in Prometheus for which metadata is fetched. If the number of metrics exceeds this limit, no metric metadata is fetched at all.

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 for your correction !

src/lang-promql/complete/hybrid.ts Outdated Show resolved Hide resolved
src/lang-promql/complete/hybrid.ts Show resolved Hide resolved
src/lang-promql/complete/index.ts Outdated Show resolved Hide resolved
httpErrorHandler?: (error: any) => void;
fetchFn?: FetchFn;
// When providing this custom PrometheusClient, the settings above will not be used.
prometheusClient?: PrometheusClient;
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't have to be in this PR, but would it now make more sense to package the url ... fetchFn fields into their own PrometheusConfig, and then just define the remote field as: remote: PrometheusConfig | PrometheusClient? Or something like that. Then TypeScript will prevent invalid configuration combinations and things would be clearer.

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 won't mind to do it, I would just be sure, it won't be annoying to use. I mean if I want to change just the url, then I have to create the struct:

{
  remote: {
    PrometheusConfig: {
      url: 'http://prometheus.land'
    }
  }
}

Don't know if it will bother developer to have so much different interface, just to configure an url.
What do you think ?

Copy link
Member

Choose a reason for hiding this comment

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

The middle step would be left out if you do it like I suggest above:

{
  remote: {
    url: 'http://prometheus.land'
  }
}

TypeScript would automatically notice that I'm now passing in something that satisfies the interface PrometheusConfig, not PrometheusClient. Of course then the url field should be marked mandatory in PrometheusConfig.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yeah ok, I see what you meant. Nice thanks, will do that

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Nexucis and others added 2 commits December 4, 2020 13:37
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
Co-authored-by: Julius Volz <julius.volz@gmail.com>
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
@Nexucis
Copy link
Member Author

Nexucis commented Dec 4, 2020

@juliusv many thanks for your review. I think I changes everything you asked. Tell me if you are ok know with the changes

@juliusv
Copy link
Member

juliusv commented Dec 4, 2020

👍 Thanks!

@juliusv juliusv merged commit 44e5008 into master Dec 4, 2020
@juliusv juliusv deleted the feature/enrich-completion branch December 4, 2020 14:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants