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

Feature/multi account selection #177

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

daniebrill
Copy link

@daniebrill daniebrill commented Jul 5, 2021

What type of PR is this?
UI Feature
Backend Feature

What this PR does / why we need it:
Add support for multiple accounts to UI + necessary functionality to backend

Does this PR introduce a breaking change, if so what is it?:

- does not work with data from older versions
- safe account id + account name for detected resources
- api endpoint for getting all accounts
- add accounts to filter in ui

Additional documentation:


Jackafive753 and others added 21 commits May 28, 2021 14:10
/collector/structs.go
+ AccountSpecifiedFiels struct to save AccountId and AccountName

/collector/aws/common/structs.go
+ add Method getAccountName()

/collector/aws/detector.go
+ save in DetectorManager the accountName from config file

/collector/resources/*
+ save AccountSpecifiedFields with values in detectedStructs
* elasticsearch.go getDynamicMatchQuery
   add: if filterName is Data.AccountID then build boolQuery for given AccountIDs
fit MockAWSManager to the modified AWSManager
* save arn in resourceID field
+ add values in test objects
+ add accounts to the provider store
+ Show Accounts in a chip-list like resources
+ add Accounts to filter
add comments
add spentAccounts in summary
add things to success tests
Add multiaccount-selection functionality for RessourceCharts
remove account charts with not data found
@kaplanelad kaplanelad self-requested a review August 1, 2021 07:00
Copy link
Contributor

@kaplanelad kaplanelad left a comment

Choose a reason for hiding this comment

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

Hey @daniebrill,
Thanks for your contribution! this feature is amazing for our product!

before the technical review I have few notes:

  1. when I ran your branch on our data we didn't saw details in the UI / the server returned empty data.
    It looks like BREAKING CHANGES. If someone installs the new version on his current envioronment it will not work.

  2. I ran the code from scratch with the following configuration and I'm seeing only one account:

---
name: test-1
log_level: info
api_server: 
  address: http://127.0.0.1:8081
  bulk_interval: 5s

providers:
  aws:
    accounts: 
      - name: Account A
        profile: finala-sts 
        regions:
          - Region X
      - name: Account B
        profile: finala-sts 
        regions:
          - Region Y
    metrics:
     ....

In Accounts: section I'm seeing only Account B filter (expected: Account A, Account B correct me i'm if i'm wrong), in the table view
I'm seeing all the accounts collector events

Amazing work and thank you for your help to moving Finala forward

mq.MinimumShouldMatch("100%")
if operator == "and" {
mq = mq.Operator("and")
if name == "Data.AccountID" {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we starting to manage specific logic on specific filters fields let's take the logic per filter outside of this function.
WDYT?

if val, ok := spent.Aggregations["value"]; ok {
accountID, ok := AccountIdBucket.Key.(string)
if !ok {
log.Error("type assertion to string failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Error("type assertion to string failed")
log.WithFields(log.Fields{
"search_account_id": AccountIdBucket.Key.(string),
"val": val,
}).Error("type assertion to string failed")

log.Error("type assertion to string failed")
continue
}
spentAccounts[accountID], _ = strconv.ParseFloat(string(val), 64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you catch the parsing error?

@@ -298,6 +318,44 @@ func (sm *StorageManager) GetExecutions(queryLimit int) ([]storage.Executions, e
return executions, nil
}

func (sm *StorageManager) GetAccounts(executionID string, querylimit int) ([]storage.Accounts, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

document the fucntion

// GetAccounts .....

@@ -298,6 +318,44 @@ func (sm *StorageManager) GetExecutions(queryLimit int) ([]storage.Executions, e
return executions, nil
}

func (sm *StorageManager) GetAccounts(executionID string, querylimit int) ([]storage.Accounts, error) {
accounts := []storage.Accounts{}

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add logger instance with global fields that will show for each log that you write (better visibility ):

logger := log.WithField("execution_id", executionID) 

then use logger for any log line.

@@ -166,16 +171,28 @@ func (el *ELBManager) Detect(metrics []config.MetricConfig) (interface{}, error)
}
}

Arn := "arn:aws:elasticloadbalancing:" + el.awsManager.GetRegion() + ":" + *el.awsManager.GetAccountIdentity().Account + ":loadbalancer/" + *instance.LoadBalancerName
Copy link
Contributor

Choose a reason for hiding this comment

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

same question above

@@ -166,18 +171,30 @@ func (ngw *NatGatewayManager) Detect(metrics []config.MetricConfig) (interface{}
}
}

Arn := "arn:aws:ec2:" + ngw.awsManager.GetRegion() + ":" + *ngw.awsManager.GetAccountIdentity().Account + ":natgateway/" + *natgateway.NatGatewayId
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question above

@@ -147,18 +152,30 @@ func (rdm *RedShiftManager) Detect(metrics []config.MetricConfig) (interface{},
}
}

Arn := "arn:aws:redshift:" + rdm.awsManager.GetRegion() + ":" + *rdm.awsManager.GetAccountIdentity().Account + ":cluster:" + *cluster.ClusterIdentifier
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question above

cm.updateServiceStatus(EventCollector{
ResourceName: resourceName,
Data: EventStatusData{
Status: EventFetch,
Status: EventFetch,
AccountInformation: accountSpecifiedFields.AccountName + "_" + accountSpecifiedFields.AccountID,
Copy link
Contributor

Choose a reason for hiding this comment

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

I have 2 questions:

  1. why not separate these fields? AccountName and AccountID?
  2. if we keep is it with concat string let move this logic to one place which you using it in 2 different functions CollectStart, CollectFinish

@@ -59,3 +59,12 @@ func ExtractExecutionName(executionId string) (string, error) {

return executionArr[0], nil
}

// ExtractAccountInformation will return Account Name and Account ID
func ExtractAccountInformation(account string) (string, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if you will split this value (as i maintain in collector/collector.go) you will not need this function. correct me if I'm wrong

@kaplanelad
Copy link
Contributor

Hey @daniebrill any news?

@daniebrill
Copy link
Author

Hey @kaplanelad, we are going to improve the code and react to your feedback next week.

@kaplanelad
Copy link
Contributor

Hey @daniebrill,
please let me know when we can recheck PR.

@daniebrill
Copy link
Author

Hi @kaplanelad ,
we finished the improvements, so you can recheck.

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.

3 participants