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

[#10776] Add /metricDef/userDefined api logic. #11281

Merged
merged 1 commit into from
Jul 24, 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
7 changes: 7 additions & 0 deletions otlpmetric/otlpmetric-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
<jdk.version>17</jdk.version>
<jdk.home>${env.JAVA_17_HOME}</jdk.home>
</properties>
<dependencies>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons-server</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.common.defined;

import com.navercorp.pinpoint.common.server.util.StringPrecondition;

/**
* @author minwoo-jung
*/
public class AppMetricDefinition {

public static final int SCHEMA_VERSION = 1;

private final String applicationName;
private final String id;
private final String title;
private final String metricGroupName;
private final String metricName;
private final String fieldName;
private final String tags;
private final String unit;
private final String chartType;


public AppMetricDefinition(String applicationName, String id, String title, String metricGroupName, String metricName, String fieldName, String tags, String unit, String chartType) {
this.applicationName = StringPrecondition.requireHasLength(applicationName, "applicationName");
this.id = StringPrecondition.requireHasLength(id, "id");
this.title = StringPrecondition.requireHasLength(title, "title");
this.metricGroupName = StringPrecondition.requireHasLength(metricGroupName, "metricGroupName");
this.metricName = StringPrecondition.requireHasLength(metricName, "metricName");
this.fieldName = "";
this.tags = StringPrecondition.requireHasLength(tags, "tags");
this.unit = StringPrecondition.requireHasLength(unit, "unit");
this.chartType = StringPrecondition.requireHasLength(chartType, "chartType");
}

public String getApplicationName() {
return applicationName;
}

public String getId() {
return id;
}

public String getTitle() {
return title;
}

public String getMetricGroupName() {
return metricGroupName;
}

public String getMetricName() {
return metricName;
}

public String getFieldName() {
return fieldName;
}

public String getTags() {
return tags;
}

public String getUnit() {
return unit;
}

public String getChartType() {
return chartType;
}

public int getSchemaVersion() {
return SCHEMA_VERSION;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.common.definition;
package com.navercorp.pinpoint.otlp.common.definition.property;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.common.definition;
package com.navercorp.pinpoint.otlp.common.definition.property;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.common.definition;
package com.navercorp.pinpoint.otlp.common.definition.property;

/**
* @author minwoo-jung
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.common.definition;
package com.navercorp.pinpoint.otlp.common.definition.property;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.common.definition;
package com.navercorp.pinpoint.otlp.common.definition.property;

/**
* @author minwoo-jung
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import com.navercorp.pinpoint.datasource.MainDataSourcePropertySource;
import com.navercorp.pinpoint.otlp.web.config.OtlpMetricWebPinotDaoConfiguration;
import com.navercorp.pinpoint.otlp.web.config.mysql.OtlpMetricWebMysqlDaoConfiguration;
import com.navercorp.pinpoint.otlp.web.config.pinot.OtlpMetricWebPinotDaoConfiguration;
import com.navercorp.pinpoint.pinot.config.PinotConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
Expand All @@ -30,7 +30,8 @@
})
@Import({
PinotConfiguration.class,
OtlpMetricWebPinotDaoConfiguration.class
OtlpMetricWebPinotDaoConfiguration.class,
OtlpMetricWebMysqlDaoConfiguration.class
})
@ConditionalOnProperty(name = "pinpoint.modules.web.otlpmetric.enabled", havingValue = "true")
public class OtlpMetricWebConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.web.config.mysql;

import com.navercorp.pinpoint.mybatis.MyBatisRegistryHandler;
import com.navercorp.pinpoint.otlp.common.defined.AppMetricDefinition;
import com.navercorp.pinpoint.otlp.web.dao.model.AppMetricDefDto;
import org.apache.ibatis.type.TypeAliasRegistry;
import org.apache.ibatis.type.TypeHandlerRegistry;

/**
* @author minwoo-jung
*/
public class OtlpMetricMysqlRegistryHandler implements MyBatisRegistryHandler {

Check warning on line 28 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricMysqlRegistryHandler.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricMysqlRegistryHandler.java#L28

Added line #L28 was not covered by tests
@Override
public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
typeAliasRegistry.registerAlias(AppMetricDefinition.class);
typeAliasRegistry.registerAlias(AppMetricDefDto.class);
}

Check warning on line 33 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricMysqlRegistryHandler.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricMysqlRegistryHandler.java#L31-L33

Added lines #L31 - L33 were not covered by tests

@Override
public void registerTypeHandler(TypeHandlerRegistry typeHandlerRegistry) {

}

Check warning on line 38 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricMysqlRegistryHandler.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricMysqlRegistryHandler.java#L38

Added line #L38 was not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.web.config.mysql;

import com.navercorp.pinpoint.mybatis.MyBatisConfigurationCustomizer;
import com.navercorp.pinpoint.mybatis.MyBatisRegistryHandler;
import com.navercorp.pinpoint.mybatis.plugin.BindingLogPlugin;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.Resource;

import javax.sql.DataSource;

/**
* @author minwoo-jung
*/
@org.springframework.context.annotation.Configuration
public class OtlpMetricWebMysqlDaoConfiguration {

Check warning on line 40 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L40

Added line #L40 was not covered by tests

private final Logger logger = LogManager.getLogger(OtlpMetricWebMysqlDaoConfiguration.class);

Check warning on line 42 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L42

Added line #L42 was not covered by tests

@Bean
public FactoryBean<SqlSessionFactory> otlpMysqlSqlSessionFactory(
@Qualifier("myBatisConfigurationCustomizer") MyBatisConfigurationCustomizer customizer,
@Qualifier("dataSource") DataSource dataSource,
@Value("classpath*:otlp/web/mapper/mysql/*Mapper.xml") Resource[] mappers,
BindingLogPlugin bindingLogPlugin) {

for (Resource mapper : mappers) {
logger.info("Mapper location: {}", mapper.getDescription());

Check warning on line 52 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L52

Added line #L52 was not covered by tests
}

SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource);
sessionFactoryBean.setMapperLocations(mappers);

Check warning on line 57 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L55-L57

Added lines #L55 - L57 were not covered by tests

Configuration config = new Configuration();

Check warning on line 59 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L59

Added line #L59 was not covered by tests

sessionFactoryBean.setConfiguration(config);
sessionFactoryBean.setFailFast(true);
sessionFactoryBean.setPlugins(bindingLogPlugin);

Check warning on line 63 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L61-L63

Added lines #L61 - L63 were not covered by tests

MyBatisRegistryHandler myBatisRegistryHandler = new OtlpMetricMysqlRegistryHandler();
myBatisRegistryHandler.registerTypeAlias(config.getTypeAliasRegistry());
myBatisRegistryHandler.registerTypeHandler(config.getTypeHandlerRegistry());

Check warning on line 67 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L65-L67

Added lines #L65 - L67 were not covered by tests

return sessionFactoryBean;

Check warning on line 69 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L69

Added line #L69 was not covered by tests
}

@Bean
public SqlSessionTemplate otlpMysqlSqlSessionTemplate(
@Qualifier("otlpMysqlSqlSessionFactory") SqlSessionFactory sessionFactory) {
return new SqlSessionTemplate(sessionFactory);

Check warning on line 75 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/mysql/OtlpMetricWebMysqlDaoConfiguration.java#L75

Added line #L75 was not covered by tests
}


}
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
package com.navercorp.pinpoint.otlp.web.config;
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.web.config.pinot;

import com.navercorp.pinpoint.mybatis.MyBatisRegistryHandler;
import com.navercorp.pinpoint.otlp.common.definition.MetricDescriptor;
import com.navercorp.pinpoint.otlp.common.definition.property.MetricDescriptor;
import com.navercorp.pinpoint.otlp.common.model.AggreFunc;
import com.navercorp.pinpoint.otlp.common.model.DataType;
import com.navercorp.pinpoint.otlp.web.vo.handler.FieldAttributeHandler;
import com.navercorp.pinpoint.otlp.web.vo.*;
import org.apache.ibatis.type.TypeAliasRegistry;
import org.apache.ibatis.type.TypeHandlerRegistry;

public class OtlpMetricWebRegistryHandler implements MyBatisRegistryHandler {
public class OtlpMetricPinotRegistryHandler implements MyBatisRegistryHandler {

Check warning on line 28 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/pinot/OtlpMetricPinotRegistryHandler.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/pinot/OtlpMetricPinotRegistryHandler.java#L28

Added line #L28 was not covered by tests
@Override
public void registerTypeAlias(TypeAliasRegistry typeAliasRegistry) {
typeAliasRegistry.registerAlias(OtlpMetricGroupsQueryParam.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package com.navercorp.pinpoint.otlp.web.config;
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.otlp.web.config.pinot;

import com.navercorp.pinpoint.mybatis.MyBatisConfigurationCustomizer;
import com.navercorp.pinpoint.mybatis.MyBatisRegistryHandler;
Expand Down Expand Up @@ -47,7 +63,7 @@
}

private void registryHandler(org.apache.ibatis.session.Configuration config) {
MyBatisRegistryHandler registryHandler = new OtlpMetricWebRegistryHandler();
MyBatisRegistryHandler registryHandler = new OtlpMetricPinotRegistryHandler();

Check warning on line 66 in otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/pinot/OtlpMetricWebPinotDaoConfiguration.java

View check run for this annotation

Codecov / codecov/patch

otlpmetric/otlpmetric-web/src/main/java/com/navercorp/pinpoint/otlp/web/config/pinot/OtlpMetricWebPinotDaoConfiguration.java#L66

Added line #L66 was not covered by tests
registryHandler.registerTypeAlias(config.getTypeAliasRegistry());
registryHandler.registerTypeHandler(config.getTypeHandlerRegistry());
}
Expand Down
Loading