lifecycle-toolkit icon indicating copy to clipboard operation
lifecycle-toolkit copied to clipboard

fix(metrics-operator): provide more information for dynatrace api error

Open Vickysomtee opened this issue 2 years ago • 20 comments

Description

This PR adds more information to the dynatrace api error response

Fixes #2790

How to test

Please describe how to run the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also provide information about any automatic tests that you added.

  • [ ] Manual Test A
  • [x] Unit Test B
  • [ ] Integration Test C

Checklist

  • [x] My PR fulfills the Definition of Done of the corresponding issue and not more (or parts if the issue is separated into multiple PRs)
  • [x] I used descriptive commit messages to help reviewers understand my thought process
  • [x] I signed off all my commits according to the Developer Certificate of Origin (DCO) see Contribution Guide
  • [x] My PR title is formatted according to the semantic PR conventions described in the Contribution Guide
  • [x] My code follows the style guidelines of this project (golangci-lint passes, YAMLLint passes)
  • [ ] I regenerated the auto-generated docs for Helm and the CRD documentation (if applicable)
  • [x] I have performed a self-review of my code
  • [ ] I have made corresponding changes to the documentation (if needed)
  • [ ] My changes result in all-green PR checks (first-time contributors need to ask a maintainer to approve their test runs)
  • [x] New and existing unit and integration tests pass locally with my changes

Vickysomtee avatar Jan 26 '24 07:01 Vickysomtee

Codecov Report

Attention: Patch coverage is 60.00000% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 85.32%. Comparing base (e048679) to head (131675f).

:exclamation: Current head 131675f differs from pull request most recent head b34e7ab. Consider uploading reports for the commit b34e7ab to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2885      +/-   ##
==========================================
- Coverage   85.36%   85.32%   -0.05%     
==========================================
  Files         167      167              
  Lines        7412     7412              
==========================================
- Hits         6327     6324       -3     
- Misses        798      800       +2     
- Partials      287      288       +1     
Files Coverage Δ
...ollers/common/providers/dynatrace/client/client.go 72.72% <60.00%> (ø)

... and 1 file with indirect coverage changes

Flag Coverage Δ
certificate-operator 69.23% <ø> (ø)
component-tests 58.53% <ø> (-0.25%) :arrow_down:
lifecycle-operator 83.46% <ø> (ø)
metrics-operator 88.32% <60.00%> (ø)
scheduler 34.74% <ø> (ø)

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

codecov[bot] avatar Jan 26 '24 11:01 codecov[bot]

Hey @Vickysomtee the ticket requests a Chainsaw test using mockserver, you can copy the implementation of this test but change it for a failing http response to show what would be printed by the operator.

The idea is that the mockserver configuration can return a bad http code, and the result of the operator for example a keptn metric should be the error message you added.

RealAnna avatar Feb 05 '24 12:02 RealAnna

Hey @Vickysomtee the ticket requests a Kuttl test using mockserver, you can copy the implementation of this test but change it for a failing http response to show what would be printed by the operator.

The idea is that the mockserver configuration can return a bad http code, and the result of the operator for example a keptn metric should be the error message you added.

@RealAnna can you check the link in your comment? It links to a folder. Did you intend to link to a folder or a file

Also, just to note, I didn't introduce new error message. I only added statusCode

Vickysomtee avatar Feb 06 '24 00:02 Vickysomtee

Hey @Vickysomtee indeed, I had in mind you changed also the printed message but apparently not... Anyhow line 106, 111 and 127 could use coverage by unit test. For the chainsaw test this is indeed a folder with multiple files, some file declare what the test wll install on the test environment and the other assert the expected result. YOu can have a look at how it works here

RealAnna avatar Feb 06 '24 08:02 RealAnna

Hi @Vickysomtee, any news on this one? feel free to reach out if you have any questions

bacherfl avatar Feb 14 '24 12:02 bacherfl

Hi @Vickysomtee, any news on this one? feel free to reach out if you have any questions

@bacherfl I had a very tight schedule this past weeks. I am settled now, and I will round up this issue ASAP.

Vickysomtee avatar Feb 14 '24 14:02 Vickysomtee

Hi @Vickysomtee any updates on this PR?

odubajDT avatar Mar 08 '24 08:03 odubajDT

Hi @Vickysomtee any updates on this PR?

Hey @odubajDT I think I am done with the implementation. @RealAnna was helping out with the chainsaw test but it seems she currently isn't available or a little bit busy.

Vickysomtee avatar Mar 08 '24 09:03 Vickysomtee

@Vickysomtee seems like the pr needs a rebase since the go version has been upgraded, after that I will run again the test to check if any API error is propagated like it should

RealAnna avatar Apr 02 '24 12:04 RealAnna

@Vickysomtee seems like the pr needs a rebase since the go version has been upgraded, after that I will run again the test to check if any API error is propagated like it should

@RealAnna This is sorted

Vickysomtee avatar Apr 03 '24 15:04 Vickysomtee

@Vickysomtee seems like the pr needs a rebase since the go version has been upgraded, after that I will run again the test to check if any API error is propagated like it should

@RealAnna This is sorted

Please adapt the integration tests (mentioned here) and also the unit tests (mentioned here) according to the comments

odubajDT avatar Apr 03 '24 15:04 odubajDT

@Vickysomtee your unit tests are now failing, could you debug them? Also the integration test shows a strange error "unexpected end of JSON input" I would expect that the API error is forwarded.. maybe you need to doublechek your configuration of mock server:


in the logs I see that the actual query sent to the mock is:

`request:

  {
    "method" : "GET",
    "path" : "/api/v2/metrics/query",
    "queryStringParameters" : {
      "metricSelector" : [ "query" ]
    },
    "headers" : {
      "x-forwarded-by" : [ "MockServer_99f6f711-462f-4a60-9432-303a23ddd8ec" ],
      "host" : [ "mockserver.chainsaw-epic-spaniel.svc.cluster.local:1080" ],
      "content-length" : [ "0" ],
      "connection" : [ "keep-alive" ],
      "accept-encoding" : [ "gzip,deflate" ],
      "User-Agent" : [ "Go-http-client/1.1" ],
      "Authorization" : [ "Api-Token token: mytoken" ]
    },
    "keepAlive" : true,
    "secure" : false,
    "remoteAddress" : "10.244.0.1"
  }
  
  

you should try to adapt the configuration so that it matches it

RealAnna avatar Apr 04 '24 08:04 RealAnna

@Vickysomtee any news on this?

odubajDT avatar Apr 09 '24 10:04 odubajDT

@Vickysomtee any news on this?

@odubajDT I will look into between today and tomorrow

Vickysomtee avatar Apr 10 '24 07:04 Vickysomtee

@Vickysomtee your unit tests are now failing, could you debug them? Also the integration test shows a strange error "unexpected end of JSON input" I would expect that the API error is forwarded.. maybe you need to doublechek your configuration of mock server:


in the logs I see that the actual query sent to the mock is:

`request:

  {
    "method" : "GET",
    "path" : "/api/v2/metrics/query",
    "queryStringParameters" : {
      "metricSelector" : [ "query" ]
    },
    "headers" : {
      "x-forwarded-by" : [ "MockServer_99f6f711-462f-4a60-9432-303a23ddd8ec" ],
      "host" : [ "mockserver.chainsaw-epic-spaniel.svc.cluster.local:1080" ],
      "content-length" : [ "0" ],
      "connection" : [ "keep-alive" ],
      "accept-encoding" : [ "gzip,deflate" ],
      "User-Agent" : [ "Go-http-client/1.1" ],
      "Authorization" : [ "Api-Token token: mytoken" ]
    },
    "keepAlive" : true,
    "secure" : false,
    "remoteAddress" : "10.244.0.1"
  }
  
  

you should try to adapt the configuration so that it matches it

@RealAnna Should I include this headers section in the mock request as well?

Vickysomtee avatar Apr 17 '24 13:04 Vickysomtee

Please adapt the integration tests (mentioned here) and also the unit tests (mentioned here) according to the comments

@odubajDT For the unit test, I informed @RealAnna that no new error message was introduced in the PR. Only statusCode was added. For integration test, still figuring it out.

Vickysomtee avatar Apr 19 '24 10:04 Vickysomtee

@Vickysomtee your unit tests are now failing, could you debug them? Also the integration test shows a strange error "unexpected end of JSON input" I would expect that the API error is forwarded.. maybe you need to doublechek your configuration of mock server:


in the logs I see that the actual query sent to the mock is:

`request:

  {
    "method" : "GET",
    "path" : "/api/v2/metrics/query",
    "queryStringParameters" : {
      "metricSelector" : [ "query" ]
    },
    "headers" : {
      "x-forwarded-by" : [ "MockServer_99f6f711-462f-4a60-9432-303a23ddd8ec" ],
      "host" : [ "mockserver.chainsaw-epic-spaniel.svc.cluster.local:1080" ],
      "content-length" : [ "0" ],
      "connection" : [ "keep-alive" ],
      "accept-encoding" : [ "gzip,deflate" ],
      "User-Agent" : [ "Go-http-client/1.1" ],
      "Authorization" : [ "Api-Token token: mytoken" ]
    },
    "keepAlive" : true,
    "secure" : false,
    "remoteAddress" : "10.244.0.1"
  }
  
  

you should try to adapt the configuration so that it matches it

@RealAnna Should I include this headers section in the mock request as well?

Yes the mock should match what I pasted here 👍

RealAnna avatar Apr 22 '24 07:04 RealAnna

Yes the mock should match what I pasted here 👍

@RealAnna Done!

Vickysomtee avatar Apr 23 '24 05:04 Vickysomtee

Hello @RealAnna can you help review again?

Vickysomtee avatar May 07 '24 08:05 Vickysomtee

closing due to inactivity

odubajDT avatar Aug 05 '24 09:08 odubajDT