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

feat: add Elastic metrics provider #3741

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Bharadwajshivam28
Copy link
Contributor

@Bharadwajshivam28 Bharadwajshivam28 commented Oct 2, 2024

Description

fixes #3727

Hey @mowies I have started creating custom KeptnMetricsProvider for Elastic and now I have integrated some methods.

For now the methods purpose are-

  • NewElasticProvider: Creates a new KeptnElasticProvider with an Elasticsearch client.
  • FetchAnalysisValue: Runs a query to get analysis results and returns the metric value.
  • EvaluateQuery: Runs a metric query for the last 30 minutes and returns the metric value.
  • runElasticQuery: Executes a query on Elasticsearch and returns the result.
  • extractMetric: Gets the metric value from the Elasticsearch result.

@Bharadwajshivam28 Bharadwajshivam28 requested a review from a team as a code owner October 2, 2024 00:15
@mowies mowies changed the title feat: Integrating ELK provider feat: add Elastic metrics provider Oct 2, 2024
Copy link
Member

@mowies mowies left a comment

Choose a reason for hiding this comment

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

good start so far!
could you please fix the spell check issues?
you'll find instructions on how to do it in the failing check's summary

metrics-operator/go.mod Outdated Show resolved Hide resolved
@mowies
Copy link
Member

mowies commented Oct 2, 2024

also, if you can, please provide some unit tests for your new code :)

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.77%. Comparing base (8eb878f) to head (8daeb28).

❗ There is a different number of reports uploaded between BASE (8eb878f) and HEAD (8daeb28). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (8eb878f) HEAD (8daeb28)
metrics-operator 1 0
lifecycle-operator 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3741       +/-   ##
===========================================
- Coverage   74.72%   51.77%   -22.95%     
===========================================
  Files         225       42      -183     
  Lines       10160     2445     -7715     
===========================================
- Hits         7592     1266     -6326     
+ Misses       2198     1021     -1177     
+ Partials      370      158      -212     

see 196 files with indirect coverage changes

Flag Coverage Δ
certificate-operator 47.20% <ø> (ø)
component-tests 58.77% <ø> (+0.73%) ⬆️
lifecycle-operator ?
metrics-operator ?
scheduler 34.59% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Contributor

@odubajDT odubajDT left a comment

Choose a reason for hiding this comment

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

Thank you for the initial version! Can you please provide some tests?

ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()

result, err := r.runElasticQuery(ctx, metric.Spec.Query, time.Now().Add(-30*time.Minute), time.Now())
Copy link
Contributor

Choose a reason for hiding this comment

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

do we always want to have exactly the last 30min time slot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for now it's hardcoded but we can make it passed dynamically btw looking for your feedback on the right way?

Copy link
Contributor

Choose a reason for hiding this comment

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

let's make it dynamic please

}

func (r *KeptnElasticProvider) extractMetric(result map[string]interface{}) (string, error) {
hits, ok := result["hits"].(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

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

does the response have a standardized format? maybe we can create a struct and unmarshall to it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay let me check on it

@github-actions github-actions bot added the ops label Oct 3, 2024
@Bharadwajshivam28
Copy link
Contributor Author

Hey @mowies @odubajDT I have created test cases for the methods in elk provider. In short-

  • TestNewElasticProvider- Tests the NewElasticProvider method
  • TestKeptnElasticProvider_FetchAnalysisValue- Tests the FetchAnalysisValue method
  • TestKeptnElasticProvider_EvaluateQuery- Tests the EvaluateQuery method
  • TestKeptnElasticProvider_runElasticQuery- Tests the runElasticQuery method
  • TestKeptnElasticProvider_extractMetric- Tests the extractMetric method

Copy link

sonarcloud bot commented Oct 8, 2024

elasticURL,
},
}
es, err := elastic.NewClient(cfg)
Copy link
Contributor

Choose a reason for hiding this comment

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

does elastic have a mock library? if yes, let's try to use it for testing. if not, maybe we can create an interface and try to mock the elastic to improve the testing, WDYT?

_, _ = w.Write([]byte(response))
}))
defer server.Close()

Copy link
Contributor

Choose a reason for hiding this comment

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

let's try to mock the elastic to make the testing easier for multiple testing scenarios

Copy link
Contributor

@odubajDT odubajDT left a comment

Choose a reason for hiding this comment

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

