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

Enable UTM tags in IndexSearch #18

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions atlan/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func Context(apiKey, baseURL string) (*AtlanClient, error) {
logger = log.New(io.Discard, "", 0) // Logger that discards all log output
}

VERSION := "0.0"
headers := map[string]string{
"x-atlan-agent": "sdk",
"x-atlan-agent-id": "go",
"User-Agent": fmt.Sprintf("Atlan-GOSDK/%s", VERSION),
}

atlanClient := &AtlanClient{
Session: client,
host: baseURL,
Expand All @@ -82,6 +89,11 @@ func Context(apiKey, baseURL string) (*AtlanClient, error) {
},
}

// Merge the provided headers with existing headers
for key, value := range headers {
atlanClient.requestParams["headers"].(map[string]string)[key] = value
}

// Initialize the default atlan client
DefaultAtlanClient = atlanClient

Expand Down Expand Up @@ -213,6 +225,7 @@ func (ac *AtlanClient) makeRequest(method, path string, params map[string]interf
req.URL.RawQuery = query
}

fmt.Println(req.Header)
return ac.Session.Do(req)
}

Expand Down
4 changes: 4 additions & 0 deletions atlan/client/fluent_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ func (fs *FluentSearch) ToRequest() *model.IndexSearchRequest {
Aggregation: fs.Aggregations,
TrackTotalHits: true,
},
Metadata: model.Metadata{
SaveSearchLog: true,
UtmTags: []string{atlan.PROJECT_SDK_GO.String()},
},
}

// Add Wheres to Query
Expand Down
20 changes: 12 additions & 8 deletions atlan/client/index_search_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ func FindGlossaryByName(glossaryName string) (*model.IndexSearchResponse, error)
TrackTotalHits: true,
Sort: sortItemsJSON,
},
SuppressLogs: true,
ShowSearchScore: false,
ExcludeMeanings: false,
ExcludeClassifications: false,
SuppressLogs: true,
ShowSearchScore: false,
ExcludeMeanings: false,
ExcludeAtlanTags: false,
Metadata: model.Metadata{
SaveSearchLog: true,
UtmTags: []string{atlan.PROJECT_SDK_GO.String()},
},
}

iterator := NewIndexSearchIterator(pageSize, request)
Expand Down Expand Up @@ -98,10 +102,10 @@ func FindCategoryByName(categoryName string, glossaryQualifiedName string) (*mod
Query: boolQuery.ToJSON(),
TrackTotalHits: true,
},
SuppressLogs: true,
ShowSearchScore: false,
ExcludeMeanings: false,
ExcludeClassifications: false,
SuppressLogs: true,
ShowSearchScore: false,
ExcludeMeanings: false,
ExcludeAtlanTags: false,
}

iterator := NewIndexSearchIterator(pageSize, request)
Expand Down
119 changes: 119 additions & 0 deletions atlan/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -2702,3 +2702,122 @@ func (q *QueryUsernameStrategy) UnmarshalJSON(data []byte) error {

return nil
}

type UTMTags struct {
Name string
}

func (u UTMTags) String() string {
return u.Name
}

var (
// PAGE_ entries indicate where the action was taken.

// Search was made from the home page.
PAGE_HOME = UTMTags{"page_home"}
// Search was made from the assets (discovery) page.
PAGE_ASSETS = UTMTags{"page_assets"}
// Asset was viewed from within a glossary.
PAGE_GLOSSARY = UTMTags{"page_glossary"}
// Asset was viewed from within insights.
PAGE_INSIGHTS = UTMTags{"page_insights"}

// PROJECT_ entries indicate how (via what application) the action was taken.

// Search was made via the webapp (UI)
PROJECT_WEBAPP = UTMTags{"project_webapp"}
// Search was made via the Java SDK.
PROJECT_SDK_JAVA = UTMTags{"project_sdk_java"}
// Search was made via the Python SDK.
PROJECT_SDK_PYTHON = UTMTags{"project_sdk_python"}
// Search was made via the Go SDK.
PROJECT_SDK_GO = UTMTags{"project_sdk_go"}
// Search was made via the atlan cli.
PROJECT_SDK_CLI = UTMTags{"project_sdk_cli"}

// ACTION_ entries dictate the specific action that was taken.

// Assets were searched.
ACTION_SEARCHED = UTMTags{"action_searched"}
// Search was run through the Cmd-K popup.
ACTION_CMD_K = UTMTags{"action_cmd_k"}
// Search was through changing a filter in the UI (discovery).
ACTION_FILTER_CHANGED = UTMTags{"action_filter_changed"}
// Search was through changing a type filter (pill) in the UI (discovery)
ACTION_ASSET_TYPE_CHANGED = UTMTags{"action_asset_type_changed"}
// Asset was viewed, rather than an explicit search.
ACTION_ASSET_VIEWED = UTMTags{"action_asset_viewed"}

// Others indicate any special mechanisms used for the action.

// Search was run using the UI popup searchbar.
UI_POPUP_SEARCHBAR = UTMTags{"ui_popup_searchbar"}
// Search was through a UI filter (discovery).
UI_FILTERS = UTMTags{"ui_filters"}
// View was done via the UI's sidebar.
UI_SIDEBAR = UTMTags{"ui_sidebar"}
// View was done of the full asset profile, not only sidebar.
UI_PROFILE = UTMTags{"ui_profile"}
// Listing of assets, usually by a particular type, in the discovery page.
UI_MAIN_LIST = UTMTags{"ui_main_list"}
)

func (u UTMTags) MarshalJSON() ([]byte, error) {
return json.Marshal(u.Name)
}

func (u *UTMTags) UnmarshalJSON(data []byte) error {
var UtmTags string
if err := json.Unmarshal(data, &UtmTags); err != nil {
return err
}

switch UtmTags {
case "page_home":
*u = PAGE_HOME
switch UtmTags {
case "page_home":
*u = PAGE_HOME
case "page_assets":
*u = PAGE_ASSETS
case "page_glossary":
*u = PAGE_GLOSSARY
case "page_insights":
*u = PAGE_INSIGHTS
case "project_webapp":
*u = PROJECT_WEBAPP
case "project_sdk_java":
*u = PROJECT_SDK_JAVA
case "project_sdk_python":
*u = PROJECT_SDK_PYTHON
case "project_sdk_go":
*u = PROJECT_SDK_GO
case "project_sdk_cli":
*u = PROJECT_SDK_CLI
case "action_searched":
*u = ACTION_SEARCHED
case "action_cmd_k":
*u = ACTION_CMD_K
case "action_filter_changed":
*u = ACTION_FILTER_CHANGED
case "action_asset_type_changed":
*u = ACTION_ASSET_TYPE_CHANGED
case "action_asset_viewed":
*u = ACTION_ASSET_VIEWED
case "ui_popup_searchbar":
*u = UI_POPUP_SEARCHBAR
case "ui_filters":
*u = UI_FILTERS
case "ui_sidebar":
*u = UI_SIDEBAR
case "ui_profile":
*u = UI_PROFILE
case "ui_main_list":
*u = UI_MAIN_LIST
default:
*u = UTMTags{Name: UtmTags}
}
}
return nil
}
37 changes: 22 additions & 15 deletions atlan/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,22 @@ type SearchRequest struct {
RelationsAttributes []string `json:"relationsAttributes,omitempty"`
}

type Metadata struct {
SaveSearchLog bool `json:"saveSearchLog,omitempty"`
UtmTags []string `json:"utmTags,omitempty"`
}

// IndexSearchRequest represents a search request in the Atlas search DSL.
type IndexSearchRequest struct {
SearchRequest
Dsl Dsl `json:"dsl"`
RelationAttributes []string `json:"relationAttributes,omitempty"`
SuppressLogs bool `json:"suppressLogs"`
ShowSearchScore bool `json:"showSearchScore"`
ExcludeMeanings bool `json:"excludeMeanings"`
ExcludeClassifications bool `json:"excludeClassifications"`
Dsl Dsl `json:"dsl"`
RelationAttributes []string `json:"relationAttributes,omitempty"`
SuppressLogs bool `json:"suppressLogs,omitempty"`
ShowSearchScore bool `json:"showSearchScore,omitempty"`
ExcludeMeanings bool `json:"excludeMeanings,omitempty"`
ExcludeAtlanTags bool `json:"excludeClassifications,omitempty"`
AllowDeletedRelations bool `json:"allowDeletedRelations,omitempty"`
Metadata Metadata `json:"requestMetadata,omitempty"`
}

