Skip to content

Commit

Permalink
Merge pull request #241 from BaritoLog/disable-inc-log-count-01
Browse files Browse the repository at this point in the history
fix(rails): disable increment log count api and log count view.
  • Loading branch information
Ranjeet Singh authored Apr 28, 2022
2 parents 61eeb6e + e2d5472 commit 1b30443
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 99 deletions.
47 changes: 3 additions & 44 deletions app/controllers/api/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,50 +82,9 @@ def profile_by_app_group
end

def increase_log_count
# Metrics are sent in batch
app_group_metrics = metric_params[:application_groups]
errors = []
log_count_data = []

if not app_group_metrics.blank?
app_group_metrics.each do |app_metric|
# Find app based on secret
app_secret = app_metric[:token] || ""
app = BaritoApp.find_by_secret_key(app_secret)
if app.blank?
errors << "#{app_secret} : is not a valid App Secret"
next
end

# Increase log count on both app_group and app
app_group = app.app_group
app_group.increase_log_count(app_metric[:new_log_count])
app.increase_log_count(app_metric[:new_log_count])

app.reload
log_count_data << {
token: app_metric[:token],
log_count: app.log_count
}

broadcast(:log_count_changed,
app.id,
app_metric[:new_log_count].to_i
)
end
end

if errors.empty? && !app_group_metrics.blank?
render json: {
data: log_count_data
}, status: :ok
else
render json: {
success: false,
errors: errors,
code: 404
}, status: :not_found
end
render json: {
data: []
}, status: :ok
end

private
Expand Down
47 changes: 3 additions & 44 deletions app/controllers/api/v2/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,50 +80,9 @@ def profile_by_app_group
end

def increase_log_count
# Metrics are sent in batch
app_group_metrics = metric_params[:application_groups]
errors = []
log_count_data = []

if not app_group_metrics.blank?
app_group_metrics.each do |app_metric|
# Find app based on secret
app_secret = app_metric[:token] || ""
app = BaritoApp.find_by_secret_key(app_secret)
if app.blank?
errors << "#{app_secret} : is not a valid App Secret"
next
end

# Increase log count on both app_group and app
app_group = app.app_group
app_group.increase_log_count(app_metric[:new_log_count])
app.increase_log_count(app_metric[:new_log_count])

app.reload
log_count_data << {
token: app_metric[:token],
log_count: app.log_count
}

broadcast(:log_count_changed,
app.id,
app_metric[:new_log_count].to_i
)
end
end

if errors.empty? && !app_group_metrics.blank?
render json: {
data: log_count_data
}, status: :ok
else
render json: {
success: false,
errors: errors,
code: 404
}, status: :not_found
end
render json: {
data: []
}, status: :ok
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/app_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def show
@barito_router_url = "#{Figaro.env.router_protocol}://#{Figaro.env.router_domain}/produce_batch"
@open_kibana_url = "#{Figaro.env.viewer_protocol}://#{Figaro.env.viewer_domain}/" +
@app_group.helm_infrastructure.cluster_name.to_s + "/"

@open_katulampa_url = sprintf(Figaro.env.MONITORING_LINK_FORMAT, @app_group.helm_infrastructure.cluster_name.to_s)
@allow_set_status = policy(@new_app).toggle_status?
@allow_manage_access = policy(@app_group).manage_access?
@allow_see_infrastructure = policy(Infrastructure).show?
Expand Down
6 changes: 2 additions & 4 deletions app/views/app_groups/_applications.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ h4.mb-3 All Applications
th.col-1 Retention Days
th.col-1 Max TPS
th.col-1 Status
th.col-1 Log Count
th.col-1 Created At (UTC)
th.col-2 Created At (UTC)
th.col-1 Actions
tbody
- apps.each do |app|
Expand Down Expand Up @@ -49,8 +48,7 @@ h4.mb-3 All Applications
= hidden_field_tag :toggle_status
- else
= app.status
td.col-1= app.log_count
td.col-1= app.created_at.strftime('%d %B %Y, %T')
td.col-2= app.created_at.strftime('%d %B %Y, %T')
td.col-1
- if allow_delete
.btn.btn-danger.btn-sm
Expand Down
3 changes: 3 additions & 0 deletions app/views/app_groups/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
.btn.btn-primary.btn-sm.mr-2
i.fas.fa-search.mr-1
= link_to 'Open Kibana', @open_kibana_url, target: '_blank', rel: 'noopener noreferrer', class: 'text-light', style: 'text-decoration: none'
.btn.btn-primary.btn-sm.mr-2
i.fas.fa-tachometer-alt.mr-1
= link_to 'Monitoring', @open_katulampa_url, target: '_blank', rel: 'noopener noreferrer', class: 'text-light', style: 'text-decoration: none'

- if @allow_manage_access
.btn.btn-primary.btn-sm.mr-2
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/api/apps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class Datadog::Statsd

describe 'Increase Log count API' do
context 'when empty application_groups metrics' do
it 'should return 404' do
it 'should return 404', :skip do
post api_increase_log_count_path, params: { access_token: @access_token, application_groups: []}, headers: headers
expect(response.status).to eq 404
end
Expand All @@ -224,12 +224,12 @@ class Datadog::Statsd
json_response = JSON.parse(response.body)

expect(response.status).to eq 200
expect(json_response['data'][0]['log_count']).to eq(10)
expect(json_response['data']).to be_empty
end
end

context 'when invalid token' do
it 'should return 404' do
it 'should return 404', :skip do
secret_key = SecureRandom.uuid.gsub(/\-/, '')
error_msg = "#{secret_key} : is not a valid App Secret"

Expand Down
6 changes: 3 additions & 3 deletions spec/requests/api/v2/apps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Datadog::Statsd

describe 'Increase Log count API' do
context 'when empty application_groups metrics' do
it 'should return 404' do
it 'should return 404', :skip do
post api_v2_increase_log_count_path, params: {access_token: @access_token, application_groups: []}, headers: headers

expect(response.status).to eq 404
Expand All @@ -252,12 +252,12 @@ class Datadog::Statsd
json_response = JSON.parse(response.body)

expect(response.status).to eq 200
expect(json_response['data'][0]['log_count']).to eq(10)
expect(json_response['data']).to be_empty
end
end

context 'when invalid token' do
it 'should return 404' do
it 'should return 404', :skip do
secret_key = SecureRandom.uuid.gsub(/\-/, '')
error_msg = "#{secret_key} : is not a valid App Secret"

Expand Down

0 comments on commit 1b30443

Please sign in to comment.