Thanks for the contributions, please see the additional comments on the code. One question tho, did you manually tried the implementation with Keptn? Seems to me that currently won't work, as the new provider is not present in the list of supported providers. If possible please add it and try it out manually.

Also additional question, would it be possible to create a full e2e test for the provider? Would be awesome if we could be able to test it as part of our CI

@Bharadwajshivam28
Copy link
Contributor Author

Thanks for the contributions, please see the additional comments on the code. One question tho, did you manually tried the implementation with Keptn? Seems to me that currently won't work, as the new provider is not present in the list of supported providers. If possible please add it and try it out manually.

Also additional question, would it be possible to create a full e2e test for the provider? Would be awesome if we could be able to test it as part of our CI

ya I can create full e2e test for the provider btw can you brief me above lines I didn't understood this "manually tried the implementation with Keptn"

@odubajDT
Copy link
Contributor

odubajDT commented Oct 9, 2024

Thanks for the contributions, please see the additional comments on the code. One question tho, did you manually tried the implementation with Keptn? Seems to me that currently won't work, as the new provider is not present in the list of supported providers. If possible please add it and try it out manually.
Also additional question, would it be possible to create a full e2e test for the provider? Would be awesome if we could be able to test it as part of our CI

ya I can create full e2e test for the provider btw can you brief me above lines I didn't understood this "manually tried the implementation with Keptn"

What I mean is using the elastic metric provider with Keptn, this means setting up an application, monitor it and fetch some data with the elastic metrics provider, used the data for Evaluations and then use Keptn to deploy the application.

@Bharadwajshivam28
Copy link
Contributor Author

Bharadwajshivam28 commented Oct 9, 2024

Thanks for the contributions, please see the additional comments on the code. One question tho, did you manually tried the implementation with Keptn? Seems to me that currently won't work, as the new provider is not present in the list of supported providers. If possible please add it and try it out manually.
Also additional question, would it be possible to create a full e2e test for the provider? Would be awesome if we could be able to test it as part of our CI

ya I can create full e2e test for the provider btw can you brief me above lines I didn't understood this "manually tried the implementation with Keptn"

What I mean is using the elastic metric provider with Keptn, this means setting up an application, monitor it and fetch some data with the elastic metrics provider, used the data for Evaluations and then use Keptn to deploy the application.

The thing is I am not familiar with elk much so can it be like once pr is merged then users who use elk can use it?

I am familiar with code part implementation and till now I feel the provider is mostly correct and the test cases also just a minor change required.

@odubajDT
Copy link
Contributor

odubajDT commented Oct 9, 2024

Thanks for the contributions, please see the additional comments on the code. One question tho, did you manually tried the implementation with Keptn? Seems to me that currently won't work, as the new provider is not present in the list of supported providers. If possible please add it and try it out manually.
Also additional question, would it be possible to create a full e2e test for the provider? Would be awesome if we could be able to test it as part of our CI

ya I can create full e2e test for the provider btw can you brief me above lines I didn't understood this "manually tried the implementation with Keptn"

What I mean is using the elastic metric provider with Keptn, this means setting up an application, monitor it and fetch some data with the elastic metrics provider, used the data for Evaluations and then use Keptn to deploy the application.

The thing is I am not familiar with elk much so can it be like once pr is merged then users who use elk can use it?

I am familiar with code part implementation and till now I feel the provider is mostly correct and the test cases also just a minor change required.

I understand, but part of the implementation should be a e2e/integration test, which will require to deploy the provider and test the correct functioning of the provider with Keptn. In this case I would suggest getting in contact with the author of the issue regarding some more guidance about deploying and using the provider. Therefore we can verify the correct functionality of the provider and potentially also add some configurable parameters, that are needed in the provider.

Another option for the e2e test might be to use mock-server for mocking the responses of the provider, like it's done here. Therefore there is no need for you to actually deploy the provider locally. Please have a look at this option.

In that case, we can maybe ask the author of the issue @arkaonline to test the implementation for us once it's ready and merged before actually releasing the feature. But the e2e test mocking the provider is still needed and the PR shouldn't be merged without it.

@Bharadwajshivam28
Copy link
Contributor Author

Thanks for the contributions, please see the additional comments on the code. One question tho, did you manually tried the implementation with Keptn? Seems to me that currently won't work, as the new provider is not present in the list of supported providers. If possible please add it and try it out manually.
Also additional question, would it be possible to create a full e2e test for the provider? Would be awesome if we could be able to test it as part of our CI

ya I can create full e2e test for the provider btw can you brief me above lines I didn't understood this "manually tried the implementation with Keptn"

What I mean is using the elastic metric provider with Keptn, this means setting up an application, monitor it and fetch some data with the elastic metrics provider, used the data for Evaluations and then use Keptn to deploy the application.

The thing is I am not familiar with elk much so can it be like once pr is merged then users who use elk can use it?

I am familiar with code part implementation and till now I feel the provider is mostly correct and the test cases also just a minor change required.

I understand, but part of the implementation should be a e2e/integration test, which will require to deploy the provider and test the correct functioning of the provider with Keptn. In this case I would suggest getting in contact with the author of the issue regarding some more guidance about deploying and using the provider. Therefore we can verify the correct functionality of the provider and potentially also add some configurable parameters, that are needed in the provider.

Another option for the e2e test might be to use mock-server for mocking the responses of the provider, like it's done here. Therefore there is no need for you to actually deploy the provider locally. Please have a look at this option.

In that case, we can maybe ask the author of the issue @arkaonline to test the implementation for us once it's ready and merged before actually releasing the feature. But the e2e test mocking the provider is still needed and the PR shouldn't be merged without it.

Okay so let me go through these and first create the e2e test mocking feature. Also yes the issue author can help us to test the full provider.

@arkaonline
Copy link

@Bharadwajshivam28 @odubajDT I can surely help you test it out.
Please share with me the ELK provider files that needs to be added and the steps I need to add them.
Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

@odubajDT
Copy link
Contributor

odubajDT commented Oct 9, 2024

@Bharadwajshivam28 @odubajDT I can surely help you test it out. Please share with me the ELK provider files that needs to be added and the steps I need to add them. Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

Thank you! Yes you are right, we are missing multiple places now. When the implementation will be ready for testing, we will reach out to you. :-)

@Bharadwajshivam28
Copy link
Contributor Author

@Bharadwajshivam28 @odubajDT I can surely help you test it out. Please share with me the ELK provider files that needs to be added and the steps I need to add them. Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

Thank you! Yes you are right, we are missing multiple places now. When the implementation will be ready for testing, we will reach out to you. :-)

so for now I think I should make the e2e tests ready and then @arkaonline can help us in testing the provider once the code is merged?

CC- @odubajDT

@odubajDT
Copy link
Contributor

odubajDT commented Oct 9, 2024

@Bharadwajshivam28 @odubajDT I can surely help you test it out. Please share with me the ELK provider files that needs to be added and the steps I need to add them. Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

Thank you! Yes you are right, we are missing multiple places now. When the implementation will be ready for testing, we will reach out to you. :-)

so for now I think I should make the e2e tests ready and then @arkaonline can help us in testing the provider once the code is merged?

CC- @odubajDT

First, the implementation needs to be finished and covered by unit tests, afterwards we should aim for a integration/e2e test with using the mock server. When this is finished, we can ask @arkaonline to test Keptn with the new provider and afterwards we can proceed with merging the PR.

@Bharadwajshivam28
Copy link
Contributor Author

@Bharadwajshivam28 @odubajDT I can surely help you test it out. Please share with me the ELK provider files that needs to be added and the steps I need to add them. Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

Thank you! Yes you are right, we are missing multiple places now. When the implementation will be ready for testing, we will reach out to you. :-)

so for now I think I should make the e2e tests ready and then @arkaonline can help us in testing the provider once the code is merged?

CC- @odubajDT

First, the implementation needs to be finished and covered by unit tests, afterwards we should aim for a integration/e2e test with using the mock server. When this is finished, we can ask @arkaonline to test Keptn with the new provider and afterwards we can proceed with merging the PR.

Okay cool so I will Focus on the unit tests and e2e test with the mock server.

Also can you please share some information to start with the e2e test?

@odubajDT
Copy link
Contributor

odubajDT commented Oct 9, 2024

@Bharadwajshivam28 @odubajDT I can surely help you test it out. Please share with me the ELK provider files that needs to be added and the steps I need to add them. Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

Thank you! Yes you are right, we are missing multiple places now. When the implementation will be ready for testing, we will reach out to you. :-)

so for now I think I should make the e2e tests ready and then @arkaonline can help us in testing the provider once the code is merged?
CC- @odubajDT

First, the implementation needs to be finished and covered by unit tests, afterwards we should aim for a integration/e2e test with using the mock server. When this is finished, we can ask @arkaonline to test Keptn with the new provider and afterwards we can proceed with merging the PR.