// Dsl represents the DSL for the Atlas search request.
Expand All @@ -445,15 +452,15 @@ type IndexSearchResponse struct {

// SearchParameters represents the search parameters in the Atlas search response.
type SearchParameters struct {
ShowSearchScore bool `json:"showSearchScore"`
SuppressLogs bool `json:"suppressLogs"`
ExcludeMeanings bool `json:"excludeMeanings"`
ExcludeAtlanTags bool `json:"excludeClassifications"`
AllowDeletedRelations bool `json:"allowDeletedRelations"`
SaveSearchLog bool `json:"saveSearchLog"`
RequestMetadata map[string]interface{} `json:"requestMetadata"`
Dsl Dsl `json:"dsl"`
Query string `json:"query"`
ShowSearchScore bool `json:"showSearchScore"`
SuppressLogs bool `json:"suppressLogs"`
ExcludeMeanings bool `json:"excludeMeanings"`
ExcludeAtlanTags bool `json:"excludeClassifications"`
AllowDeletedRelations bool `json:"allowDeletedRelations"`
SaveSearchLog bool `json:"saveSearchLog"`
RequestMetadata Metadata `json:"requestMetadata"`
Dsl Dsl `json:"dsl"`
Query string `json:"query"`
}

type SearchAssets struct {
Expand Down
101 changes: 76 additions & 25 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"fmt"
"github.com/atlanhq/atlan-go/atlan"
"github.com/atlanhq/atlan-go/atlan/client"
)

Expand All @@ -11,35 +12,85 @@ func main() {
client.LoggingEnabled = true
ctx := client.NewContext()

client.GetCustomMetadataCache().RefreshCache()
id, err := client.GetCustomMetadataCache().GetIDForName("testcmgsdk")
if err != nil {
fmt.Println("Error:", err)
}
name, _ := client.GetCustomMetadataCache().GetNameForID("cvhn5T7YwnsYXiMCKh9PoW")
attrID, _ := client.GetCustomMetadataCache().GetAttrIDForName("testcmgsdk", "gsdk")
attrName, _ := client.GetCustomMetadataCache().GetAttrNameForID("cvhn5T7YwnsYXiMCKh9PoW", "foYi4v02OVjKt0YzcTCKM3")
fmt.Println("ID for name is : ", id)
fmt.Println("Name fo ID is:", name)
fmt.Printf("\nAttrID for name is: %s\n", attrID)
fmt.Printf("\nAttrName for ID is: %s\n", attrName)

fmt.Println(client.GetCustomMetadataCache().GetAttributesForSearchResultsByName("testcmgsdk"))
customMetadata := client.GetCustomMetadataCache().GetAttributesForSearchResultsByName("testcmgsdk")

customMeta, _ := client.NewFluentSearch().
// Fetch columns of table from Atlan using Qualified Name
qualifiedname := "default/snowflake/1714501359/ANALYTICS/WIDE_WORLD_IMPORTERS/CUSTOMERR/ID"

columnResult := client.NewFluentSearch().
PageSizes(50).
ActiveAssets().
Where(ctx.Glossary.QUALIFIED_NAME.Eq("fW6NU2lWKaMy5ZyVlGYes")).
IncludeOnResults(customMetadata...).
IncludeOnResults("terms").
IncludeOnResults("tags").
Execute()

for _, entity := range customMeta[0].Entities {
fmt.Println("Entity:", *entity.DisplayName)
Where(ctx.Column.TYPENAME.Eq("Column")).
Where(ctx.Column.QUALIFIED_NAME.Eq(qualifiedname)).
ToRequest()

columnResult.Metadata.UtmTags = []string{atlan.PROJECT_SDK_CLI.String()}

iterator := client.NewIndexSearchIterator(columnResult.Size, *columnResult)

for iterator.HasMoreResults() {
responses, _ := iterator.IteratePages()
for _, response := range responses {
fmt.Println(response)
break
}
break
}

/*
if err != nil {
fmt.Printf("Error executing search: %v\n", err)
return
}

fmt.Println("Search results:", *columnResult[0].Entities[0].Name)
fmt.Println("Search results:", *columnResult[0].Entities[0].QualifiedName)


*/
//client.GetAll()

/*
dc := &client.DataContract{}
dc.Creator("DataContractLatestCertified")
response, err := client.Save()
if err != nil {
fmt.Println(err)
}
fmt.Println("response", response)


*/
/*
client.GetCustomMetadataCache().RefreshCache()
id, err := client.GetCustomMetadataCache().GetIDForName("testcmgsdk")
if err != nil {
fmt.Println("Error:", err)
}
name, _ := client.GetCustomMetadataCache().GetNameForID("cvhn5T7YwnsYXiMCKh9PoW")
attrID, _ := client.GetCustomMetadataCache().GetAttrIDForName("testcmgsdk", "gsdk")
attrName, _ := client.GetCustomMetadataCache().GetAttrNameForID("cvhn5T7YwnsYXiMCKh9PoW", "foYi4v02OVjKt0YzcTCKM3")
fmt.Println("ID for name is : ", id)
fmt.Println("Name fo ID is:", name)
fmt.Printf("\nAttrID for name is: %s\n", attrID)
fmt.Printf("\nAttrName for ID is: %s\n", attrName)

fmt.Println(client.GetCustomMetadataCache().GetAttributesForSearchResultsByName("testcmgsdk"))
customMetadata := client.GetCustomMetadataCache().GetAttributesForSearchResultsByName("testcmgsdk")

customMeta, _ := client.NewFluentSearch().
PageSizes(50).
ActiveAssets().
Where(ctx.Glossary.QUALIFIED_NAME.Eq("fW6NU2lWKaMy5ZyVlGYes")).
IncludeOnResults(customMetadata...).
IncludeOnResults("terms").
IncludeOnResults("tags").
Execute()

for _, entity := range customMeta[0].Entities {
fmt.Println("Entity:", *entity.AssetDbtJobNextRunHumanized)
}


*/
/*
ctx := client.NewContext()
assetQualifiedName := "default/mssql/1711817247/WideWorldImporters/Purchasing/SupplierCategories_Archive"
Expand Down
Loading