Skip to content

Conversation

@csfmomo
Copy link
Contributor

@csfmomo csfmomo commented Feb 25, 2021

fix: repair 3 logs.

Reason for Change:
3 not-readable logs as following

// Should use body info instead of its address
Response body is [123 34 104 116 116 112 83 116 97 116 117 115 67 111 100 101 34 58 34 50 48 48 34 44 34 110 101 116 119 111 114 107 67 111 110 116 97 105 110 101 114 115 34 58 91 93 125]
// Should expose pod info for debugging
SetIPConfigAsAvailable failed to release, no allocation found for pod
// Should use decoded message
[azure-cns] Received *cns.IPConfigRequest &{DesiredIPAddress: OrchestratorContext:[123 34 80 111 100 78 97 109 101 34 58 34 109 101 116 114 105 99 115 45 115 101 114 118 101 114 45 53 56 102 100 99 56 55 53 100 53 45 104 57 109 107 107 34 44 34 80 111 100 78 97 109 101 115 112 97 99 101 34 58 34 107 117 98 101 45 115 121 115 116 101 109 34 125]}.

Issue Fixed:
Non-readable log.

Requirements:

@codecov
Copy link

codecov bot commented Feb 25, 2021

Codecov Report

Merging #803 (974303e) into master (bfbd945) will decrease coverage by 0.14%.
The diff coverage is 43.75%.

@@            Coverage Diff             @@
##           master     #803      +/-   ##
==========================================
- Coverage   42.05%   41.91%   -0.15%     
==========================================
  Files         144      152       +8     
  Lines       14051    14401     +350     
==========================================
+ Hits         5909     6036     +127     
- Misses       7427     7633     +206     
- Partials      715      732      +17     

@neaggarwMS
Copy link
Member

logger.Response(service.Name, reserveResp, resp.ReturnCode, ReturnCodeToString(resp.ReturnCode), err)

Can you add Request context to this response message otherwise it is hard to correlate


Refers to: cns/restserver/ipam.go:53 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

@neaggarwMS
Copy link
Member

  returnMessage = err.Error()

CAn you add log for the failure


Refers to: cns/restserver/ipam.go:89 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

@neaggarwMS
Copy link
Member

  	logger.Printf("Released IP %+v for pod %+v", ipconfig.IPAddress, podInfo)

Why this log is missing in Geneva? Also can you move this log before marking the ip as available


Refers to: cns/restserver/ipam.go:304 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

@neaggarwMS
Copy link
Member

  	logger.Errorf("Failed to get release ipconfig. Pod to IPID exists, but IPID to IPConfig doesn't exist, CNS State potentially corrupt")

Can you add context (Pod and IP details)


Refers to: cns/restserver/ipam.go:307 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

@neaggarwMS
Copy link
Member

service.PodIPConfigState[ipconfig.ID] = ipconfig

Can you add log for which IP is allocate with pod context


Refers to: cns/restserver/ipam.go:280 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

@neaggarwMS
Copy link
Member

delete(service.PodIPIDByOrchestratorContext, podInfo.GetOrchestratorContextKey())

Can you add log here as well for when IP is released with podcontext


Refers to: cns/restserver/ipam.go:289 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

Copy link
Member

@neaggarwMS neaggarwMS left a comment

Choose a reason for hiding this comment

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

🕐

@csfmomo
Copy link
Contributor Author

csfmomo commented Feb 26, 2021

delete(service.PodIPIDByOrchestratorContext, podInfo.GetOrchestratorContextKey())

Can you add log here as well for when IP is released with podcontext

Refers to: cns/restserver/ipam.go:289 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

releaseIPConfig already have it's log. Added log in setIPConfigAsAvailable

@csfmomo
Copy link
Contributor Author

csfmomo commented Feb 26, 2021

  	logger.Errorf("Failed to get release ipconfig. Pod to IPID exists, but IPID to IPConfig doesn't exist, CNS State potentially corrupt")

Can you add context (Pod and IP details)

Refers to: cns/restserver/ipam.go:307 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

Added

@csfmomo
Copy link
Contributor Author

csfmomo commented Feb 26, 2021

service.PodIPConfigState[ipconfig.ID] = ipconfig

Added.

@csfmomo
Copy link
Contributor Author

csfmomo commented Feb 26, 2021

logger.Printf("Released IP %+v for pod %+v", ipconfig.IPAddress, podInfo)

Moved.

@csfmomo
Copy link
Contributor Author

csfmomo commented Feb 26, 2021

  returnMessage = err.Error()

CAn you add log for the failure

Refers to: cns/restserver/ipam.go:89 in e40eb49. [](commit_id = e40eb49, deletion_comment = False)

Added

@csfmomo
Copy link
Contributor Author

csfmomo commented Feb 26, 2021

logger.Response(service.Name, reserveResp, resp.ReturnCode, ReturnCodeToString(resp.ReturnCode), err)

Added.

pjohnst5
pjohnst5 previously approved these changes Feb 26, 2021
Copy link
Contributor

@pjohnst5 pjohnst5 left a comment

Choose a reason for hiding this comment

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

LGTM