Okay cool so I will Focus on the unit tests and e2e test with the mock server.

Also can you please share some information to start with the e2e test?

You should use chainsaw and mock-server how it's done for example here

@Bharadwajshivam28
Copy link
Contributor Author

@Bharadwajshivam28 @odubajDT I can surely help you test it out. Please share with me the ELK provider files that needs to be added and the steps I need to add them. Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

Thank you! Yes you are right, we are missing multiple places now. When the implementation will be ready for testing, we will reach out to you. :-)

so for now I think I should make the e2e tests ready and then @arkaonline can help us in testing the provider once the code is merged?
CC- @odubajDT

First, the implementation needs to be finished and covered by unit tests, afterwards we should aim for a integration/e2e test with using the mock server. When this is finished, we can ask @arkaonline to test Keptn with the new provider and afterwards we can proceed with merging the PR.

Okay cool so I will Focus on the unit tests and e2e test with the mock server.

Also can you please share some information to start with the e2e test?

You should use chainsaw and mock-server how it's done for example here

Okay so this for the e2e test right?

@Bharadwajshivam28
Copy link
Contributor Author

Bharadwajshivam28 commented Oct 9, 2024

@Bharadwajshivam28 @odubajDT I can surely help you test it out. Please share with me the ELK provider files that needs to be added and the steps I need to add them. Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

Thank you! Yes you are right, we are missing multiple places now. When the implementation will be ready for testing, we will reach out to you. :-)

so for now I think I should make the e2e tests ready and then @arkaonline can help us in testing the provider once the code is merged?
CC- @odubajDT

First, the implementation needs to be finished and covered by unit tests, afterwards we should aim for a integration/e2e test with using the mock server. When this is finished, we can ask @arkaonline to test Keptn with the new provider and afterwards we can proceed with merging the PR.

Okay cool so I will Focus on the unit tests and e2e test with the mock server.

Also can you please share some information to start with the e2e test?

You should use chainsaw and mock-server how it's done for example here

Okay so this for the e2e test right?

Hey @odubajDT I saw the e2e test files you shared so I had one question:

can you please give me information about getting started on e2e tests implementation for the provider I am creating?

@odubajDT
Copy link
Contributor

odubajDT commented Oct 9, 2024

@Bharadwajshivam28 @odubajDT I can surely help you test it out. Please share with me the ELK provider files that needs to be added and the steps I need to add them. Also , I believe "Elastic" has to be added as supported provider name in helmchart . is that right ?

Thank you! Yes you are right, we are missing multiple places now. When the implementation will be ready for testing, we will reach out to you. :-)

so for now I think I should make the e2e tests ready and then @arkaonline can help us in testing the provider once the code is merged?
CC- @odubajDT

First, the implementation needs to be finished and covered by unit tests, afterwards we should aim for a integration/e2e test with using the mock server. When this is finished, we can ask @arkaonline to test Keptn with the new provider and afterwards we can proceed with merging the PR.

Okay cool so I will Focus on the unit tests and e2e test with the mock server.
Also can you please share some information to start with the e2e test?

You should use chainsaw and mock-server how it's done for example here

Okay so this for the e2e test right?

Hey @odubajDT I saw the e2e test files you shared so I had one question:

can you please give me information about getting started on e2e tests implementation for the provider I am creating?

Sure, please have a look at the testing framework we are using and also on mock-server. With the example I pointed you into that should get you going

@mowies
Copy link
Member

mowies commented Oct 14, 2024

@Bharadwajshivam28 any updates on this?

@Bharadwajshivam28
Copy link
Contributor Author

Bharadwajshivam28 commented Oct 14, 2024

@Bharadwajshivam28 any updates on this?

I am working on this and will finish the logic and unit tests by today and for the e2e tests I will make it finish in upcoming 1-2 days.

The provider is completed and the unit test also I need to just work on the e2e tests

} `json:"hits"`
}

func NewElasticProvider(log logr.Logger, k8sClient client.Client, elasticURL string) (*KeptnElasticProvider, error) {
Copy link
Contributor

@odubajDT odubajDT Oct 23, 2024

Choose a reason for hiding this comment

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

where is this code actually used? Currently it isn't used anywhere, therefore it has no impact on the functionality (dead code). Please add the appropiate changes in the providers factory and also in the KeptnMetricsProvider CRD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrating Keptn with ELK Stack
4 participants