Skip to content

feat(inputs.aliyuncms): Refactor common parts to plugins/common#18280

Closed
ZPascal wants to merge 2 commits intoinfluxdata:masterfrom
ZPascal:add-the-aliyun-common-lib
Closed

feat(inputs.aliyuncms): Refactor common parts to plugins/common#18280
ZPascal wants to merge 2 commits intoinfluxdata:masterfrom
ZPascal:add-the-aliyun-common-lib

Conversation

@ZPascal
Copy link
Contributor

@ZPascal ZPascal commented Jan 29, 2026

Description

This PR adds the Aliyun common library to Telegraf.

Checklist

  • No AI generated code was used in this PR
  • I have read the contributing guidelines
  • I have signed the CLA
  • I have added tests to cover my changes
  • All new and existing tests pass

Related issues

related to #18253

@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Jan 29, 2026
@ZPascal
Copy link
Contributor Author

ZPascal commented Jan 29, 2026

FYI: @srebhan This PR integrates the Aliyun common library.

@srebhan srebhan changed the title feat: Add the aliyun common lib feat(inputs.aliyuncms): Refactor common parts to plugins/common Jan 30, 2026
@telegraf-tiger telegraf-tiger bot added the plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins label Jan 30, 2026
Copy link
Member

@srebhan srebhan 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 PR @ZPascal! I have some comments in the code. Furthermore, I would love to see inputs.aliyuncms to be migrated to this package in this PR without change of functionality.

Comment on lines +32 to +35
var (
roleSessionExpiration = 3600
sessionExpiration = 3600
)
Copy link
Member

Choose a reason for hiding this comment

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

Please use

Suggested change
var (
roleSessionExpiration = 3600
sessionExpiration = 3600
)
roleSessionExpiration := 3600
sessionExpiration := 3600

Comment on lines +78 to +82
if err != nil {
require.Contains(t, err.Error(), "failed to retrieve credential")
} else {
require.NotNil(t, cred)
}
Copy link
Member

Choose a reason for hiding this comment

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

No! You should know what you expect from that call! Either this should return an error, then check for it, or it doesn't!

Comment on lines +225 to +229
var (
err error
data map[string]interface{}
lastData map[string]interface{}
)
Copy link
Member

Choose a reason for hiding this comment

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

None of these is required to be declared outside of the go-routine, is it? Please use implicit declarations where possible and limit the scope of variables to a minimum to avoid unintended reuse!

Comment on lines +245 to +246
case <-dt.done:
return
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't using a cancel-able context be better here?

Comment on lines +96 to +100
req = "string"
require.NotNil(t, req)

req = 123
require.NotNil(t, req)
Copy link
Member

Choose a reason for hiding this comment

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

What does this test?

Comment on lines +76 to +87
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rpcReq, err := getRPCReqFromDiscoveryRequest(tt.req)
if tt.expectError {
require.Error(t, err)
require.Nil(t, rpcReq)
} else {
require.NoError(t, err)
require.NotNil(t, rpcReq)
}
})
}
Copy link
Member

Choose a reason for hiding this comment

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

Please split into a test that should succeed and one that should fail to simplify code and to provide context to the reader.

Same for other cases where you have if expectedError else constructs in tests!

Comment on lines +91 to +93
var req DiscoveryRequest

req = &mockDiscoveryRequest{RpcRequest: &requests.RpcRequest{}}
Copy link
Member

Choose a reason for hiding this comment

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

Please use implicit declarations where possible

Suggested change
var req DiscoveryRequest
req = &mockDiscoveryRequest{RpcRequest: &requests.RpcRequest{}}
req := &mockDiscoveryRequest{RpcRequest: &requests.RpcRequest{}}

Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to get the regions from the SDK? I don't want to maintain that list in telegraf as it is likely to be changed without anyone from Aliyun notifying us...

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this test does anything useful...