logger.Request(service.Name, &ipconfigRequest, err)
operationName := "requestIPConfigHandler"
desiredIPAddress := ipconfigRequest.DesiredIPAddress
orchestratorContest := string(ipconfigRequest.OrchestratorContext)
Copy link
Contributor Author

@csfmomo csfmomo Feb 27, 2021

Choose a reason for hiding this comment

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

The test for why string can works
https://play.golang.org/p/rMJJrhnhCNP
From this test, we can see, if we don't use string but use unmarshall to change it to readable, the type of unmarshalled object is KubernetesPodInfo type instead of string. Then we can't add both string and KubernetesPodInfo into logger request.


import (
    "encoding/json"
    "fmt"
)

type IPConfigRequest struct {
	DesiredIPAddress    string
	OrchestratorContext json.RawMessage
}

type KubernetesPodInfo struct {
	PodName      string
	PodNamespace string
}

func main() {
    testPod1Info := KubernetesPodInfo{
	PodName:      "testpod1",
	PodNamespace: "testpod1namespace",
    }

    req := IPConfigRequest{}
    b, _ := json.Marshal(testPod1Info)
    req.OrchestratorContext = b
    req.DesiredIPAddress = "1.1.1.1"
    // string translate can work.
    fmt.Println(req.DesiredIPAddress + string(b))
    fmt.Println(b)

    var podInfo KubernetesPodInfo 
    err := json.Unmarshal(b, &podInfo)
    if err != nil {
        panic(err)
    }
    fmt.Printf("%v\n", podInfo)
    fmt.Printf("%+v\n", podInfo)
    fmt.Printf("%v\n", b)
}

@csfmomo csfmomo force-pushed the fixLog branch 2 times, most recently from f694a1b to add15bd Compare March 8, 2021 07:31
@neaggarwMS
Copy link
Member

logger.Response(service.Name, reserveResp, resp.ReturnCode, ReturnCodeToString(resp.ReturnCode), err)

We are printing double logs that could lead to noise. Can you update logger.Response method to accept Request and Response interface and print it at one place


In reply to: 786283821 [](ancestors = 786283821)


Refers to: cns/restserver/ipam.go:53 in add15bd. [](commit_id = add15bd, deletion_comment = False)

@neaggarwMS
Copy link
Member

logger.Response(service.Name, reserveResp, resp.ReturnCode, ReturnCodeToString(resp.ReturnCode), err)

Also expose a string function to IPConfigResponse like we have exposed it for IpConfigRequest


In reply to: 794273976 [](ancestors = 794273976,786283821)


Refers to: cns/restserver/ipam.go:53 in add15bd. [](commit_id = add15bd, deletion_comment = False)

}

service.PodIPIDByOrchestratorContext[podInfo.GetOrchestratorContextKey()] = ipconfig.ID
logger.Printf("Set PodIPIDByOrchestratorContext item %s with ID %s and IP is %s", podInfo.GetOrchestratorContextKey(), ipconfig.ID, ipconfig.IPAddress)
Copy link
Member

Choose a reason for hiding this comment

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

Can you prefix it with [setIPConfigAsAllocated]

Copy link
Member

Choose a reason for hiding this comment

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

I think updateIPConfigState already logs, do we need to duplicate it here?


In reply to: 590618862 [](ancestors = 590618862)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a duplication if we want to ensure line 319 got executed.

@neaggarwMS neaggarwMS dismissed their stale review March 9, 2021 18:32

revoking review

Copy link
Member

@neaggarwMS neaggarwMS left a comment

Choose a reason for hiding this comment

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

🕐

err = service.Listener.Decode(w, r, &ipconfigRequest)
logger.Request(service.Name, &ipconfigRequest, err)
operationName := "requestIPConfigHandler"
logger.Request(service.Name+operationName, ipconfigRequest.String(), err)
Copy link
Member

Choose a reason for hiding this comment

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

You dont have to add 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.

I need add String, otherwise, the OrchestratorContext part is binary and not readable. String() function translate the binary to string for OrchestratorContext part.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested, no need to call .String specifically. Let me remove it.

@csfmomo csfmomo requested a review from neaggarwMS March 16, 2021 22:25
msg = fmt.Sprintf("[%s] Code:%s, %+v, %+v.", tag, returnStr, request, response)
}

sendTraceInternal(msg)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? Log.logger.ResponseEx will print to AI too, right?

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 didn't see either Log.logger.ResponseEx or Log.logger.Response prints to AI.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After offline sync up, we'll keep it as it is for now. I'll make a separate PR to remove duplicate AI telemetry log populating issue.


err = service.Listener.Encode(w, &resp)
logger.Response(service.Name, resp, resp.ReturnCode, ReturnCodeToString(resp.ReturnCode), err)
logger.ResponseEx(service.Name, req.String(), resp, resp.ReturnCode, ReturnCodeToString(resp.ReturnCode), err)
Copy link
Member

Choose a reason for hiding this comment

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

Again API accepts interface, you dont need to pass String()

Copy link
Member

@neaggarwMS neaggarwMS left a comment

Choose a reason for hiding this comment

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

:shipit:

@csfmomo csfmomo merged commit dc7ff48 into master Mar 18, 2021
@csfmomo csfmomo deleted the fixLog branch March 18, 2021 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants