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

fix(upstreams): unable remove some fields' value [KM-970] #1978

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

raoxiaoyan
Copy link
Contributor

@raoxiaoyan raoxiaoyan commented Feb 24, 2025

.

Summary

KM-970
FTI-6493

@raoxiaoyan raoxiaoyan requested review from a team as code owners February 24, 2025 07:18
@raoxiaoyan raoxiaoyan self-assigned this Feb 25, 2025
@raoxiaoyan raoxiaoyan changed the title fix: fix(upstreams): unable remove some fields' value [KM-970] fix(upstreams): unable remove some fields' value [KM-970] Feb 25, 2025
@raoxiaoyan raoxiaoyan force-pushed the fix/KM-970 branch 4 times, most recently from b61d884 to 476efd5 Compare February 26, 2025 11:01
@raoxiaoyan raoxiaoyan force-pushed the fix/KM-970 branch 3 times, most recently from 2e1cadc to d27daac Compare March 3, 2025 02:51
@raoxiaoyan raoxiaoyan requested a review from sumimakito March 3, 2025 02:54
@kongponents-bot
Copy link
Collaborator

Preview components from this PR in consuming application

In consuming application project install preview versions of shared packages generated by this PR:

@kong-ui-public/entities-upstreams-targets@pr-1978

@raoxiaoyan raoxiaoyan requested a review from sumimakito March 11, 2025 08:09
Copy link
Member

@sumimakito sumimakito left a comment

Choose a reason for hiding this comment

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

Thanks for the updates

if (state.fields.healthchecksThreshold) {
result.healthchecks.threshold = Number(state.fields.healthchecksThreshold)
}
const getBasePayload = computed((): UpstreamFormPayload => ( {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const getBasePayload = computed((): UpstreamFormPayload => ( {
const basePayload = computed((): UpstreamFormPayload => ({

})
const getPayload = computed((): UpstreamFormPayload => {
const basePayload = getBasePayload.value
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const basePayload = getBasePayload.value

Comment on lines +431 to +438
const payload: UpstreamFormPayload = {
...basePayload,
healthchecks: {
...basePayload.healthchecks,
active: active || undefined,
passive: passive || undefined,
},
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const payload: UpstreamFormPayload = {
...basePayload,
healthchecks: {
...basePayload.healthchecks,
active: active || undefined,
passive: passive || undefined,
},
}
const payload: UpstreamFormPayload = {
...basePayload.value,
healthchecks: {
...basePayload.value.healthchecks,
active: active || undefined,
passive: passive || undefined,
},
}

Comment on lines +73 to +88
healthy: {
interval: response?.healthchecks.active?.healthy?.interval?.toString() || '0',
successes: response?.healthchecks.active?.healthy?.successes?.toString() || '5',
httpStatuses: response?.healthchecks.active?.healthy?.http_statuses
? numberToStringArray(response.healthchecks.active.healthy.http_statuses)
: ActiveHealthyHttpStatuses,
},
unhealthy: {
interval: response?.healthchecks.active?.unhealthy?.interval?.toString() || '0',
httpFailures: response?.healthchecks.active?.unhealthy?.http_failures?.toString() || '5',
tcpFailures: response?.healthchecks.active?.unhealthy?.tcp_failures?.toString() || '5',
httpStatuses: response?.healthchecks.active?.unhealthy?.http_statuses
? numberToStringArray(response.healthchecks.active.unhealthy.http_statuses)
: ActiveUnhealthyHttpStatuses,
timeouts: response?.healthchecks.active?.unhealthy?.timeouts?.toString() || '0',
},
Copy link
Member

Choose a reason for hiding this comment

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

Shall we populate the empty fields with the defaults in the schema?

healthy = {
  interval = 0,  -- 0 = probing disabled by default
  http_statuses = { 200, 302 },
  successes = 0, -- 0 = disabled by default
},
unhealthy = {
  interval = 0, -- 0 = probing disabled by default
  http_statuses = { 429, 404,
                    500, 501, 502, 503, 504, 505 },
  tcp_failures = 0,  -- 0 = disabled by default
  timeouts = 0,      -- 0 = disabled by default
  http_failures = 0, -- 0 = disabled by default
}

Comment on lines +92 to +105
healthy: {
successes: response?.healthchecks.passive?.healthy?.successes?.toString() || '5',
httpStatuses: response?.healthchecks.passive?.healthy?.http_statuses
? numberToStringArray(response.healthchecks.passive.healthy.http_statuses)
: PassiveHealthyHttpStatuses,
},
unhealthy: {
timeouts: response?.healthchecks.passive?.unhealthy?.timeouts?.toString() || '0',
httpFailures: response?.healthchecks.passive?.unhealthy?.http_failures?.toString() || '5',
tcpFailures: response?.healthchecks.passive?.unhealthy?.tcp_failures?.toString() || '5',
httpStatuses: response?.healthchecks.passive?.unhealthy?.http_statuses
? numberToStringArray(response.healthchecks.passive.unhealthy.http_statuses)
: PassiveUnhealthyHttpStatuses,
},
Copy link
Member

Choose a reason for hiding this comment

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

healthy = {
  http_statuses = { 200, 201, 202, 203, 204, 205, 206, 207, 208, 226,
                    300, 301, 302, 303, 304, 305, 306, 307, 308 },
  successes = 0,
},
unhealthy = {
  http_statuses = { 429, 500, 503 },
  tcp_failures = 0,  -- 0 = circuit-breaker disabled by default
  timeouts = 0,      -- 0 = circuit-breaker disabled by default
  http_failures = 0, -- 0 = circuit-breaker disabled by default
}

type: state.fields.activeHealthCheck.type,
healthy: {
interval: Number(state.fields.activeHealthCheck.healthy.interval || '0'),
successes: Number(state.fields.activeHealthCheck.healthy.successes || '5'),
Copy link
Member

Choose a reason for hiding this comment

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

Should we use 0 here?

unhealthy: {
interval: Number(state.fields.activeHealthCheck.unhealthy.interval || '0'),
timeouts: Number(state.fields.activeHealthCheck.unhealthy.timeouts || '0'),
tcp_failures: Number(state.fields.activeHealthCheck.unhealthy.tcpFailures || '5'),
Copy link
Member

Choose a reason for hiding this comment

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

Should we default to 0 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch.

Comment on lines -73 to -84
interval: response?.healthchecks.active?.healthy?.interval?.toString() || '0',
successes: response?.healthchecks.active?.healthy?.successes?.toString() || '5',
httpStatuses: response?.healthchecks.active?.healthy?.http_statuses
? numberToStringArray(response.healthchecks.active.healthy.http_statuses)
: ActiveHealthyHttpStatuses,
unhealthyInterval: response?.healthchecks.active?.unhealthy?.interval?.toString() || '0',
httpFailures: response?.healthchecks.active?.unhealthy?.http_failures?.toString() || '5',
tcpFailures: response?.healthchecks.active?.unhealthy?.tcp_failures?.toString() || '5',
unhealthyHttpStatuses: response?.healthchecks.active?.unhealthy?.http_statuses
? numberToStringArray(response.healthchecks.active.unhealthy.http_statuses)
: ActiveUnhealthyHttpStatuses,
unhealthyTimeouts: response?.healthchecks.active?.unhealthy?.timeouts?.toString() || '0',
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 don't know why here didn't populate the default value from the schema.
Maybe there is something wrong. Let me check it again.
@sumimakito

Comment on lines -165 to -176
state.fields.activeHealthCheck.interval = val ? '5' : '0'
state.fields.activeHealthCheck.successes = val ? '5' : '0'
state.fields.activeHealthCheck.httpFailures = val ? '5' : '0'
state.fields.activeHealthCheck.unhealthyInterval = val ? '5' : '0'
state.fields.activeHealthCheck.tcpFailures = val ? '5' : '0'
state.fields.activeHealthCheck.healthy.interval = val ? '5' : '0'
state.fields.activeHealthCheck.healthy.successes = val ? '5' : '0'
state.fields.activeHealthCheck.healthy.httpStatuses = val ? ActiveHealthyHttpStatuses : []
state.fields.activeHealthCheck.unhealthy.httpStatuses = val ? ActiveUnhealthyHttpStatuses : []
state.fields.activeHealthCheck.unhealthy.httpFailures = val ? '5' : '0'
state.fields.activeHealthCheck.unhealthy.interval = val ? '5' : '0'
state.fields.activeHealthCheck.unhealthy.tcpFailures = val ? '5' : '0'
state.fields.activeHealthCheck.unhealthy.timeouts = val ? '5' : '0'
state.fields.activeHealthCheck.timeout = val ? '1' : '0'
state.fields.activeHealthCheck.concurrency = val ? '10' : '0'
state.fields.activeHealthCheck.httpPath = val ? '/' : ''
state.fields.activeHealthCheck.httpsSni = ''
state.fields.activeHealthCheck.type = 'http'
}
const resetOnPassiveSwitch = (val: boolean): void => {
state.fields.passiveHealthCheck.timeouts = val ? '5' : '0'
state.fields.passiveHealthCheck.successes = val ? '80' : '0'
state.fields.passiveHealthCheck.tcpFailures = val ? '5' : '0'
state.fields.passiveHealthCheck.httpFailures = val ? '5' : '0'
Copy link
Contributor Author

@raoxiaoyan raoxiaoyan Mar 11, 2025

Choose a reason for hiding this comment

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

@2eha0 Why give these default values for these fields when enabling active or passive health?

Copy link
Member

Choose a reason for hiding this comment

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

Looking into the history of the file

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 think it should be enabled the active health requires the non-zero number.
But Why give these numbers? Where can I find some docs to ref.

Copy link
Member

Choose a reason for hiding this comment

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

It seems the default values have been there since two years ago when it was first added. I also have no idea why we chose them but let's keep them there as the current values serve as a good simple example instead of the all-zero ones.

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