@srebhan srebhan self-assigned this Jan 30, 2026
@ZPascal ZPascal force-pushed the add-the-aliyun-common-lib branch 2 times, most recently from c390979 to 37fba13 Compare February 19, 2026 22:28
@srebhan
Copy link
Member

srebhan commented Feb 27, 2026

This PR is still missing the part where you convert inputs.aliyuncms to use this common part...

@srebhan srebhan added the waiting for response waiting for response from contributor label Feb 27, 2026
@ZPascal ZPascal force-pushed the add-the-aliyun-common-lib branch from 37fba13 to 56d4c35 Compare March 7, 2026 16:39
@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Mar 7, 2026

Copy link
Member

@srebhan srebhan 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 update @ZPascal! I have some more comments in the code. The biggest hurdles I see are

  1. The PR contains RDS code. This is unrelated to this PR and should be removed.
  2. The PR changes functionality in the CMS plugin. Please remove those changes and try to only move code around.

Please reduce this PR to only move code to common! Do not add functionality or change the way things are done in this PR! Submit follow-up PRs if you need to add functionality or if you need to change type-assertions, timestamp-parsing etc.

## - acs_rds_dashboard
## - acs_slb_dashboard
## - acs_vpc_eip
## Note: RDS Performance metrics are now supported via the dedicated aliyunrds plugin
Copy link
Member

Choose a reason for hiding this comment

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

This does not belong here!

Comment on lines +191 to +195
## RDS Performance metrics

You can use the dedicated [aliyunrds](../aliyunrds/README.md) plugin to
collect RDS Performance metrics.

Copy link
Member

Choose a reason for hiding this comment

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

This does not belong here!

## - acs_rds_dashboard
## - acs_slb_dashboard
## - acs_vpc_eip
## Note: RDS Performance metrics are now supported via the dedicated aliyunrds plugin
Copy link
Member

Choose a reason for hiding this comment

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

This does not belong here!

}
}

func TestPluginMetricsRDSServiceInitialize(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This does not belong here!

}

func TestGather(t *testing.T) {
func TestRDSServiceInitialization(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

This does not belong here! Same for all other RDS related things below!

Log telegraf.Logger `toml:"-"`

client aliyuncmsClient
cmsClient aliyuncmsClient
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the previous name to reduce the diff-size in the PR!

}

// parseTimestamp normalizes various timestamp representations into seconds since epoch.
func (s *AliyunCMS) parseTimestamp(v interface{}) (int64, bool) { //nolint:revive // Valid case
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need the nolint statement here?

if val, err := t.Int64(); err == nil {
return val, true
}
default:
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the default case as it doesn't do anything...

Comment on lines +296 to +301
parsed, ok := s.parseTimestamp(value)
if !ok {
s.Log.Warnf("Unexpected timestamp type %T, skipping datapoint", value)
continue NextDataPoint
}
ts = parsed
Copy link
Member

Choose a reason for hiding this comment

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

This is a functional extension! Please move this to an own PR!

Comment on lines -304 to +289
tags[key] = value.(string)
if metric.discoveryTags != nil { // discovery can be not activated
// Skipping data point if discovery data not exist
_, ok := metric.discoveryTags[value.(string)]
if !ok &&
!metric.AllowDataPointWODiscoveryData {
s.Log.Warnf("Instance %q is not found in discovery, skipping monitoring datapoint...", value.(string))
continue NextDataPoint
}

for k, v := range metric.discoveryTags[value.(string)] {
tags[k] = v
}
strVal, ok := value.(string)
if !ok {
s.Log.Warnf("Unexpected non-string %q value in datapoint, skipping...", key)
continue NextDataPoint
}
tags[key] = strVal
if keep := s.enrichTagsWithDiscovery(tags, m, strVal); !keep {
continue NextDataPoint
Copy link
Member

Choose a reason for hiding this comment

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

Why do you change this?

@telegraf-tiger
Copy link
Contributor

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Forums or provide additional details in this issue and reqeust that it be re-opened. Thank you!

@telegraf-tiger telegraf-tiger bot closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins waiting for response waiting for response from contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants