Skip to content

Commit

Permalink
Fix logging levels in go-sdk
Browse files Browse the repository at this point in the history
Signed-off-by: Karanjot Singh <[email protected]>
  • Loading branch information
0xquark committed May 15, 2024
1 parent a767f17 commit 05c0996
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
26 changes: 0 additions & 26 deletions atlan/client/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,6 @@ func RetrieveMinimal(guid string) (*Assets2.Asset, error) {
queryParams["min_ext_info"] = "true"
queryParams["ignore_relationships"] = "true"

DefaultAtlanClient.logger.Debugf("Retrieving Asset with GUID: %s", guid)
response, err := DefaultAtlanClient.CallAPI(api, queryParams, nil)
if err != nil {
return nil, err
Expand All @@ -769,8 +768,6 @@ func RetrieveMinimal(guid string) (*Assets2.Asset, error) {
return nil, fmt.Errorf("error unmarshalling asset response: %v", err)
}

DefaultAtlanClient.logger.Debugf("Asset retrieved successfully with GUID: %s", guid)

api.Path = originalPath // Reset the api.Path to its original value
return &assetresponse, nil
}
Expand All @@ -793,22 +790,16 @@ func PurgeByGuid(guids []string) (*model.AssetMutationResponse, error) {
// Add the comma-separated string of GUIDs to the query parameters
queryParams["guid"] = guidString

DefaultAtlanClient.logger.Debugf("Purging assets with GUIDs: %v", guids)

// Call the API
resp, err := DefaultAtlanClient.CallAPI(api, queryParams, nil)
if err != nil {
DefaultAtlanClient.logger.Errorf("Error purging assets: %v", err)
return nil, err
}

DefaultAtlanClient.logger.Debugf("Assets purged successfully")

// Unmarshal the response into the AssetMutationResponse struct
var response model.AssetMutationResponse
err = json.Unmarshal(resp, &response)
if err != nil {
DefaultAtlanClient.logger.Errorf("Error unmarshalling response: %v", err)
return nil, fmt.Errorf("error unmarshaling response: %v", err)
}

Expand All @@ -822,16 +813,13 @@ func DeleteByGuid(guids []string) (*model.AssetMutationResponse, error) {
}

for _, guid := range guids {
DefaultAtlanClient.logger.Debugf("Deleting asset with GUID: %s", guid)
asset, err := RetrieveMinimal(guid)
if err != nil {
DefaultAtlanClient.logger.Errorf("Error retrieving asset: %v", err)
return nil, fmt.Errorf("error retrieving asset: %v", err)
}

// Assuming the asset has a CanBeArchived field that indicates if it can be archived
if *asset.TypeName == "AtlasGlossaryCategory" {
DefaultAtlanClient.logger.Errorf("Asset %s of type %s cannot be archived", guid, *asset.TypeName)
return nil, fmt.Errorf("asset %s of type %s cannot be archived", guid, *asset.TypeName)
}
}
Expand All @@ -850,30 +838,24 @@ func DeleteByGuid(guids []string) (*model.AssetMutationResponse, error) {

fmt.Println("Query Params:", queryParams)

DefaultAtlanClient.logger.Debugf("Soft deleting assets with GUIDs: %v", guids)

// Call the API
resp, err := DefaultAtlanClient.CallAPI(api, queryParams, nil)
if err != nil {
DefaultAtlanClient.logger.Errorf("Error soft deleting assets: %v", err)
return nil, err
}

DefaultAtlanClient.logger.Debugf("Assets soft deleted successfully")

// Unmarshal the response into the AssetMutationResponse struct
var response model.AssetMutationResponse
err = json.Unmarshal(resp, &response)
if err != nil {
DefaultAtlanClient.logger.Errorf("Error unmarshalling response: %v", err)
return nil, fmt.Errorf("error unmarshaling response: %v", err)
}

// Wait until each asset is deleted
for _, guid := range guids {
err = WaitTillDeleted(guid)
if err != nil {
DefaultAtlanClient.logger.Errorf("Error waiting for asset deletion: %v", err)
return nil, err
}
}
Expand All @@ -883,20 +865,16 @@ func DeleteByGuid(guids []string) (*model.AssetMutationResponse, error) {

// WaitTillDeleted waits for an asset to be deleted.
func WaitTillDeleted(guid string) error {
DefaultAtlanClient.logger.Debugf("Waiting for asset with GUID %s to be deleted", guid)
for i := 0; i < MaxRetries; i++ {
asset, err := RetrieveMinimal(guid)
if err != nil {
DefaultAtlanClient.logger.Errorf("Error retrieving asset: %v", err)
return fmt.Errorf("error retrieving asset: %v", err)
}

if *asset.Status == "DELETED" {
DefaultAtlanClient.logger.Debugf("Asset with GUID %s is deleted", guid)
return nil
}

DefaultAtlanClient.logger.Errorf("Retry limit overrun waiting for asset with GUID %s to be deleted", guid)
// If the asset is not deleted, wait for a while before retrying
time.Sleep(RetryInterval)
}
Expand All @@ -911,7 +889,6 @@ type SaveRequest struct {

// Save saves the assets in memory to the Atlas server.
func Save(assets ...AtlanObject) (*model.AssetMutationResponse, error) {
DefaultAtlanClient.logger.Debugf("Saving assets: %v", assets)
request := SaveRequest{
Entities: assets,
}
Expand All @@ -922,12 +899,9 @@ func Save(assets ...AtlanObject) (*model.AssetMutationResponse, error) {
return nil, err
}

DefaultAtlanClient.logger.Debugf("Assets saved successfully")

var response model.AssetMutationResponse
err = json.Unmarshal(resp, &response)
if err != nil {
DefaultAtlanClient.logger.Errorf("Error unmarshalling response: %v", err)
return nil, err
}

Expand Down
12 changes: 6 additions & 6 deletions atlan/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (ac *AtlanClient) CallAPI(api *API, queryParams map[string]string, requestO
if requestObj != nil {
//fmt.Println("Request Object:", requestObj)
requestJSON, err := json.Marshal(requestObj)
//fmt.Println("Request JSON:", string(requestJSON))
logger.Log.Debugf("Request JSON: %s", string(requestJSON))
if err != nil {
ac.logger.Errorf("error marshaling request object: %v", err)
return nil, fmt.Errorf("error marshaling request object: %v", err)
Expand Down Expand Up @@ -287,14 +287,14 @@ func (ac *AtlanClient) makeRequest(method, path string, params map[string]interf
}

func (ac *AtlanClient) logAPICall(method, path string) {
ac.logger.Info("------------------------------------------------------")
ac.logger.Infof("Call : %s %s", method, path)
ac.logger.Infof("Content-type : application/json")
ac.logger.Infof("Accept : application/json")
ac.logger.Debugf("------------------------------------------------------")
ac.logger.Debugf("Call : %s %s", method, path)
ac.logger.Debugf("Content-type : application/json")
ac.logger.Debugf("Accept : application/json")
}

func (ac *AtlanClient) logHTTPStatus(response *http.Response) {
ac.logger.Infof("HTTP Status: %s", response.Status)
ac.logger.Debugf("HTTP Status: %s", response.Status)
if response.StatusCode < 200 || response.StatusCode >= 300 {
errorMessage, err := ioutil.ReadAll(response.Body)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions atlan/client/fluent_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"fmt"
"github.com/atlanhq/atlan-go/atlan"
"github.com/atlanhq/atlan-go/atlan/logger"
"github.com/atlanhq/atlan-go/atlan/model"
)

Expand Down Expand Up @@ -159,7 +158,6 @@ func (fs *FluentSearch) Execute() ([]*model.IndexSearchResponse, error) {

}
}
logger.Log.Debugf("Executed search successfully")
return responses, nil
}

Expand Down

0 comments on commit 05c0996

Please sign in to comment.