Skip to content

[Question]: Customrest backend failing to read specific Error Messages #1556

@shmohitBhushan123

Description

@shmohitBhushan123

Checklist

  • I've searched for similar issues and couldn't find anything matching
  • I've included steps to reproduce the behavior

Affected Components

  • K8sGPT (CLI)
  • K8sGPT Operator

K8sGPT Version

0.4.22

Kubernetes Version

v1.33.1

Host OS and its Version

MacOS / Linux

Steps to reproduce

  1. Using a customrest backend to hit an ai endpoint
  2. Deploying a pod with an error of Image Pull Backoff
  3. Running k8sgpt analyze --explain --backend customrest

Expected behaviour

A generated response in which providing steps to suggested solution

Actual behaviour

Error: failed while calling AI provider customrest: invalid character 'n' after object key:value pair

Additional Information

I noticed my custom rest endpoint is able to analyze several resources within my cluster, so I know that the endpoint is being hit successfully in many instances, and a proper analysis is given. However, I have noticed that it fails specifically whenever the Error Message from the analyzer has quotations within the body itself.
I saw that customRest is a bit of a unique exception compared to others, as it takes prompt as a string and then unmarshalls accordingly, but the error that I am facing happens right upon this unmarshalling.

This is the current prompt the custom rest prepares to unmarshall after the string replacement done here:
{\"language\": \"english\",\"message\": \"Back-off pulling image \"nginx:1.a.b.c\": ErrImagePull: rpc error: code = NotFound desc = failed to pull and unpack image \"nginx:1.a.b.c\": failed to resolve reference \"nginx:1.a.b.c\": nginx:1.a.b.c: not found\",\"prompt\": \"Simplify the following Kubernetes error message delimited by triple dashes written in --- english --- language; --- Back-off pulling image \"nginx:1.a.b.c\": ErrImagePull: rpc error: code = NotFound desc = failed to pull and unpack image \"nginx:1.a.b.c\": failed to resolve reference \"nginx:1.a.b.c\": nginx:1.a.b.c: not found ---.\\n\\tProvide the most possible solution in a step by step style in no more than 280 characters. Write the output in the following format:\\n\\tError: {Explain error here}\\n\\tSolution: {Step by step solution here}\"}

However, this triggers the error: invalid character 'n' after object key:value pair. I noticed the string would properly unmarshall after adding two \'s within the quotes of the message. The example below was able to properly unmarshal with the added \:

{\"language\": \"english\",\"message\": \"Back-off pulling image \\\"nginx:1.a.b.c\\\": ErrImagePull: rpc error: code = NotFound desc = failed to pull and unpack image \"nginx:1.a.b.c\": failed to resolve reference \\\"nginx:1.a.b.c\\\": nginx:1.a.b.c: not found\",\"prompt\": \"Simplify the following Kubernetes error message delimited by triple dashes written in --- english --- language; --- Back-off pulling image \\\"nginx:1.a.b.c\\\": ErrImagePull: rpc error: code = NotFound desc = failed to pull and unpack image \\\"nginx:1.a.b.c\\\": failed to resolve reference \\\"nginx:1.a.b.c\\\": nginx:1.a.b.c: not found ---.\\n\\tProvide the most possible solution in a step by step style in no more than 280 characters. Write the output in the following format:\\n\\tError: {Explain error here}\\n\\tSolution: {Step by step solution here}\"}

This string resolved the issue for me personally. Is there something I am missing though? I referred to the documentation for customrest and couldn't find anything else. Thank you for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    Status

    Proposed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions